def test_windows_case_insensitivity(mocker: MockFixture): # given mocked_pythonpath = [Path(r"d:\a\package")] mocker.patch("pycollect.module_finder.sys.path", mocked_pythonpath) filepath = Path(r"D:\a\package\module.py") expected_module_name = "module" # when module_name = find_module_name(filepath) # then assert module_name == expected_module_name
def test_find_nonexistent_module_name(): """ This test intents to ensure that the utility function `find_module_name` will return None for files it can not attribute a module name """ # given filepath = build_path("test_find_nonexistent_module_name", "bar.py") # when module_name = find_module_name(filepath) # then assert module_name is None
def test_find_outermost_module_name(): """ This test intents to ensure that the utility function `find_module_name` will find the correct outermost module name for a given filepath by default """ # given filepath = foo.__file__ expected_module_name = "tests.resources.example_module.foo.foo" # when module_name = find_module_name(filepath) # then assert module_name == expected_module_name
def test_find_nonexistent_module_name(): """ This test intents to ensure that the utility function `find_module_name` will return None for files it can not attribute a module name """ # given root_dir = "usr" if os.name != "nt" else "C:" filepath = os.path.join(os.sep, root_dir + os.sep, "random", "path", "script.py") # when module_name = find_module_name(filepath) # then assert module_name is None
def test_find_innermost_module_name(): """ This test intents to ensure that the utility function `find_module_name` will find the correct innermost module name for a given filepath when parameter `innermost=True` """ # given filepath = foo.__file__ expected_module_name = "example_module.foo.foo" # when module_name = find_module_name(filepath, innermost=True) # then assert module_name == expected_module_name
def test_find_outermost_module_name(): """ This test intents to ensure that the utility function `find_module_name` will find the correct outermost module name for a given filepath by default """ # given package_path = build_path("test_find_outermost_module_name", "some_package") inner_module_path = join_paths(package_path, "inner_module") filepath = join_paths(inner_module_path, "foo", "bar.py") sys.path.append(parent_path(package_path)) sys.path.append(parent_path(inner_module_path)) expected_module_name = "some_package.inner_module.foo.bar" # when module_name = find_module_name(filepath) # then assert module_name == expected_module_name
def _load_file(cls, file: os.DirEntry): module_name = find_module_name(file) spec = spec_from_file_location(module_name, file.path) module = module_from_spec(spec) sys.modules[module_name] = module spec.loader.exec_module(module)
def test_example_case(example_file: os.DirEntry): reset_injection_container() module_name = find_module_name(os.path.abspath(example_file.path)) example = import_module(module_name) example.run_example()
def test_example_case(example_file: os.DirEntry): module_name = find_module_name(os.path.abspath(example_file.path)) example = import_module(module_name) example.run_example()