def runAssemblerTest(fname, exceptFailure): print 'Running assembler test', os.path.basename(fname) error = False try: assemble.assembleClass(fname, fatal=True) except AsssemblerError: error = True assert error == exceptFailure
def runDisassemblerTest(target, testcases): print 'Running disassembler test {}...'.format(target) tdir = tempfile.mkdtemp() classloc = os.path.join(dis_class_location, target + '.class') jloc = os.path.join(tdir, target + '.j') disassemble.disassembleClass(disassemble.readFile, targets=[classloc], outpath=tdir) pairs = assemble.assembleClass(jloc) new_fname = os.path.join(tdir, target + '.class') for name, data in pairs: assert name == target with open(new_fname, 'wb') as f: f.write(data) good_fname = os.path.join(dis_class_location, target + '.class') runJavaAndCompare(target, testcases, good_fname, new_fname) shutil.rmtree(tdir)