Skip to content

Commit 3e9c9cf

Browse files
Reorganize test folder (#54)
* Reorganize tests folder to match directory structure of project * Skip more tests on windows * Report test speeds * Skip new keynesian tests on windows * Remove quotes * single quotes * escape space * another try * quote the whole string * new matrix argument
1 parent 05e81d8 commit 3e9c9cf

File tree

73 files changed

+1967
-1591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1967
-1591
lines changed

.github/workflows/run_tests.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,54 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
include:
23-
- subset-name: "Model Steady State Tests"
23+
- subset-name: "Steady State Tests"
2424
os: ubuntu-latest
2525
python-version: "3.12"
26-
test-subset: "tests/test_model.py::test_numerical_steady_state tests/test_model.py::test_steady_state tests/test_model.py::test_partially_analytical_steady_state"
27-
- subset-name: "Model Tests"
26+
test-subset: "tests/model/test_steady_state.py tests/model/test_model.py::test_steady_state"
27+
test-marker: ""
28+
29+
- subset-name: "Numerical Steady State Tests"
2830
os: ubuntu-latest
2931
python-version: "3.12"
30-
test-subset: "tests/test_model.py --deselect tests/test_model.py::test_numerical_steady_state --deselect tests/test_model.py::test_steady_state --deselect tests/test_model.py::test_partially_analytical_steady_state"
31-
- subset-name: "Steady State Tests"
32+
test-subset: "tests/model/test_model.py::test_numerical_steady_state tests/model/test_model.py::test_numerical_steady_state_with_calibrated_params tests/model/test_model.py::test_partially_analytical_steady_state"
33+
test-marker: ""
34+
35+
- subset-name: "Perturbation and Statespace Tests"
3236
os: ubuntu-latest
3337
python-version: "3.12"
34-
test-subset: "tests/test_steady_state.py"
35-
- subset-name: "Perturbation Tests"
38+
test-subset: "tests/model/test_perturbation.py tests/model/test_statespace.py"
39+
test-marker: ""
40+
41+
- subset-name: "Other Model Tests"
3642
os: ubuntu-latest
3743
python-version: "3.12"
38-
test-subset: "tests/test_perturbation.py"
44+
test-subset: "tests/model --ignore=tests/model/test_steady_state.py --ignore=tests/model/test_statespace.py --ignore=tests/model/test_perturbation.py --deselect tests/model/test_model.py::test_numerical_steady_state --deselect tests/model/test_model.py::test_numerical_steady_state_with_calibrated_params --deselect tests/model/test_model.py::test_partially_analytical_steady_state"
45+
test-marker: ""
46+
3947
- subset-name: "Other Tests"
4048
os: ubuntu-latest
4149
python-version: "3.12"
42-
test-subset: "tests/ --ignore tests/test_model.py --ignore tests/test_steady_state.py --ignore tests/test_perturbation.py"
50+
test-subset: "tests/ --ignore=tests/model"
51+
test-marker: ""
52+
4353
- subset-name: "Windows Test Model"
4454
os: windows-latest
4555
python-version: "3.13"
46-
test-subset: "tests/test_model.py --deselect tests/test_model.py::test_numerical_steady_state --deselect tests/test_model.py::test_steady_state --deselect tests/test_model.py::test_partially_analytical_steady_state --deselect tests/test_model.py::test_all_backends_agree_on_functions --deselect tests/test_model.py::test_scipy_wrapped_functions_agree"
56+
test-subset: "tests/model --ignore=tests/model/test_steady_state.py --ignore=tests/model/test_statespace.py --ignore=tests/model/test_build.py --deselect tests/model/test_model.py::test_steady_state --deselect tests/model/test_model.py::test_numerical_steady_state --deselect tests/model/test_model.py::test_partially_analytical_steady_state --deselect tests/model/test_model.py::test_all_backends_agree_on_functions --deselect tests/model/test_model.py::test_scipy_wrapped_functions_agree --deselect tests/model/test_model.py::test_all_backends_agree_on_parameters --deselect tests/models/test_model.py::test_simulate"
57+
test-marker: "not include_nk"
58+
4759
- subset-name: "Windows Other Tests"
4860
os: windows-latest
4961
python-version: "3.13"
50-
test-subset: "tests/ --ignore tests/test_model.py --ignore tests/test_steady_state.py --ignore tests/test_perturbation.py"
62+
test-subset: "tests/ --ignore=tests/model"
63+
test-marker: "not include_nk"
64+
5165
name: ${{ matrix.subset-name }} (${{ matrix.os }} Python ${{ matrix.python-version }})
5266
runs-on: ${{ matrix.os }}
5367

5468
env:
5569
TEST_SUBSET: ${{ matrix.test-subset }}
70+
TEST_MARKER: ${{ matrix.test-marker }}
5671

5772
defaults:
5873
run:
@@ -87,7 +102,7 @@ jobs:
87102
88103
- name: Run tests
89104
run: |
90-
python -m pytest -vv --cache-clear --cov=gEconpy --cov-report=xml:coverage/coverage-${MATRIX_ID}.xml --no-cov-on-fail --cov-report term $TEST_SUBSET
105+
python -m pytest -vv --cache-clear --cov=gEconpy --cov-report=xml:coverage/coverage-${MATRIX_ID}.xml --no-cov-on-fail --cov-report term $TEST_SUBSET -m "$TEST_MARKER" --durations=50
91106
env:
92107
MATRIX_ID: ${{ steps.matrix-id.outputs.id }}
93108

gEconpy/model/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytensor.tensor as pt
44
import sympy as sp
5+
from pathlib import Path
56

67
from pymc.pytensorf import rewrite_pregrad
78
from pytensor import graph_replace
@@ -204,7 +205,7 @@ def _compile_gcn(
204205

205206

206207
def model_from_gcn(
207-
gcn_path: str,
208+
gcn_path: str | Path,
208209
simplify_blocks: bool = True,
209210
simplify_tryreduce: bool = True,
210211
simplify_constants: bool = True,

gEconpy/parser/file_loaders.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from warnings import warn
55

66
import sympy as sp
7+
from pathlib import Path
78

89
from gEconpy.classes.containers import SymbolDictionary
910
from gEconpy.classes.time_aware_symbol import TimeAwareSymbol
@@ -33,13 +34,13 @@
3334
_log = logging.getLogger(__name__)
3435

3536

36-
def load_gcn(gcn_path: str) -> str:
37+
def load_gcn(gcn_path: str | Path) -> str:
3738
"""
3839
Loads a model file as raw text.
3940
4041
Parameters
4142
----------
42-
gcn_path : str
43+
gcn_path : str or Path
4344
File path to model file (GCN file).
4445
4546
Returns
@@ -300,7 +301,7 @@ def parsed_model_to_data(
300301

301302

302303
def gcn_to_block_dict(
303-
gcn_path: str, simplify_blocks: bool, include_ss_block=False
304+
gcn_path: str | Path, simplify_blocks: bool, include_ss_block=False
304305
) -> tuple[
305306
dict[str, Block],
306307
ASSUMPTION_DICT,

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ filterwarnings = [
108108
"ignore::DeprecationWarning",
109109
"ignore::RuntimeWarning"]
110110

111+
markers = [
112+
"include_nk: mark tests using the full new keyenesian model (which can be quite slow)",
113+
]
111114

112115
[tool.ruff.lint]
113116
select = ["D", "E", "F", "I", "UP", "W", "RUF"]
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import os
2-
1+
from pathlib import Path
32
from functools import cache
43

54
from gEconpy import model_from_gcn, statespace_from_gcn
@@ -11,7 +10,7 @@ def load_and_cache_model(gcn_file, backend, use_jax=False):
1110
if backend == "pytensor" and use_jax:
1211
compile_kwargs["mode"] = "JAX"
1312

14-
gcn_path = os.path.join("tests", "Test GCNs", gcn_file)
13+
gcn_path = Path("tests") / "_resources" / "test_gcns" / gcn_file
1514
model = model_from_gcn(
1615
gcn_path,
1716
verbose=False,
@@ -24,7 +23,7 @@ def load_and_cache_model(gcn_file, backend, use_jax=False):
2423

2524
@cache
2625
def load_and_cache_statespace(gcn_file):
27-
gcn_path = os.path.join("tests", "Test GCNs", gcn_file)
26+
gcn_path = Path("tests") / "_resources" / "test_gcns" / gcn_file
2827
statespace = statespace_from_gcn(gcn_path, verbose=False)
2928

3029
return statespace

tests/dynare_outputs/basic_rbc_loglinear_results.mat renamed to tests/_resources/dynare_outputs/basic_rbc_loglinear_results.mat

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)