Refactor test_top_level_imports() test cases ...

... into a unified location
This commit is contained in:
Alexander Hess 2024-09-18 20:05:49 +02:00
parent 62b25f66d9
commit 51c73163e4
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
2 changed files with 18 additions and 24 deletions

View file

@ -1,18 +0,0 @@
"""Test top-level imports for `lalib.elements`."""
from lalib import elements as top_level
def test_top_level_imports():
"""Verify `from lalib.elements import *` works."""
environment = {}
exec("...", environment, environment) # noqa: S102
defined_vars_before = set(environment)
exec("from lalib.elements import *", environment, environment) # noqa: S102
defined_vars_after = set(environment)
new_vars = defined_vars_after - defined_vars_before
assert new_vars == set(top_level.__all__)

View file

@ -1,18 +1,30 @@
"""Test top-level imports for `lalib`."""
import lalib as top_level
import importlib
from typing import Any
import pytest
def test_top_level_imports():
"""Verify `from lalib import *` works."""
environment = {}
@pytest.mark.parametrize(
"path_to_package",
[
"lalib",
"lalib.elements",
],
)
def test_top_level_imports(path_to_package: str):
"""Verify `from {path_to_package} import *` works."""
package = importlib.import_module(path_to_package)
environment: dict[str, Any] = {}
exec("...", environment, environment) # noqa: S102
defined_vars_before = set(environment)
exec("from lalib import *", environment, environment) # noqa: S102
exec(f"from {path_to_package} import *", environment, environment) # noqa: S102
defined_vars_after = set(environment)
new_vars = defined_vars_after - defined_vars_before
assert new_vars == set(top_level.__all__)
assert new_vars == set(package.__all__)