def get_disassembly(self, func, lasti=-1, wrapper=True): output = io.StringIO() if wrapper: dis.dis(func, file=output) else: dis.disassemble(func, lasti, file=output) return output.getvalue()
def get_disassembly(self, func, lasti=-1, wrapper=True): # We want to test the default printing behaviour, not the file arg output = io.StringIO() with contextlib.redirect_stdout(output): if wrapper: dis.dis(func) else: dis.disassemble(func, lasti) return output.getvalue()
def get_disassembly(self, func, lasti=-1, wrapper=True): s = io.StringIO() save_stdout = sys.stdout sys.stdout = s try: if wrapper: dis.dis(func) else: dis.disassemble(func, lasti) finally: sys.stdout = save_stdout # Trim trailing blanks (if any). return [line.rstrip() for line in s.getvalue().splitlines()]
def do_disassembly_test(self, func, expected): s = StringIO() save_stdout = sys.stdout sys.stdout = s dis.dis(func) sys.stdout = save_stdout got = s.getvalue() # Trim trailing blanks (if any). lines = got.split('\n') # lines = [line.rstrip() for line in lines] expected = expected.split("\n") import difflib if expected != lines: self.fail("events did not match expectation:\n" + "\n".join(difflib.ndiff(expected, lines)))
def do_disassembly_test(self, func, expected): s = StringIO() save_stdout = sys.stdout sys.stdout = s dis.dis(func) sys.stdout = save_stdout got = s.getvalue() # Trim trailing blanks (if any). lines = got.split('\n') # lines = [line.rstrip() for line in lines] expected = expected.split("\n") import difflib if expected != lines: self.fail( "events did not match expectation:\n" + "\n".join(difflib.ndiff(expected, lines)))
def test_dis(stream_fixture): dis.dis(TEST_SOURCE_CODE, file=stream_fixture) actual = stream_fixture.getvalue() assert actual == expected_dis + '\n'