예제 #1
0
 def test_dict(self):
     assert prettify_expr('{"x" : 123, \'yy\': 234, 567:...}'
                          ) == "{'x': 123, 'yy': 234, (567): ...}"
     # note: parentheses could be skipped                                                ^   ^
     assert prettify_expr('{"x" : {}, **{"y":set()}, **abc}'
                          ) == "{'x': {}, **{'y': set()}, **abc}"
     assert prettify_expr(
         'dict (   abc=  123,qwe=x)') == 'dict(abc=123, qwe=x)'
예제 #2
0
 def fmt_eval(self, x, t):
     expr = prettify_expr(t.expr)
     if is_dependent_expr(t.expr):
         return f'{x} => {expr}'
     else:
         return expr
예제 #3
0
 def stringify(self, obj):
     return prettify_expr(obj.stringify(self))
예제 #4
0
 def test_tuple(self):
     assert prettify_expr('func  ( (1,2,3,) )') == 'func((1, 2, 3))'
     assert prettify_expr('func(  *(x, y   ,z) )') == 'func(*(x, y, z))'
     assert prettify_expr('foo[(1,2,3)]') == 'foo[1, 2, 3]'
예제 #5
0
 def test_list(self):
     assert prettify_expr('x = [     ]  ') == 'x = []'
     assert prettify_expr(
         '[1] +[ ] / [1,2,] + [3,4]  ') == '[1] + [] / [1, 2] + [3, 4]'
     assert prettify_expr('[ [],[[],[]]]') == '[[], [[], []]]'
예제 #6
0
 def test_parentheses(self):
     assert prettify_expr('(  12*23)+ 34') == '12 * 23 + 34'
     assert prettify_expr('34 + (( 12*  (23+23)))') == '34 + 12 * (23 + 23)'
예제 #7
0
 def test_arithmetic(self):
     assert prettify_expr('123+234//5') == '123 + 234 // 5'
     assert prettify_expr('123+-234%5  ') == '123 + -234 % 5'
     assert prettify_expr('123   *3   #qq') == '123 * 3'
     assert prettify_expr(
         'qwe =  asd =  234 == None') == 'qwe = asd = 234 == None'
예제 #8
0
파일: trans.py 프로젝트: gergelyk/peepshow
 def __init__(self, target, expr):
     super().__init__(target)
     self.expr = prettify_expr(expr)