def test_import_from_tmppy_module_name_not_found_error(): module_foo_name = 'foo' module_foo_source = '''\ def f(b: bool): if b: return 7 else: return 43 ''' compiled_module_foo = compile(module_foo_source, module_name=module_foo_name) module_bar_name = 'bar' module_bar_source = '''\ from foo import f assert f(False) == 43 ''' compiled_module_bar = compile(module_bar_source, module_name=module_bar_name, context_object_file_content=compiled_module_foo) cpp_source = link(compiled_module_bar, main_module_name=module_bar_name) expect_cpp_code_success(tmppy_source=module_foo_source + module_bar_source, object_file_content=compiled_module_bar, cxx_source=cpp_source, main_module_name=module_bar_name)
def test_import_two_modules_with_same_public_name_only_one_imported_ok(): module_foo_name = 'foo' module_foo_source = '''\ class MyError(Exception): def __init__(self, b: bool): self.message = 'Something went wrong' self.b = b def is_false(b: bool): return not b def f(b: bool): if is_false(b): return 3 else: raise MyError(b) ''' compiled_module_foo = compile(module_foo_source, module_name=module_foo_name) module_bar_name = 'bar' module_bar_source = '''\ class MyError(Exception): def __init__(self, b: bool): self.message = 'Something went wrong' self.b = b def is_false(b: bool): return not b def g(b: bool): if is_false(b): return 3 else: raise MyError(b) ''' compiled_module_bar = compile(module_bar_source, module_name=module_bar_name) module_baz_name = 'baz' module_baz_source = '''\ from foo import f from bar import g def h(b: bool): return f(b) + g(b) ''' compiled_module_baz = compile( module_baz_source, module_name=module_baz_name, context_object_file_content=merge_object_files( [compiled_module_foo, compiled_module_bar])) cpp_source = link(compiled_module_baz, main_module_name=module_baz_name) expect_cpp_code_success(tmppy_source=module_foo_source + module_bar_source + module_baz_source, object_file_content=compiled_module_baz, cxx_source=cpp_source, main_module_name=module_baz_name)
def test_import_from_tmppy_module_chain_ok(): module_foo_name = 'foo' module_foo_source = '''\ def f(b: bool): return 7 ''' compiled_module_foo = compile(module_foo_source, module_name=module_foo_name) module_bar_name = 'bar' module_bar_source = '''\ from foo import f def g(b: bool): return f(b) ''' compiled_module_bar = compile( module_bar_source, module_name=module_bar_name, context_object_file_content=compiled_module_foo) module_baz_name = 'baz' module_baz_source = '''\ from bar import g assert g(True) == 7 ''' compiled_module_baz = compile( module_baz_source, module_name=module_baz_name, context_object_file_content=compiled_module_bar) cpp_source = link(compiled_module_baz, main_module_name=module_baz_name) expect_cpp_code_success(tmppy_source=module_foo_source + module_bar_source + module_baz_source, object_file_content=compiled_module_baz, cxx_source=cpp_source, main_module_name=module_baz_name)