Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to cover the InfoMander class #34

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit
pip install -e . -r requirements.txt -r requirements-test.txt
python -m pip install -e . -r requirements.txt -r requirements-test.txt
cd frontend && npm install
- name: Lint with pre-commit
run: |
Expand All @@ -34,7 +33,7 @@ jobs:
cp -a dist/. ../src/mandr/dashboard/static
- name: Test with pytest
run: |
pytest --cov
python -m pytest tests
- name: Test with vitest
run: |
cd frontend
Expand Down
17 changes: 15 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ dependencies = [
]

[project.optional-dependencies]
test = ["pytest", "pytest-cov", "pre-commit", "ruff"]
test = [
"pre-commit",
"pytest",
"pytest-cov",
"pytest-randomly",
"ruff"
]

[tool.hatch.build.targets.wheel]
packages = ["src/mandr"]
Expand All @@ -31,7 +37,14 @@ packages = ["src/mandr"]
upgrade = true

[tool.pytest.ini_options]
addopts = ["--import-mode=importlib"]
addopts = [
"--cov=src/",
"--cov=tests/",
"--cov-branch",
"--import-mode=importlib",
"--no-header",
"--verbosity=2",
]

[tool.ruff]
src = ["mandr"]
Expand Down
6 changes: 0 additions & 6 deletions src/mandr/__main__.py

This file was deleted.

157 changes: 0 additions & 157 deletions src/mandr/app.py

This file was deleted.

49 changes: 35 additions & 14 deletions src/mandr/dashboard/webapp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""A FastAPI based webapp to serve a local dashboard."""

import os
from pathlib import Path

from fastapi import FastAPI, HTTPException, Request
from fastapi.staticfiles import StaticFiles

from mandr.infomander import ARTIFACTS_KEY, LOGS_KEY, VIEWS_KEY, InfoManderRepository
from mandr import InfoMander

_DASHBOARD_PATH = Path(__file__).resolve().parent
_STATIC_PATH = _DASHBOARD_PATH / "static"
Expand All @@ -16,23 +17,43 @@
@app.get("/api/mandrs")
async def list_mandrs(request: Request) -> list[str]:
"""Send the list of mandrs path below the current working directory."""
return [f"{p}" for p in InfoManderRepository.get_all_paths()]
path = os.environ["MANDR_PATH"]
root = Path(os.environ["MANDR_ROOT"])
ims = [InfoMander(path, root=root)]
paths = []

# Use `ims` as a queue to recursively iterate over children to retrieve path.
for im in ims:
ims[len(ims) :] = im.children()
absolute_path = im.project_path
relative_path = absolute_path.relative_to(root)

@app.get("/api/mandrs/{mander_path:path}")
async def get_mandr(request: Request, mander_path: str):
paths.append(str(relative_path))

return sorted(paths)


@app.get("/api/mandrs/{path:path}")
async def get_mandr(request: Request, path: str):
"""Return one mandr."""
mander = InfoManderRepository.get(path=mander_path)
if mander is None:
raise HTTPException(status_code=404, detail=f"No mandr found in {mander_path}")
serialized_mander = {
"path": f"{mander.path}",
"views": mander[VIEWS_KEY].items(),
"logs": mander[LOGS_KEY].items(),
"artifacts": mander[ARTIFACTS_KEY].items(),
"info": {k: str(v) for k, v in mander.fetch().items() if not k.startswith("_")},
root = Path(os.environ["MANDR_ROOT"])

if not (root / path).exists():
raise HTTPException(status_code=404, detail=f"No mandr found in '{path}'")

im = InfoMander(path, root=root)

return {
"path": path,
"views": im[InfoMander.VIEWS_KEY].items(),
"logs": im[InfoMander.LOGS_KEY].items(),
"artifacts": im[InfoMander.ARTIFACTS_KEY].items(),
"info": {
key: str(value)
for key, value in im.fetch().items()
if key not in InfoMander.RESERVED_KEYS
},
}
return serialized_mander


# as we mount / this line should be after all route declarations
Expand Down
Loading
Loading