Repository navigation
Lint tests/ with muff-check; fix the lint violations - #72
Merged
Merged
Conversation
Remove the `lint.exclude` for `tests/` in `muff.toml`, so `muff-check` also lints the test files, and fix the violations: - Use plain `assert` statements and `pytest.raises()` instead of the `unittest`-style assertion methods (PT009, PT027). `assertAlmostEqual()` becomes `pytest.approx()`, with `abs=` set to its `delta` (or to 1e-7, its default precision of 7 decimal places) - Read the data files via `pathlib` instead of `os.path` (PTH118, PTH120). Paths passed to PySeismoSoil are converted with `str()`, since its functions check for `str` file names - Escape the literal `match=` patterns with `re.escape()` (RUF043) - Add return type annotations (ANN201 etc.), move imports to the top level, remove unused variables, wrap long lines, and keep one statement in each `pytest.raises()` block Test-specific ignores (INP001, PLR0904, PLR6301, SLF001) are added to the `tests/*` per-file ignores. The SVM test that checks numpy's legacy global random state keeps its `np.random` calls, with inline `noqa: NPY002`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TaAeTVJL3sqwsptnDto2WD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TaAeTVJL3sqwsptnDto2WD
Three leftovers from the automatic conversion to plain `assert`: - `test_Vs_cap_is_user_defined` compared with `pytest.approx(1234.5)` (about +/-0.001), instead of the original exact equality. Compare with the `Vs_cap` variable instead, which keeps the exact check and avoids the float literal that RUF069 flags - `nearly_identical()` returned `r >= thres`, which is `False` for a NaN correlation, whereas the original returned `True`. Use `not r < thres`, which matches the original for every value - The auto-fixer re-spelled number literals inside the asserts it rewrote (e.g., `6.4e7` -> `64000000.0`, `0.9980` -> `0.998`, `1e-5` -> `1e-05`). Restore the original spellings (same values) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TaAeTVJL3sqwsptnDto2WD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TaAeTVJL3sqwsptnDto2WD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #71:
muff-checknow lintstests/too, and all ~1,060 violations there are fixed.Config (
muff.toml)lint.exclude = ["tests/**"]."tests/*"per-file ignores, next toPLC2701/PLR2004:INP001:tests/is not a package; pytest runs the files directlyPLR0904: a test class can group many testsPLR6301: test methods inunittest.TestCaseclasses don't useself(221 hits after the assertion changes below)SLF001: tests can check private members (75 hits)Fixes in
tests/*.pyPT009/PT027(476 hits):self.assertTrue/Equal/...→ plainassert, andself.assertRaises(Regex)→pytest.raises(match=...), mostly with muff's fixes. The auto-fixer re-spelled some number literals (e.g.,6.4e7→64000000.0), so I restored the original spellings. The 40assertAlmostEqualcalls becamepytest.approx(b, abs=delta). Where nodeltawas given, I usedabs=1e-7, close to its default of 7 decimal places. The test classes still inherit fromunittest.TestCase, so theif __name__ == '__main__'runners still work.PTH118/PTH120(184 hits):f_dir = Path(__file__).resolve().parent / 'files'. Paths passed to PySeismoSoil are wrapped instr(...), because the library checksisinstance(data, str)to tell a file name from an array.np.genfromtxttakes thePathdirectly.RUF043: literalmatch=strings that contain.etc. are wrapped inre.escape().ANN*:-> Noneon test methods; annotated thenearly_identical()helper and the__init__overrides.PLC0415)_(F841,RUF059)E501), and three over-long test names shortenedpytest.raises()block (PT012)PERF401)return not r[1, 0] < thres(SIM103; same result as before, including whenris NaN)test_Vs_cap_is_user_defined, compare with aVs_capvariable instead of the float literal1234.5(RUF069); still an exact comparisonNPY002: kept as inline# noqain one SVM test. That test checks on purpose thatget_randomized_profile()doesn't change numpy's legacy global random state, so it has to callnp.random.seed()andnp.random.random().Docs
CONTRIBUTING.mdandCHANGELOG.mdare updated:tests/is now linted, and tests use plainassertandpytest.raises().Notebooks
examples/*.ipynbre-run, as every PR requires.Test logic is unchanged
I compared every test function with
mainafter parsing both versions. I mapped eachself.assert*()call to its plain-assertform andos.path.jointopathlib, and ignored annotations and moved imports. The other differences fall into these groups:0 == x→x == 0)_Vs_capvariablenot r < threspytest.raises()blocks now hold only the call that should raise; the setup moved out (PT012)match=patterns are escaped, so.matches only a literal periodassertAlmostEqualcalls withoutdeltanow allow an absolute difference of up to1e-7. unittest's default (rounding to 7 decimal places) is about5e-8.Number literal values, comments (apart from line wrapping and the removed
# noqa: F841), class bases and module-level code are all unchanged. Both versions collect the same 262 tests, apart from the 3 renamed ones.Test plan
pytest tests: 262 passed (same tests as before)pre-commit run -a: all hooks pass, includingmuff-checkontests/tox -e run-notebooks: all notebooks ran without errors🤖 Generated with Claude Code
https://claude.ai/code/session_01TaAeTVJL3sqwsptnDto2WD