diff --git a/tests/test_module_alias.py b/tests/test_module_alias.py index bc8c8e5..cb8f885 100644 --- a/tests/test_module_alias.py +++ b/tests/test_module_alias.py @@ -3,13 +3,7 @@ import pytest import traceback_with_variables as twv -from traceback_with_variables.module_alias import ( - create_alias, - rm_alias, - module_name_to_path, - Path, - NoModuleError, -) +from traceback_with_variables.module_alias import create_alias, rm_alias, module_name_to_path, Path ROOT_PATH = Path(twv.__file__).parent.parent @@ -21,7 +15,7 @@ def test_module_name_to_path(): assert module_name_to_path(OS) == Path(os.__file__) assert module_name_to_path(TWV) == ROOT_PATH / TWV - with pytest.raises(NoModuleError): + with pytest.raises(ModuleNotFoundError): module_name_to_path('nonexistant_module') @@ -36,14 +30,14 @@ def test_create_and_rm_alias(): create_alias('bad name', TWV) assert str(e.value) == 'the alias must have only ascii lowecases, digits and underscores' - with pytest.raises(NoModuleError): + with pytest.raises(ModuleNotFoundError): create_alias(ALIAS, 'nonexistant_module') with pytest.raises(ValueError) as e: create_alias(OS, TWV) assert str(e.value) == 'a module with the alias name already exists' - with pytest.raises(NoModuleError): + with pytest.raises(ModuleNotFoundError): rm_alias(ALIAS) with pytest.raises(ValueError) as e: @@ -67,7 +61,7 @@ def test_create_and_rm_alias(): # problems after we rm the alias - with pytest.raises(NoModuleError): + with pytest.raises(ModuleNotFoundError): rm_alias(ALIAS) # rare case of garbage in the lib dir diff --git a/traceback_with_variables/module_alias.py b/traceback_with_variables/module_alias.py index cbbd478..bb88a06 100644 --- a/traceback_with_variables/module_alias.py +++ b/traceback_with_variables/module_alias.py @@ -9,14 +9,10 @@ VALID_CHARS = set(string.ascii_lowercase + string.digits + '_') -class NoModuleError(ValueError): - pass - - def module_name_to_path(name: str) -> Path: spec = importlib.util.find_spec(name) if spec is None: - raise NoModuleError(name) + raise ModuleNotFoundError(name) path = Path(spec.origin) return path.parent if path.name == '__init__.py' else path @@ -24,7 +20,7 @@ def module_name_to_path(name: str) -> Path: def module_exists(name: str) -> bool: try: module_name_to_path(name) - except NoModuleError: + except ModuleNotFoundError: return False return True