Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Lint tests #1127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Feb 19, 2025
Merged

Lint tests #1127

merged 24 commits into from
Feb 19, 2025

Conversation

roryyorke
Copy link
Contributor

This extends ruff testing to control/tests/*.py

I've tried to order the commits from obvious to subtle; on the whole:

  • remove unused imports
  • removed unused variables, or sometimes prefix with '_' where that seemed to make things clearer
  • tweaked two eval calls

The remaining errors I'm less sure of. It would be simple to silence them with # noqa: F<relevant code>, and defer fixing these to later; then at least no new ruff errors will sneak in in the future.

More detail on remaining failures:

control/tests/kwargs_test.py

Here the dict literal has repeated keys for 'StateSpace.__init__' and 'StateSpace.__sample':

    'StateSpace.__init__':
        interconnect_test.test_interconnect_exceptions,
    'StateSpace.sample': test_unrecognized_kwargs,
    'NonlinearIOSystem.__init__':
        interconnect_test.test_interconnect_exceptions,
    'StateSpace.__init__': test_unrecognized_kwargs,
    'StateSpace.initial_response': timeresp_test.test_timeresp_aliases,
    'StateSpace.sample': test_unrecognized_kwargs,

Last-value-wins in dict literals, so the first two entries have no effect. It looks like this is just a check that something exists, so I guess we can just erase the first two entries?

control/tests/modelsimp_test.py

The variable mrk is assigned to: mrk = markov(outp, inp, 1, transpose=False). I didn't investigate issue #395 referenced above -- is it enough that this call doesn't raise?

control/tests/optimal_test.py

curved_seg_length is calculated, but not used. It's not obviously copy-and-pasted from another test, so I'm not sure if the test should be changed here. It's obviously easy enough to just remove this variable, and straight_seg_length just above it.

Where it's clear that function is called for side effects (e.g., in a
q`with pytest.raises` block), don't assign function output.  Where
it's not clear, e.g., binary ops on LTI objects, call result `_sys` or
similar.  There are plenty of in-between cases: for those I chose
based on understandability.
Where imports were test fixtures, replaced with
`@pytest.mark.usefixtures('nameoffixture')`.
Provide relevant symbols via `locals` argument to eval.
Symbol reference in lambda which is never called.
The test had no assertions, but have been intended to test MIMO
feedback; for this see testMIMOfb in same file.
The function doesn't exist, but the test is never called.
slycontonly is not a fixture.
It looks like a block of code was copied-and-pasted between two test
functions; removed the unused variable in each case.
@roryyorke roryyorke marked this pull request as draft February 16, 2025 10:42
Only works from Python 3.13.
@coveralls
Copy link

coveralls commented Feb 16, 2025

Coverage Status

coverage: 94.744%. remained the same
when pulling c907a4f on roryyorke:lint-tests
into 2a919cc on python-control:main.

@murrayrm
Copy link
Member

control/tests/kwargs_test.py

Correct that there just needs to be some test that verifies that unknown keywords generate an error. Whichever of the tests that has that check should be kept and if both do then keeping either is fine.

control/tests/modelsimp_test.py

Correct that the intent of this test was just to make sure an exception wasn't raised. We could either get rid of the assignment to mrk or check the output to make sure it does something sensible. For example:

np.testing.assert_almost_equal(mrk, 2.)

control/tests/optimal_test.py

I'm pretty sure I wrote this example and I can't see any reason to keep straight_seg_length or curved_seg_length.

@roryyorke roryyorke marked this pull request as ready for review February 16, 2025 17:45
@roryyorke roryyorke changed the title [WIP] Lint tests Lint tests Feb 16, 2025
@roryyorke
Copy link
Contributor Author

Oops - had a commit there I'd intended for another PR. Reverted.

If this PR isn't merged now, it'll be worth merging main into the PR before merging the PR to main, to make sure the lint checks don't causes failures on main after the merge of the PR. (I hope that sentence is less confusing than I think it is!)

@murrayrm murrayrm merged commit f6799ab into python-control:main Feb 19, 2025
24 checks passed
@murrayrm murrayrm added this to the 0.10.2 milestone Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants