Skip to content

Commit

Permalink
Moving a bunch of integration test files to pytest. (#4238)
Browse files Browse the repository at this point in the history
* Moving a bunch of integration test files to pytest

Signed-off-by: Pradyot Ranjan <[email protected]>

* style: pre-commit fixes

---------

Signed-off-by: Pradyot Ranjan <[email protected]>
Co-authored-by: Pradyot Ranjan <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Arjun Verma <[email protected]>
Co-authored-by: Agriya Khetarpal <[email protected]>
  • Loading branch information
5 people authored Jul 3, 2024
1 parent e625a09 commit 3ed1405
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 258 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import pybamm
import unittest
import tests
from tests import TestCase


class TestThevenin(TestCase):
class TestThevenin:
def test_basic_processing(self):
model = pybamm.equivalent_circuit.Thevenin()
modeltest = tests.StandardModelTest(model)
modeltest.test_all()


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#
# Tests for the asymptotic convergence of the simplified models
#
from tests import TestCase
import pybamm

import numpy as np
import unittest


class TestAsymptoticConvergence(TestCase):
class TestAsymptoticConvergence:
def test_leading_order_convergence(self):
"""
Check that the leading-order model solution converges linearly in C_e to the
Expand Down Expand Up @@ -72,12 +70,3 @@ def get_max_error(current):
loqs_rates = np.log2(loqs_errs[:-1] / loqs_errs[1:])

np.testing.assert_array_less(0.99 * np.ones_like(loqs_rates), loqs_rates)


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#
# Compare basic models with full models
#
from tests import TestCase
import pybamm

import numpy as np
import unittest


class TestCompareBasicModels(TestCase):
class TestCompareBasicModels:
def test_compare_full(self):
basic_full = pybamm.lead_acid.BasicFull()
full = pybamm.lead_acid.Full()
Expand Down Expand Up @@ -39,12 +37,3 @@ def test_compare_full(self):
np.testing.assert_allclose(
basic_sol[name].entries, sol[name].entries, rtol=1e-4, atol=1e-8
)


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#
# Tests for the asymptotic convergence of the simplified models
#
from tests import TestCase
import pybamm
import numpy as np
import unittest
from tests import StandardOutputComparison


class TestCompareOutputs(TestCase):
class TestCompareOutputs:
def test_compare_averages_asymptotics(self):
"""
Check that the average value of certain variables is constant across submodels
Expand Down Expand Up @@ -87,12 +85,3 @@ def test_compare_outputs_surface_form(self):
# compare outputs
comparison = StandardOutputComparison(solutions)
comparison.test_all(skip_first_timestep=True)


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#
# Tests for the lead-acid Full model
#
from tests import TestCase
import pybamm
import tests

import unittest
import numpy as np


class TestLeadAcidFull(TestCase):
class TestLeadAcidFull:
def test_basic_processing(self):
options = {"thermal": "isothermal"}
model = pybamm.lead_acid.Full(options)
Expand Down Expand Up @@ -56,7 +54,7 @@ def test_basic_processing_1plus1D(self):
modeltest.test_all(skip_output_tests=True)


class TestLeadAcidFullSurfaceForm(TestCase):
class TestLeadAcidFullSurfaceForm:
def test_basic_processing_differential(self):
options = {"surface form": "differential"}
model = pybamm.lead_acid.Full(options)
Expand Down Expand Up @@ -88,12 +86,3 @@ def test_thermal(self):
model = pybamm.lead_acid.Full(options)
modeltest = tests.StandardModelTest(model)
modeltest.test_all()


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#
# Tests for the lead-acid LOQS model
#
from tests import TestCase
import pybamm
import tests

import unittest
import numpy as np


class TestLOQS(TestCase):
class TestLOQS:
def test_basic_processing(self):
model = pybamm.lead_acid.LOQS()
modeltest = tests.StandardModelTest(model)
Expand Down Expand Up @@ -74,12 +72,3 @@ def test_basic_processing_1plus1D(self):
model = pybamm.lead_acid.LOQS(options)
modeltest = tests.StandardModelTest(model, var_pts=var_pts)
modeltest.test_all(skip_output_tests=True)


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#
# Tests for the lead-acid LOQS model with capacitance
#
from tests import TestCase
import pybamm
import tests

import unittest

import pytest
import numpy as np


class TestLeadAcidLoqsSurfaceForm(TestCase):
class TestLeadAcidLoqsSurfaceForm:
def test_basic_processing(self):
options = {"surface form": "algebraic"}
model = pybamm.lead_acid.LOQS(options)
Expand All @@ -23,7 +20,7 @@ def test_basic_processing_with_capacitance(self):
modeltest = tests.StandardModelTest(model)
modeltest.test_all()

@unittest.skip("model not working for 1+1D differential")
@pytest.mark.skip(reason="model not working for 1+1D differential")
def test_basic_processing_1p1D_differential(self):
options = {
"surface form": "differential",
Expand Down Expand Up @@ -59,12 +56,3 @@ def test_set_up(self):
optimtest = tests.OptimisationsTest(model)
optimtest.set_up_model(to_python=True)
optimtest.set_up_model(to_python=False)


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#
# Tests for the lead-acid Full model
#
from tests import TestCase
import pybamm
import tests

import unittest
import numpy as np


class TestLeadAcidFullSideReactions(TestCase):
class TestLeadAcidFullSideReactions:
def test_basic_processing(self):
options = {"hydrolysis": "true"}
model = pybamm.lead_acid.Full(options)
Expand Down Expand Up @@ -45,12 +43,3 @@ def test_basic_processing_zero_current(self):
parameter_values.update({"Current function [A]": 0})
modeltest = tests.StandardModelTest(model, parameter_values=parameter_values)
modeltest.test_all(skip_output_tests=True)


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#
# Tests for the lead-acid LOQS model
#
from tests import TestCase
import pybamm
import tests
import unittest


class TestLeadAcidLOQSWithSideReactions(TestCase):
class TestLeadAcidLOQSWithSideReactions:
def test_discharge_differential(self):
options = {"surface form": "differential", "hydrolysis": "true"}
model = pybamm.lead_acid.LOQS(options)
Expand Down Expand Up @@ -46,12 +44,3 @@ def test_zero_current(self):
parameter_values.update({"Current function [A]": 0})
modeltest = tests.StandardModelTest(model, parameter_values=parameter_values)
modeltest.test_all(skip_output_tests=True)


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#
# Test basic model classes
#
from tests import TestCase
import pybamm

import unittest
import pytest


class BaseBasicModelTest:
Expand All @@ -21,31 +19,26 @@ def test_with_experiment(self):
sim.solve(calc_esoh=False)


class TestBasicSPM(BaseBasicModelTest, TestCase):
class TestBasicSPM(BaseBasicModelTest):
@pytest.fixture(autouse=True)
def setUp(self):
self.model = pybamm.lithium_ion.BasicSPM()


class TestBasicDFN(BaseBasicModelTest, TestCase):
class TestBasicDFN(BaseBasicModelTest):
@pytest.fixture(autouse=True)
def setUp(self):
self.model = pybamm.lithium_ion.BasicDFN()


class TestBasicDFNComposite(BaseBasicModelTest, TestCase):
class TestBasicDFNComposite(BaseBasicModelTest):
@pytest.fixture(autouse=True)
def setUp(self):
self.model = pybamm.lithium_ion.BasicDFNComposite()


class TestBasicDFNHalfCell(BaseBasicModelTest, TestCase):
class TestBasicDFNHalfCell(BaseBasicModelTest):
@pytest.fixture(autouse=True)
def setUp(self):
options = {"working electrode": "positive"}
self.model = pybamm.lithium_ion.BasicDFNHalfCell(options)


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#
# Compare basic models with full models
#
from tests import TestCase
import pybamm

import numpy as np
import unittest


class TestCompareBasicModels(TestCase):
class TestCompareBasicModels:
def test_compare_dfns(self):
parameter_values = pybamm.ParameterValues("Ecker2015")
basic_dfn = pybamm.lithium_ion.BasicDFN()
Expand Down Expand Up @@ -88,12 +86,3 @@ def test_compare_spms(self):
np.testing.assert_allclose(
basic_sol[name].entries, sol[name].entries, rtol=1e-4
)


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

if "-v" in sys.argv:
debug = True
unittest.main()
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#
# Tests for the lithium-ion DFN half-cell model
#
from tests import TestCase
import pybamm
import unittest
from tests import BaseIntegrationTestLithiumIonHalfCell
import pytest


class TestDFNHalfCell(BaseIntegrationTestLithiumIonHalfCell, TestCase):
class TestDFNHalfCell(BaseIntegrationTestLithiumIonHalfCell):
@pytest.fixture(autouse=True)
def setUp(self):
self.model = pybamm.lithium_ion.DFN


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

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

0 comments on commit 3ed1405

Please sign in to comment.