Skip to content

Commit

Permalink
pybamm-team#1182 some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Apr 6, 2023
1 parent b79d25f commit 2f4ad5c
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/unit/test_citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@contextlib.contextmanager
def temporary_filename():
"""Create a temporary-file and return yield it's filename"""
"""Create a temporary-file and return yield its filename"""

f = NamedTemporaryFile(delete=False)
try:
Expand Down Expand Up @@ -116,6 +116,7 @@ def test_marquis_2019(self):
self.assertNotIn("Marquis2019", citations._papers_to_cite)
pybamm.lithium_ion.SPM(build=False)
self.assertIn("Marquis2019", citations._papers_to_cite)
self.assertIn("Marquis2019", citations._citation_tags.keys())

citations._reset()
pybamm.lithium_ion.SPMe(build=False)
Expand All @@ -127,6 +128,7 @@ def test_doyle_1993(self):
self.assertNotIn("Doyle1993", citations._papers_to_cite)
pybamm.lithium_ion.DFN(build=False)
self.assertIn("Doyle1993", citations._papers_to_cite)
self.assertIn("Doyle1993", citations._citation_tags.keys())

def test_sulzer_2019(self):
# Test that calling relevant bits of code adds the right paper to citations
Expand All @@ -136,10 +138,12 @@ def test_sulzer_2019(self):
self.assertNotIn("Sulzer2019asymptotic", citations._papers_to_cite)
pybamm.lead_acid.LOQS(build=False)
self.assertIn("Sulzer2019asymptotic", citations._papers_to_cite)
self.assertIn("Sulzer2019asymptotic", citations._citation_tags.keys())

citations._reset()
pybamm.lead_acid.Full(build=False)
self.assertIn("Sulzer2019physical", citations._papers_to_cite)
self.assertIn("Sulzer2019physical", citations._citation_tags.keys())

def test_timms_2021(self):
# Test that calling relevant bits of code adds the right paper to citations
Expand All @@ -149,36 +153,43 @@ def test_timms_2021(self):
self.assertNotIn("Timms2021", citations._papers_to_cite)
pybamm.current_collector.BasePotentialPair(param=None)
self.assertIn("Timms2021", citations._papers_to_cite)
self.assertIn("Timms2021", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Timms2021", citations._papers_to_cite)
pybamm.current_collector.EffectiveResistance()
self.assertIn("Timms2021", citations._papers_to_cite)
self.assertIn("Timms2021", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Timms2021", citations._papers_to_cite)
pybamm.current_collector.AlternativeEffectiveResistance2D()
self.assertIn("Timms2021", citations._papers_to_cite)
self.assertIn("Timms2021", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Timms2021", citations._papers_to_cite)
pybamm.thermal.pouch_cell.CurrentCollector1D(param=None)
self.assertIn("Timms2021", citations._papers_to_cite)
self.assertIn("Timms2021", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Timms2021", citations._papers_to_cite)
pybamm.thermal.pouch_cell.CurrentCollector2D(param=None)
self.assertIn("Timms2021", citations._papers_to_cite)
self.assertIn("Timms2021", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Timms2021", citations._papers_to_cite)
pybamm.thermal.Lumped(param=None)
self.assertIn("Timms2021", citations._papers_to_cite)
self.assertIn("Timms2021", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Timms2021", citations._papers_to_cite)
pybamm.thermal.OneDimensionalX(param=None)
self.assertIn("Timms2021", citations._papers_to_cite)
self.assertIn("Timms2021", citations._citation_tags.keys())

def test_subramanian_2005(self):
# Test that calling relevant bits of code adds the right paper to citations
Expand All @@ -190,13 +201,15 @@ def test_subramanian_2005(self):
None, "negative", {"particle": "quadratic profile"}, "primary"
)
self.assertIn("Subramanian2005", citations._papers_to_cite)
self.assertIn("Subramanian2005", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Subramanian2005", citations._papers_to_cite)
pybamm.particle.PolynomialProfile(
None, "negative", {"particle": "quadratic profile"}, "primary"
)
self.assertIn("Subramanian2005", citations._papers_to_cite)
self.assertIn("Subramanian2005", citations._citation_tags.keys())

def test_brosaplanella_2021(self):
# Test that calling relevant bits of code adds the right paper to citations
Expand All @@ -206,6 +219,7 @@ def test_brosaplanella_2021(self):
self.assertNotIn("BrosaPlanella2021", citations._papers_to_cite)
pybamm.electrolyte_conductivity.Integrated(None)
self.assertIn("BrosaPlanella2021", citations._papers_to_cite)
self.assertIn("BrosaPlanella2021", citations._citation_tags.keys())

def test_brosaplanella_2022(self):
# Test that calling relevant bits of code adds the right paper to citations
Expand Down Expand Up @@ -235,6 +249,7 @@ def test_brosaplanella_2022(self):
build=False, options={"lithium plating": "irreversible"}
)
self.assertIn("BrosaPlanella2022", citations._papers_to_cite)
self.assertIn("BrosaPlanella2022", citations._citation_tags.keys())
citations._reset()

def test_newman_tobias(self):
Expand All @@ -246,7 +261,9 @@ def test_newman_tobias(self):
self.assertNotIn("Chu2020", citations._papers_to_cite)
pybamm.lithium_ion.NewmanTobias()
self.assertIn("Newman1962", citations._papers_to_cite)
self.assertIn("Newman1962", citations._citation_tags.keys())
self.assertIn("Chu2020", citations._papers_to_cite)
self.assertIn("Chu2020", citations._citation_tags.keys())

def test_scikit_fem(self):
citations = pybamm.citations
Expand All @@ -255,6 +272,7 @@ def test_scikit_fem(self):
self.assertNotIn("Gustafsson2020", citations._papers_to_cite)
pybamm.ScikitFiniteElement()
self.assertIn("Gustafsson2020", citations._papers_to_cite)
self.assertIn("Gustafsson2020", citations._citation_tags.keys())

def test_reniers_2019(self):
# Test that calling relevant bits of code adds the right paper to citations
Expand All @@ -264,6 +282,7 @@ def test_reniers_2019(self):
self.assertNotIn("Reniers2019", citations._papers_to_cite)
pybamm.active_material.LossActiveMaterial(None, "negative", None, True)
self.assertIn("Reniers2019", citations._papers_to_cite)
self.assertIn("Reniers2019", citations._citation_tags.keys())

def test_mohtat_2019(self):
citations = pybamm.citations
Expand All @@ -274,6 +293,7 @@ def test_mohtat_2019(self):
pybamm.ParameterValues("Marquis2019")
)._get_electrode_soh_sims_full()
self.assertIn("Mohtat2019", citations._papers_to_cite)
self.assertIn("Mohtat2019", citations._citation_tags.keys())

def test_mohtat_2021(self):
citations = pybamm.citations
Expand All @@ -282,6 +302,7 @@ def test_mohtat_2021(self):
self.assertNotIn("Mohtat2021", citations._papers_to_cite)
pybamm.external_circuit.CCCVFunctionControl(None, None)
self.assertIn("Mohtat2021", citations._papers_to_cite)
self.assertIn("Mohtat2021", citations._citation_tags.keys())

def test_sripad_2020(self):
citations = pybamm.citations
Expand All @@ -290,42 +311,54 @@ def test_sripad_2020(self):
self.assertNotIn("Sripad2020", citations._papers_to_cite)
pybamm.kinetics.Marcus(None, None, None, None, None)
self.assertIn("Sripad2020", citations._papers_to_cite)
self.assertIn("Sripad2020", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Sripad2020", citations._papers_to_cite)
pybamm.kinetics.MarcusHushChidsey(None, None, None, None, None)
self.assertIn("Sripad2020", citations._papers_to_cite)
self.assertIn("Sripad2020", citations._citation_tags.keys())

def test_parameter_citations(self):
citations = pybamm.citations

citations._reset()
pybamm.ParameterValues("Chen2020")
self.assertIn("Chen2020", citations._papers_to_cite)
self.assertIn("Chen2020", citations._citation_tags.keys())

citations._reset()
pybamm.ParameterValues("NCA_Kim2011")
self.assertIn("Kim2011", citations._papers_to_cite)
self.assertIn("Kim2011", citations._citation_tags.keys())

citations._reset()
pybamm.ParameterValues("Marquis2019")
self.assertIn("Marquis2019", citations._papers_to_cite)
self.assertIn("Marquis2019", citations._citation_tags.keys())

citations._reset()
pybamm.ParameterValues("Sulzer2019")
self.assertIn("Sulzer2019physical", citations._papers_to_cite)
self.assertIn("Sulzer2019physical", citations._citation_tags.keys())

citations._reset()
pybamm.ParameterValues("Ecker2015")
self.assertIn("Ecker2015i", citations._papers_to_cite)
self.assertIn("Ecker2015i", citations._citation_tags.keys())
self.assertIn("Ecker2015ii", citations._papers_to_cite)
self.assertIn("Ecker2015ii", citations._citation_tags.keys())
self.assertIn("Zhao2018", citations._papers_to_cite)
self.assertIn("Zhao2018", citations._citation_tags.keys())
self.assertIn("Hales2019", citations._papers_to_cite)
self.assertIn("Hales2019", citations._citation_tags.keys())
self.assertIn("Richardson2020", citations._papers_to_cite)
self.assertIn("Richardson2020", citations._citation_tags.keys())

citations._reset()
pybamm.ParameterValues("ORegan2022")
self.assertIn("ORegan2022", citations._papers_to_cite)
self.assertIn("ORegan2022", citations._citation_tags.keys())

def test_solver_citations(self):
# Test that solving each solver adds the right citations
Expand All @@ -335,28 +368,33 @@ def test_solver_citations(self):
self.assertNotIn("Virtanen2020", citations._papers_to_cite)
pybamm.ScipySolver()
self.assertIn("Virtanen2020", citations._papers_to_cite)
self.assertIn("Virtanen2020", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Virtanen2020", citations._papers_to_cite)
pybamm.AlgebraicSolver()
self.assertIn("Virtanen2020", citations._papers_to_cite)
self.assertIn("Virtanen2020", citations._citation_tags.keys())

if pybamm.have_scikits_odes():
citations._reset()
self.assertNotIn("Malengier2018", citations._papers_to_cite)
pybamm.ScikitsOdeSolver()
self.assertIn("Malengier2018", citations._papers_to_cite)
self.assertIn("Malengier2018", citations._citation_tags.keys())

citations._reset()
self.assertNotIn("Malengier2018", citations._papers_to_cite)
pybamm.ScikitsDaeSolver()
self.assertIn("Malengier2018", citations._papers_to_cite)
self.assertIn("Malengier2018", citations._citation_tags.keys())

if pybamm.have_idaklu():
citations._reset()
self.assertNotIn("Hindmarsh2005", citations._papers_to_cite)
pybamm.IDAKLUSolver()
self.assertIn("Hindmarsh2005", citations._papers_to_cite)
self.assertIn("Hindmarsh2005", citations._citation_tags.keys())

@unittest.skipIf(not pybamm.have_jax(), "jax or jaxlib is not installed")
def test_jax_citations(self):
Expand All @@ -365,6 +403,7 @@ def test_jax_citations(self):
self.assertNotIn("jax2018", citations._papers_to_cite)
pybamm.JaxSolver()
self.assertIn("jax2018", citations._papers_to_cite)
self.assertIn("jax2018", citations._citation_tags.keys())


if __name__ == "__main__":
Expand Down

0 comments on commit 2f4ad5c

Please sign in to comment.