Example #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)'
Example #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
Example #3
0
 def stringify(self, obj):
     return prettify_expr(obj.stringify(self))
Example #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]'
Example #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('[ [],[[],[]]]') == '[[], [[], []]]'
Example #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)'
Example #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'
Example #8
0
 def __init__(self, target, expr):
     super().__init__(target)
     self.expr = prettify_expr(expr)