Add real pytest tests and CI linting (black, ruff, mypy)#8
Conversation
|
This merge would close #2 |
…black/ruff/mypy Co-authored-by: dantzert <47285626+dantzert@users.noreply.github.com>
tests/test_modpods.py
Outdated
| These tests cover the functions that are self-contained and do not require | ||
| external data files or long-running simulations. |
There was a problem hiding this comment.
The tests should include the larger data files that are tracked in version control as well. Move any larger files to tests/data and give them a pytest slow mark, but don't skip them in CI.
Further, those old testing files should be deleted once all their functions are collected
There was a problem hiding this comment.
Done in commit a1705b9. Here's what was addressed:
- All 7 old test scripts deleted — functions collected from:
test.py,test_coef_constraints.py,test_lti_from_gamma.py,test_lti_system_gen.py,test_topo_from_swmm.py,test_lti_control_of_swmm.py,test_topo_inference.py - Large data files moved to
tests/data/—03439000_05_model_output.txt(1.4 MB) andswmm_lti_plant_approx_seeing.pickle(53 KB) @pytest.mark.slowapplied to tests that load those files or run long pystorms/training simulations (5 tests); the CI workflow runs all tests including slow onesslowmarker registered inpyproject.toml
The conversion also required fixing several upstream compatibility issues in modpods.py to make the tests pass against current deps (pandas 3.x CoW, pysindy 2.x API, numpy 2.x, pyswmm 2.x multi-simulation guard), so all 18 tests now pass in ~2.5 minutes.
|
@copilot please address the feedback in my latest code review and send a notification once you've passed CI and are ready for my review |
… dependency compat Co-authored-by: dantzert <47285626+dantzert@users.noreply.github.com>
The existing "test" files were standalone scripts with no assertions or pytest structure — nothing discoverable or verifiable by a test runner. This PR converts the project to proper pytest and wires up a CI pipeline with linting.
Changes
modpods.pyinfer_causative_topology:total_graphwas initialized asobjectdtype, breakingnx.from_pandas_adjacencyon newer NetworkX. Addeddtype=floatto the DataFrame constructor.transform_inputsfor pandas 3.x Copy-on-Write: column accumulation now uses a numpy array before assignment.ps.SINDy()calls: removedfeature_namesparameter (dropped in pysindy 2.x).ConstrainedSR3usage: imported frompysindy.optimizers._constrained_sr3; updated parameter names (threshold→reg_weight_lam,thresholder→regularizer,nu→relax_coeff_nu).library.fit()inlti_system_gen: replacedAxesArraywrapping a Python list with a plainnp.zerosarray.constraint_rhs = 0scalar →np.zeros(1)array for pysindy 2.x compatibility.A/B/Cmatrix finalization inlti_system_gen: replacedfillna(0)(which ignores non-NaN string values) withpd.to_numeric(errors='coerce').fillna(0).topo_from_pystorms: resets pyswmm 2.x single-simulation guard before opening its own connection.np.NAN→np.nanthroughout (removed in numpy 2.x).tests/test_modpods.pyExpanded from 8 to 18 pytest tests covering all original test scripts (now deleted):
lti_from_gamma(4)test_lti_from_gamma.pydelay_io_train+delay_io_predict(4)test_coef_constraints.pyinfer_causative_topology(4)test_topo_inference.pylti_system_gen(1)test_lti_system_gen.py@pytest.mark.slowtopo_from_pystormszeta (2)test_topo_from_swmm.py@pytest.mark.slowtopo_from_pystormsgamma (1)test_lti_control_of_swmm.py@pytest.mark.slowtest.py@pytest.mark.slowAll 18 tests run in CI (slow tests are marked but not skipped).
tests/data/Large data files tracked in version control moved here from the repo root:
03439000_05_model_output.txt(1.4 MB CAMELS daily streamflow data)swmm_lti_plant_approx_seeing.pickle(53 KB trained SWMM plant model)Old test scripts deleted
test.py,test_coef_constraints.py,test_lti_from_gamma.py,test_lti_system_gen.py,test_topo_from_swmm.py,test_lti_control_of_swmm.py,test_topo_inference.pyInfrastructure
requirements.txt— updated to pysindy≥2.0; added cvxpy, pystorms, dillpyproject.toml— black, ruff (E/F/W/I, no E501), mypy (lenient for untyped codebase), pytesttestpaths,slowmarker registered.github/workflows/ci.yml— runsblack --check tests/,ruff check tests/,mypy tests/ modpods.py, thenpytest tests/ -von every push/PR; scoped withpermissions: contents: readOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.