def test6(self): s = Gen_All(syntax_Py, False) #open('Ast_Py2.py', 'w').write(s) s2 = open('Ast_Py_noserial.py').read() self.assertEqual(s, s2) s = Gen_All(syntax_Py, True) #open('Ast_Py.py', 'w').write(s) s2 = open('Ast_Py.py').read() self.assertEqual(s, s2)
def test5(self): s = Gen_All(syntax_Py, True) #open('Ast_Py2.py', 'w').write(s) s2 = open('Ast_Py.py').read() self.assertEqual(s, s2) #return import Ast_Py the = Ast_Py.PY_Parser(sample_Python) the.deep() mod = the.handle_main() last = the.SerialOut() stand = [[['main', [], [[[['c', 1], [[[['2800', 0], 4], 2]]], 5], [[['f', 1], [[[[[[[[[['10000', 0], 4], 2]], '/', [[['5', 0], 4]]]], 0], 1]], '*', [[['2801', 0], 4]]]], 5], [[[['f', [[[['c', 1], 4], 2]]], 0], [[[['0', 0], 4], 2]]], 5], [[['e', 1], [[[['0', 0], 4], 2]]], 5], [[[[[[['c', 1], 4], 2]], '!=', [[['0', 0], 4]]], [[[['d', 1], [[[['0', 0], 4], 2]]], 5], [[['b', 1], [[[['c', 1], 4], 2]]], 5], [[[[[0, 3], 2]], [[[['d', 1], 0, [[[[['f', [[[['b', 1], 4], 2]]], 2], 2]], '*', [[['10000', 0], 4]]]], 6], [[[['f', [[[['b', 1], 4], 2]]], 0], [[[[['d', 1], 4], 2]], '%', [[[[[[[['b', 1], 4], 2]], '*', [[['2', 0], 4]]], '-', [[['1', 0], 4]]], 0]]]], 5], [[['d', 1], 2, [[[[[[[[['b', 1], 4], 2]], '*', [[['2', 0], 4]]], '-', [[['1', 0], 4]]], 0], 2]]], 6], [[['b', 1], 1, [[[['1', 0], 4], 2]]], 6], [[[[[[['b', 1], 4], 2]], '==', [[['0', 0], 4]]], [[[[[['break', 1], 4], 2]], 7]], []], 0], [[['d', 1], 3, [[[['b', 1], 4], 2]]], 6]], []], 1], [[['c', 1], 1, [[[['14', 0], 4], 2]]], 6], [[[[[[[["'%04d'", 2], 4], 2]], '%', [[[[[[['e', 1], 4], 2]], '+', [[[['d', 1], 4]], '/', [[['10000', 0], 4]]]], 0]]]], 1], 3], [[['e', 1], [[[[['d', 1], 4], 2]], '%', [[['10000', 0], 4]]]], 5]], []], 1], [[[], 0], 3]]], 4], [[[[['main', []], 1], 2]], 7]] if last != stand: print last self.assertEqual(last, stand) the2 = Ast_Py.PY_SerialIn() mod2 = the2.handle_main(stand) outp = Ast_Py.OutP() the2 = Ast_Py.PY_output(outp) mod.walkabout(the2) txt = outp.txt #print '<%s>' % txt print txt txt2 = ''' def main ( ) : c = 2800 f = [ 10000 / 5 ] * 2801 f [ c ] = 0 e = 0 while c != 0 : d = 0 b = c while True : d += f [ b ] * 10000 f [ b ] = d % ( b * 2 - 1 ) d /= ( b * 2 - 1 ) b -= 1 if b == 0 : break d *= b c -= 14 print '%04d' % ( e + d / 10000 ) , e = d % 10000 print main ( )''' self.assertEqual(txt, txt2) outp = Ast_Py.OutP() the2 = Ast_Py.PY_output(outp) mod2.walkabout(the2) txt = outp.txt self.assertEqual(txt, txt2)
def test5(self): s = Gen_All(syntax_Py, True) #open('Ast_Py2.py', 'w').write(s) s2 = open('Ast_Py.py').read() self.assertEqual(s, s2) #return import Ast_Py the = Ast_Py.PY_Parser(sample_Python) the.deep() mod = the.handle_main() last = the.SerialOut() stand = [[[[['LiuD_Main_Gen'], [[[['Gen_All'], []]], 1]], 0], 6], [['cls1', [], [[[[[['v3', 0], 2], [[[[[[[[[[[[[[[[[['a1', 1], 1], 7], 0], 'a2'], 3], [[[[[[[[[['3', 0], 1], 7], 0], 1]]]]], 2]], 1], 'a3'], 3], [[[], [[[[[[[[['a4', 1], 1], 7], 0], 1]]]]]], [[], [[[[[[[[['a5', 1], 1], 7], 0], 1]]]]]]]], 2], 1]]]]], 1]], 2], 9]]], 7], [['cls2', [[['cls1'], ['object']]], [[[[[['v', 0], 2], [[[[[[[[[[[['3', 0], 1], 7], 0], 1]], '+', [[[[['2', 0], 1], 7], 0]]]]], [[[[[0, 6], 0], 1]]], [[[[0, [[[['66', 0], 1], 7], 0]], 0]]]]], 1]], 2], 9]]], 7], [[[[['s', 0], 2], [[[[[[[[[['"""test\ntest\n multiline\n string"""', 0], 0], 7], 0], 1]]]]], 1]], 2], 9], [['main', [], [[[[[['c', 0], 2], [[[[[[[[[['2800', 0], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[['f', 0], 2], [[[[[[[[[[[[[[[[[[[[['10000', 0], 1], 7], 0], 1]], '/', [[[[['5', 0], 1], 7], 0]]]]]]], 0], 0], 0], 1]], '*', [[[[['2801', 0], 1], 7], 0]]]]]], 1]], 2], 9], [[[[[[['f', 0], [[[[[[[[[['c', 1], 1], 7], 0], 1]]]]], 2]], 1], 2], [[[[[[[[[['0', 0], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[['e', 0], 2], [[[[[[[[[['0', 0], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[[[[[[[[['c', 1], 1], 7], 0], 1]]], '!=', [[[[[[['0', 0], 1], 7], 0], 1]]]]]], [[[[[['d', 0], 2], [[[[[[[[[['0', 0], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[['b', 0], 2], [[[[[[[[[['c', 1], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[[[[[[0, 6], 0], 1]]]]], [[[[[['d', 0], 2], 0, [[[[[[[[[[[['f', 1], 1], 7], 0], [[[[[[[[[['b', 1], 1], 7], 0], 1]]]]], 2]], 1], 1]], '*', [[[[['10000', 0], 1], 7], 0]]]]]]], 3], 9], [[[[[[['f', 0], [[[[[[[[[['b', 1], 1], 7], 0], 1]]]]], 2]], 1], 2], [[[[[[[[[[['d', 1], 1], 7], 0], 1]]], '%', [[[[[[[[[[[[[[[['b', 1], 1], 7], 0], 1]], '*', [[[[['2', 0], 1], 7], 0]]], '-', [[[[['1', 0], 1], 7], 0]]]]]], 4], 0], 1]]]]]], 1]], 2], 9], [[[[['d', 0], 2], 2, [[[[[[[[[[[[[[[[[['b', 1], 1], 7], 0], 1]], '*', [[[[['2', 0], 1], 7], 0]]], '-', [[[[['1', 0], 1], 7], 0]]]]]], 4], 0], 1]]]]]], 3], 9], [[[[['b', 0], 2], 1, [[[[[[[[['1', 0], 1], 7], 0], 1]]]]]], 3], 9], [[[[[[[[[[[['b', 1], 1], 7], 0], 1]]], '==', [[[[[[['0', 0], 1], 7], 0], 1]]]]]], [[[1, 0], 9]], [], []], 0], [[[[['d', 0], 2], 3, [[[[[[[[['b', 1], 1], 7], 0], 1]]]]]], 3], 9]], []], 1], [[[[['c', 0], 2], 1, [[[[[[[[['14', 0], 1], 7], 0], 1]]]]]], 3], 9], [[[[[[[[[[[[["'%04d'", 6], 0], 7], 0], 1]]], '%', [[[[[[[[[[[[[[['e', 1], 1], 7], 0], 1]], '+', [[[[[['d', 1], 1], 7], 0]], '/', [[[[['10000', 0], 1], 7], 0]]]]]]], 4], 0], 1]]]]]]], 1], 4], [[[[['e', 0], 2], [[[[[[[[[[['d', 1], 1], 7], 0], 1]]], '%', [[[[[[['10000', 0], 1], 7], 0], 1]]]]]], 1]], 2], 9]], []], 1], [[[], 0], 4]]], 5], [[[[[[[[[['main', []], 5], 0], 1]]]]], 4], 9]] if last != stand: print last self.assertEqual(last, stand) the2 = Ast_Py.PY_SerialIn() mod2 = the2.handle_main(stand) outp = Ast_Py.OutP() the2 = Ast_Py.PY_output(outp) mod.walkabout(the2) txt = outp.txt #print '<%s>' % txt txt2 = '''from LiuD_Main_Gen import Gen_All class cls1 : v3 = a1 . a2 [ 3 ] . a3 ( a4 , a5 ) class cls2 ( cls1 , object ) : v = 3 + 2 if True else - 66 s = """test test multiline string""" def main ( ) : c = 2800 f = [ 10000 / 5 ] * 2801 f [ c ] = 0 e = 0 while c != 0 : d = 0 b = c while True : d += f [ b ] * 10000 f [ b ] = d % ( b * 2 - 1 ) d /= ( b * 2 - 1 ) b -= 1 if b == 0 : break d *= b c -= 14 print '%04d' % ( e + d / 10000 ) , e = d % 10000 print main ( )''' self.assertEqual(txt, txt2) if True: outp = Ast_Py.OutP() the2 = Ast_Py.PY_output(outp) mod2.walkabout(the2) txt = outp.txt print '<%s>' % txt self.assertEqual(txt, txt2)
def test1(self): s = Gen_All(LiuD_syntax) open('Ast_LiuD2.py', 'w').write(s) s2 = open('Ast_LiuD.py').read() self.assertEqual(s, s2)
def func1(): s = Gen_All(liud_syntax) print s
def test2(self): s = Gen_All(syntax_CPP) #open('Ast_CPP2.py', 'w').write(s) s2 = open('Ast_CPP.py').read() self.assertEqual(s, s2)
def func5(): s = Gen_All(syntax_Py) print s
def func3(): s = Gen_All(syntax_CPP) print s