-
-
Notifications
You must be signed in to change notification settings - Fork 622
chore: enable pytest ruff rule and apply fixes #4928
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Aswinr24! Where did you get the match="string"
strings from, as most of them are wrong? Is it from an older version of PyBaMM?
Please see my comments below to fix the tests.
tests/unit/test_expression_tree/test_operations/test_convert_to_casadi.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Aswinr24! This looks good now. Could you please resolve the conflicts?
Yes thanks!, would resolve the conflicts and push it |
Was thinking to open the PR to enable isort rule along with its suggested fixes as well |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4928 +/- ##
========================================
Coverage 98.58% 98.58%
========================================
Files 304 304
Lines 23689 23689
========================================
Hits 23353 23353
Misses 336 336 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Aswinr24! Please see my comments below -
@@ -689,7 +689,7 @@ def test_failures(self): | |||
solver = pybamm.IDAKLUSolver() | |||
|
|||
t_eval = [0, 3] | |||
with pytest.raises(ValueError): | |||
with pytest.raises(ValueError, match="std::exception"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error raised is different on Windows and UNIX. Can we not have match=
here (ignore the rule) and add a comment for future reference -
# raises `std::exception` on UNIX and `IDA failed with flag -22` on Windows
with pytest.raises(ValueError) # noqa: ...
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, Will add this comment and ignore the rule here
@@ -894,7 +894,7 @@ def test_solver_options(self): | |||
options = {option: options_fail[option]} | |||
solver = pybamm.IDAKLUSolver(options=options) | |||
|
|||
with pytest.raises(ValueError): | |||
with pytest.raises(ValueError, match="std::exception"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto!
Yes, sounds good to me. |
pre-commit.ci run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now, thanks, @Aswinr24!
Thanks! |
interp = pybamm.Interpolant(x4_, data4, y4, interpolator="linear") | ||
interp_casadi = interp.to_casadi(y=casadi_y) | ||
interp_casadi = interp.to_casadi(y=casadi_y) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part looks off to me. If the raise value error happens in the pybamm.Interpolant()
line then the to_casadi()
line does nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few other places with similar changes
with pytest.raises(pybamm.OptionError, match="natural numbers"): | ||
options = {"number of rc elements": -1} | ||
options = {"number of rc elements": -1} | ||
with pytest.raises(pybamm.OptionError, match="natural numbers"): # noqa: PT012 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is being suppressed here?
Description
This PR enables additional Ruff linting rules and applies fixes to the codebase as suggested by Ruff. The changes include:
Enabling PT (pytest-style) rules in pyproject.toml.
fixes issues raised by ruff linter which included:
pytest.raises()
is called with amatch
parameter to avoid catching overly broad exceptions.pytest.raises()
context managers contains only a single statement.Related to #4925
Type of change
Key checklist:
$ pre-commit run
(or$ nox -s pre-commit
) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)$ python -m pytest
(or$ nox -s tests
)$ python -m pytest --doctest-plus src
(or$ nox -s doctests
)You can run integration tests, unit tests, and doctests together at once, using
$ nox -s quick
.Further checks: