Skip to content

Commit

Permalink
add importability test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmeier committed Oct 3, 2023
1 parent 4b96404 commit 9a4491b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ on:
- "pyproject.toml"

jobs:
importable:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup environment
uses: ./.github/actions/setup-env
with:
optional-dependencies: "false"

- name: Check if all public packages are importable
run: python tests/test_importable.py


unit:
runs-on: ubuntu-latest
defaults:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_importable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import importlib
from pathlib import Path

HERE = Path(__file__).parent
PROJECT_ROOT = HERE.parent
PACKAGE_ROOT = PROJECT_ROOT / "ragna"


def main():
for path in PACKAGE_ROOT.rglob("*.py"):
if path.name == "__init__.py":
path = path.parent
else:
path = path.with_suffix("")

if path.name.startswith("_"):
continue

name = path.relative_to(PROJECT_ROOT).as_posix().replace("/", ".")

try:
importlib.import_module(name)
except Exception as exc:
raise ImportError(
f"Trying to import '{name}' raise the error above"
) from exc
else:
print(name)


if __name__ == "__main__":
main()

0 comments on commit 9a4491b

Please sign in to comment.