Validate that a Python namespace package is set up correctly. In a sub interpreter, add 'paths' to sys.path and attempt to import the given modules. In this module many tests configure a set of files as a namespace package, this function is used as sanity check that our files are
(
pytester: Pytester, paths: Sequence[Path], modules: Sequence[str]
)
| 1736 | |
| 1737 | |
| 1738 | def validate_namespace_package( |
| 1739 | pytester: Pytester, paths: Sequence[Path], modules: Sequence[str] |
| 1740 | ) -> RunResult: |
| 1741 | """ |
| 1742 | Validate that a Python namespace package is set up correctly. |
| 1743 | |
| 1744 | In a sub interpreter, add 'paths' to sys.path and attempt to import the given modules. |
| 1745 | |
| 1746 | In this module many tests configure a set of files as a namespace package, this function |
| 1747 | is used as sanity check that our files are configured correctly from the point of view of Python. |
| 1748 | """ |
| 1749 | lines = [ |
| 1750 | "import sys", |
| 1751 | # Configure sys.path. |
| 1752 | *[f"sys.path.append(r{str(x)!r})" for x in paths], |
| 1753 | # Imports. |
| 1754 | *[f"import {x}" for x in modules], |
| 1755 | ] |
| 1756 | return pytester.runpython_c("\n".join(lines)) |
no test coverage detected