From 685708aab3fc306425a9bb70a7dee132efc3e1e2 Mon Sep 17 00:00:00 2001 From: blakeNaccarato Date: Mon, 30 Sep 2024 12:42:13 -0700 Subject: [PATCH] Fix tests --- packages/_dev/dev/tests/modelfun/conftest.py | 4 +-- pyproject.toml | 16 ++++++--- requirements/requirements_dev.txt | 1 + tests/conftest.py | 33 ++++++++++++++++++- .../tests/modelfun => tests}/test_modelfun.py | 0 uv.lock | 15 +++++++++ 6 files changed, 62 insertions(+), 7 deletions(-) rename {packages/_dev/dev/tests/modelfun => tests}/test_modelfun.py (100%) diff --git a/packages/_dev/dev/tests/modelfun/conftest.py b/packages/_dev/dev/tests/modelfun/conftest.py index 79dab9e..2fcd230 100644 --- a/packages/_dev/dev/tests/modelfun/conftest.py +++ b/packages/_dev/dev/tests/modelfun/conftest.py @@ -5,15 +5,15 @@ import pytest import seaborn as sns -from dev.tests.modelfun import FIT from boilercore.notebooks.namespaces import get_nb_ns +from dev.tests.modelfun import FIT MODELFUN = Path("src/boilercore/stages/modelfun.ipynb").resolve() @pytest.fixture -def ns(request) -> SimpleNamespace: +def ns() -> SimpleNamespace: """Namespace for the model function notebook.""" return get_nb_ns(MODELFUN.read_text(encoding="utf-8")) diff --git a/pyproject.toml b/pyproject.toml index e59cf39..12ecca2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,6 +90,7 @@ dev-dependencies = [ "pytest-custom-exit-code>=0.3.0", "pytest-github-actions-annotate-failures>=0.2.0", "pytest>=8.2.2", + "pytest-plt>=1.1.1", ] [tool.uv.pip] python-version = "3.11" @@ -163,7 +164,14 @@ showcontent = true [tool.pyright] stubPath = "typings/stubs" -exclude = ["**/node_modules", "**/__pycache__", "**/.*", ".cache", "typings"] +exclude = [ + "**/node_modules", + "**/__pycache__", + "**/.*", + ".cache", + "typings", + "packages/cachier", +] ignore = ["**/node_modules", "**/__pycache__", "**/.*", ".cache", "typings"] typeCheckingMode = "strict" # Default "true" in strict @@ -263,9 +271,9 @@ reportUnusedCallResult = "none" [tool.ruff] cache-dir = ".cache/.ruff_cache" -extend-exclude = ["packages", "typings"] -extend-include = ["*.ipynb", "packages/_dev"] -src = ["src", "docs", "scripts", "tests"] +extend-exclude = ["typings", "packages/cachier"] +extend-include = ["*.ipynb"] +src = ["src", "docs", "scripts", "f"] output-format = "grouped" fix = true preview = true diff --git a/requirements/requirements_dev.txt b/requirements/requirements_dev.txt index d61be1d..05256bb 100644 --- a/requirements/requirements_dev.txt +++ b/requirements/requirements_dev.txt @@ -190,6 +190,7 @@ pytest==8.2.2 pytest-cov==5.0.0 pytest-custom-exit-code==0.3.0 pytest-github-actions-annotate-failures==0.2.0 +pytest-plt==1.1.1 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 pytz==2024.2 diff --git a/tests/conftest.py b/tests/conftest.py index 1c368c7..c6d840f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,17 +8,26 @@ from typing import Any import pytest +import seaborn as sns from cachier import cachier, set_default_params # pyright: ignore[reportMissingImports] from dev.tests import EMPTY_NB +from dev.tests.modelfun import FIT import boilercore from boilercore.hashes import hash_args from boilercore.models.params import Params from boilercore.notebooks import namespaces -from boilercore.notebooks.namespaces import NO_PARAMS, get_cached_nb_ns, get_ns_attrs +from boilercore.notebooks.namespaces import ( + NO_PARAMS, + get_cached_nb_ns, + get_nb_ns, + get_ns_attrs, +) from boilercore.testing import get_session_path, unwrap_node from boilercore.warnings import filter_boiler_warnings +MODELFUN = Path("src/boilercore/stages/modelfun.ipynb").resolve() + # Can't be session scope @pytest.fixture(autouse=True) @@ -84,3 +93,25 @@ def cached_function(cached_function_and_cache_file): # noqa: D103 @pytest.fixture def cache_file(cached_function_and_cache_file): # noqa: D103 return cached_function_and_cache_file[1] + + +@pytest.fixture +def ns() -> SimpleNamespace: + """Namespace for the model function notebook.""" + return get_nb_ns(MODELFUN.read_text(encoding="utf-8")) + + +@pytest.fixture +def model(params): + """Deserialized model.""" + return FIT.get_models(params.paths.models)[1] + + +@pytest.fixture +def plt(plt): + """Plot.""" + sns.set_theme( + context="notebook", style="whitegrid", palette="bright", font="sans-serif" + ) + yield plt + plt.saveas = f"{plt.saveas[:-4]}.png" diff --git a/packages/_dev/dev/tests/modelfun/test_modelfun.py b/tests/test_modelfun.py similarity index 100% rename from packages/_dev/dev/tests/modelfun/test_modelfun.py rename to tests/test_modelfun.py diff --git a/uv.lock b/uv.lock index a0980b0..a18c38f 100644 --- a/uv.lock +++ b/uv.lock @@ -363,6 +363,7 @@ dev = [ { name = "pytest-cov" }, { name = "pytest-custom-exit-code" }, { name = "pytest-github-actions-annotate-failures" }, + { name = "pytest-plt" }, { name = "ruff" }, { name = "snakeviz" }, { name = "sourcery" }, @@ -418,6 +419,7 @@ dev = [ { name = "pytest-cov", specifier = ">=5.0.0" }, { name = "pytest-custom-exit-code", specifier = ">=0.3.0" }, { name = "pytest-github-actions-annotate-failures", specifier = ">=0.2.0" }, + { name = "pytest-plt", specifier = ">=1.1.1" }, { name = "ruff", specifier = ">=0.5.1" }, { name = "snakeviz", specifier = ">=2.2.0" }, { name = "sourcery", specifier = ">=1.21.0" }, @@ -3161,6 +3163,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/eb/86/9ffd9f10a7ba7387ce4ef4362505d739a48dd988051b41d255eb7f102c17/pytest_github_actions_annotate_failures-0.2.0-py3-none-any.whl", hash = "sha256:8bcef65fed503faaa0524b59cfeccc8995130972dd7b008d64193cc41b9cde85", size = 5496 }, ] +[[package]] +name = "pytest-plt" +version = "1.1.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "matplotlib" }, + { name = "pytest" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/0f/bc/2cbd5862edaddf9c06cbb90452e200dbae3106f58ac6b75737cc6e7c14f2/pytest-plt-1.1.1.tar.gz", hash = "sha256:4cebb2547db028aaeecbb481356df3eb6cb3a66053ea5e9170a8683b55d41611", size = 20437 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d9/cd/e479c8ec8487cc2d9cb918a4c6a5391a1de0fc40a9828e1dc85c45cb933e/pytest_plt-1.1.1-py3-none-any.whl", hash = "sha256:f7b700f2a9add47666fc40e03ebd487f29ed20b558249cff48ff4aac62bd6be6", size = 12133 }, +] + [[package]] name = "python-dateutil" version = "2.9.0.post0"