def test_import_as(): co_imports = get_co(IMPORT_AS) import_bc = get_bytecode(co_imports) import_stmts = equip.BytecodeObject.get_imports_from_bytecode(co_imports, import_bc) assert len(import_stmts) == 1 import_stmt = import_stmts[0] assert import_stmt.root == None assert import_stmt.aliases == [('foo', None)]
def test_imports(): co_imports = get_co(IMPORTS_CODE) import_bc = get_bytecode(co_imports) assert co_imports is not None assert len(import_bc) > 0 import_stmts = equip.BytecodeObject.get_imports_from_bytecode(co_imports, import_bc) assert len(import_stmts) == 18 splitted_imports = filter(lambda imp: imp != '', IMPORTS_CODE.split('\n')) i = 0 for stmt in import_stmts: candidate_import = splitted_imports[i] stmt_str = repr(stmt) assert candidate_import in stmt_str i += 1
def test_already_merged(): instrumented = get_bytecode(get_co(INSTRUMENTED_CODE)) instrument = get_bytecode(get_co(INSTR_CODE))[:-2] assert Merger.already_instrumented(instrumented, instrument)