From b53651850c7187652caae3277c6aac603c189f4f Mon Sep 17 00:00:00 2001 From: Chuck McCallum Date: Wed, 25 Sep 2024 16:16:35 -0400 Subject: [PATCH] simple end-to-end test --- .github/workflows/test.yml | 3 +++ README.md | 1 + dp_creator_ii/app.py | 8 ++++---- dp_creator_ii/tests/test_app.py | 13 +++++++++++++ requirements-dev.in | 1 + requirements-dev.txt | 22 +++++++++++++++++++++- 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 dp_creator_ii/tests/test_app.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f4bdb8..ecc48ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,9 @@ jobs: - name: Install dev dependencies run: pip install -r requirements-dev.txt + - name: Install browsers + run: playwright install + - name: Test run: coverage run -m pytest -v diff --git a/README.md b/README.md index 18d7308..925c4bd 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ python3 -m venv .venv source .venv/bin/activate pip install -r requirements-dev.txt pre-commit install +playwright install ``` Now install the application itself and run it: diff --git a/dp_creator_ii/app.py b/dp_creator_ii/app.py index cc80753..e6c1d35 100644 --- a/dp_creator_ii/app.py +++ b/dp_creator_ii/app.py @@ -3,10 +3,6 @@ from shiny import App, ui, reactive, render -config_path = Path(__file__).parent / "config.json" -config = json.loads(config_path.read_text()) -config_path.unlink() - def dataset_panel(): return ui.nav_panel( @@ -48,6 +44,10 @@ def results_panel(): def server(input, output, session): + config_path = Path(__file__).parent / "config.json" + config = json.loads(config_path.read_text()) + config_path.unlink() + csv_path = reactive.value(config["csv_path"]) unit_of_privacy = reactive.value(config["unit_of_privacy"]) diff --git a/dp_creator_ii/tests/test_app.py b/dp_creator_ii/tests/test_app.py new file mode 100644 index 0000000..ec1ea58 --- /dev/null +++ b/dp_creator_ii/tests/test_app.py @@ -0,0 +1,13 @@ +from shiny.run import ShinyAppProc +from playwright.sync_api import Page, expect +from shiny.pytest import create_app_fixture + + +app = create_app_fixture("../app.py") + + +# TODO: Why is incomplete coverage reported here? +def test_app(page: Page, app: ShinyAppProc): # pragma: no cover + page.goto(app.url) + expect(page).to_have_title("DP Creator II") + expect(page.locator("body")).to_contain_text("TODO: Pick dataset") diff --git a/requirements-dev.in b/requirements-dev.in index a2b13b8..f2eb714 100644 --- a/requirements-dev.in +++ b/requirements-dev.in @@ -11,6 +11,7 @@ pre-commit # Testing: pytest +pytest-playwright mypy coverage diff --git a/requirements-dev.txt b/requirements-dev.txt index cce38d6..7916b16 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -73,6 +73,8 @@ flit==3.9.0 # via -r requirements-dev.in flit-core==3.9.0 # via flit +greenlet==3.0.3 + # via playwright h11==0.14.0 # via uvicorn htmltools==0.5.3 @@ -200,6 +202,8 @@ platformdirs==4.3.6 # black # jupyter-core # virtualenv +playwright==1.47.0 + # via pytest-playwright pluggy==1.5.0 # via pytest polars==1.1.0 @@ -221,6 +225,8 @@ pyarrow==17.0.0 # via opendp pycodestyle==2.12.1 # via flake8 +pyee==12.0.0 + # via playwright pyflakes==3.2.0 # via flake8 pygments==2.18.0 @@ -232,6 +238,13 @@ pyproject-hooks==1.1.0 # build # pip-tools pytest==8.3.3 + # via + # -r requirements-dev.in + # pytest-base-url + # pytest-playwright +pytest-base-url==2.1.0 + # via pytest-playwright +pytest-playwright==0.5.2 # via -r requirements-dev.in python-dateutil==2.9.0.post0 # via @@ -239,6 +252,8 @@ python-dateutil==2.9.0.post0 # shinywidgets python-multipart==0.0.9 # via shiny +python-slugify==8.0.4 + # via pytest-playwright pyyaml==6.0.2 # via # jupytext @@ -256,7 +271,9 @@ referencing==0.35.1 # jsonschema # jsonschema-specifications requests==2.32.3 - # via flit + # via + # flit + # pytest-base-url rpds-py==0.20.0 # via # jsonschema @@ -286,6 +303,8 @@ stack-data==0.6.3 # via ipython starlette==0.38.5 # via shiny +text-unidecode==1.3 + # via python-slugify threadpoolctl==3.5.0 # via scikit-learn tinycss2==1.3.0 @@ -312,6 +331,7 @@ typing-extensions==4.12.2 # via # htmltools # mypy + # pyee # shiny uc-micro-py==1.0.3 # via linkify-it-py