def test_01reblok(self): for root, dirs, files in os.walk(self.snippets): for f in files: if not f.endswith('.pyc'): continue tmp = tempfile.mkstemp(prefix='reblok-') print os.path.join(root, f), tmp, type(tmp) ret = subprocess.call( ['reblok', os.path.join(root, f)], stdout=tmp[0]) # validation #1: reblok mist return 0 value self.assertEqual(ret, 0) # validation #2: we compare AST generated by source file and reblok-output # file with open(os.path.join(root, f)) as fh: fh.seek(8) bytecode = marshal.load(fh) tree = Parser().walk(bytecode) try: with open(tmp[1]) as fh: bytecode = compile(fh.read(), '<string>', 'exec') except SyntaxError: self.fail('%s: invalid source file (%s)' % (f, tmp[1])) tree2 = Parser().walk(bytecode) import pprint pprint.pprint(tree) pprint.pprint(tree2) self.assertEqual(tree, tree2)
def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) self.parser = Parser() # compile snippets self.snippets = os.path.join(os.path.dirname(sys.argv[0]), 'snippets') compileall.compile_dir(self.snippets)
def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) self.parser = Parser()