Skip to content

Commit

Permalink
Final pytest migration (#4443)
Browse files Browse the repository at this point in the history
* Final pytest migration

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

* style: pre-commit fixes

* Fixing assert failures

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

* converting test_idaklu_jax.py and test_solution.py to pytest

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

* style: pre-commit fixes

* removinh style failures

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

* using single argument

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

* Updating docs

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

---------

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Co-authored-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 28, 2024
1 parent 62a7ee8 commit b6fa67a
Show file tree
Hide file tree
Showing 10 changed files with 692 additions and 789 deletions.
2 changes: 1 addition & 1 deletion docs/source/user_guide/installation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ Dependency
`pre-commit <https://pre-commit.com/index.html>`__ \- dev For managing and maintaining multi-language pre-commit hooks.
`ruff <https://beta.ruff.rs/docs/>`__ \- dev For code formatting.
`nox <https://nox.thea.codes/en/stable/>`__ \- dev For running testing sessions in multiple environments.
`pytest-subtests <https://github.com/pytest-dev/pytest-subtests/>`__ \- dev For subtests pytest fixture.
`pytest-cov <https://pytest-cov.readthedocs.io/en/stable/>`__ \- dev For calculating test coverage.
`parameterized <https://github.com/wolever/parameterized>`__ \- dev For test parameterization.
`pytest <https://docs.pytest.org/en/stable/>`__ 6.0.0 dev For running the test suites.
`pytest-doctestplus <https://github.com/scientific-python/pytest-doctestplus>`__ \- dev For running doctests.
`pytest-xdist <https://pytest-xdist.readthedocs.io/en/latest/>`__ \- dev For running tests in parallel across distributed workers.
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ dev = [
"pytest-cov",
# For doctest
"pytest-doctestplus",
# For test parameterization
"parameterized>=0.9",
# pytest and its plugins
"pytest>=6",
"pytest-xdist",
"pytest-mock",
"pytest-subtests",
# For testing Jupyter notebooks
"nbmake",
# To access the metadata for python packages
Expand Down Expand Up @@ -230,6 +229,7 @@ minversion = "8"
required_plugins = [
"pytest-xdist",
"pytest-mock",
"pytest-subtests",
]
norecursedirs = 'pybind11*'
addopts = [
Expand Down
168 changes: 77 additions & 91 deletions tests/unit/test_experiments/test_simulation_with_experiment.py

Large diffs are not rendered by default.

654 changes: 320 additions & 334 deletions tests/unit/test_expression_tree/test_binary_operators.py

Large diffs are not rendered by default.

Large diffs are not rendered by default.

18 changes: 4 additions & 14 deletions tests/unit/test_parameters/test_parameter_sets/test_OKane2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Tests for O'Kane (2022) parameter set
#

import pytest
import pybamm
import unittest


class TestOKane2022(unittest.TestCase):
class TestOKane2022:
def test_functions(self):
param = pybamm.ParameterValues("OKane2022")
sto = pybamm.Scalar(0.9)
Expand Down Expand Up @@ -40,16 +40,6 @@ def test_functions(self):
}

for name, value in fun_test.items():
self.assertAlmostEqual(
param.evaluate(param[name](*value[0])), value[1], places=4
assert param.evaluate(param[name](*value[0])) == pytest.approx(
value[1], abs=0.0001
)


if __name__ == "__main__":
print("Add -v for more debug output")
import sys

if "-v" in sys.argv:
debug = True
pybamm.settings.debug_mode = True
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
#

import pybamm
import unittest


class TestParameterValuesWithModel(unittest.TestCase):
def test_parameter_values_with_model(self):
class TestParameterValuesWithModel:
def test_parameter_values_with_model(self, subtests):
param_to_model = {
"Ai2020": pybamm.lithium_ion.DFN(
{"particle mechanics": "swelling and cracking"}
Expand Down Expand Up @@ -46,16 +45,6 @@ def test_parameter_values_with_model(self):

# Loop over each parameter set, testing that parameters can be set
for param, model in param_to_model.items():
with self.subTest(param=param):
with subtests.test(param=param):
parameter_values = pybamm.ParameterValues(param)
parameter_values.process_model(model)


if __name__ == "__main__":
print("Add -v for more debug output")
import sys

if "-v" in sys.argv:
debug = True
pybamm.settings.debug_mode = True
unittest.main()
Loading

0 comments on commit b6fa67a

Please sign in to comment.