Exemple #1
0
def test_validate_entry_point_submodule_init():
    with tempfile.TemporaryDirectory() as temp_dir:
        source_module_path = Path(temp_dir, "source_module")
        source_module_path.mkdir()
        Path(source_module_path, "submodule.py").touch()
        with open(str(Path(source_module_path, "__init__.py")), "w") as f:
            f.write("from . import submodule as renamed")
        # from source_module import renamed
        _validate_entry_point(source_module_path, "source_module:renamed")
        # from . import renamed
        _validate_entry_point(source_module_path, ".:renamed")
Exemple #2
0
def test_validate_entry_point_source_module_not_found():
    with tempfile.TemporaryDirectory() as temp_dir:
        source_module_path = Path(temp_dir, "source_module")
        source_module_path.mkdir()
        Path(source_module_path, "submodule.py").touch()

        # catches ModuleNotFoundError
        module_not_found = "Entry point module was not found: fake_source_module.submodule"
        with pytest.raises(ValueError, match=module_not_found):
            _validate_entry_point(source_module_path, "fake_source_module.submodule")

        # catches AssertionError for module is not None
        submodule_not_found = "Entry point module was not found: source_module.fake_submodule"
        with pytest.raises(ValueError, match=submodule_not_found):
            _validate_entry_point(source_module_path, "source_module.fake_submodule")
Exemple #3
0
def test_validate_entry_point_default_directory():
    with tempfile.TemporaryDirectory() as temp_dir:
        source_module_path = Path(temp_dir, "source_module")
        source_module_path.mkdir()
        # import source_module
        _validate_entry_point(source_module_path, "source_module")
        # from source_module import func
        _validate_entry_point(source_module_path, "source_module:func")
        # import .
        _validate_entry_point(source_module_path, ".")
        # from . import func
        _validate_entry_point(source_module_path, ".:func")
Exemple #4
0
def test_validate_entry_point_submodule_file():
    with tempfile.TemporaryDirectory() as temp_dir:
        source_module_path = Path(temp_dir, "source_module")
        source_module_path.mkdir()
        Path(source_module_path, "submodule.py").touch()
        # from source_module import submodule
        _validate_entry_point(source_module_path, "source_module.submodule")
        # from source_module.submodule import func
        _validate_entry_point(source_module_path, "source_module.submodule:func")
        # from . import submodule
        _validate_entry_point(source_module_path, ".submodule")
        # from .submodule import func
        _validate_entry_point(source_module_path, ".submodule:func")