Skip to content

Commit

Permalink
- finished the prototype library tests (100% coverage now!)
Browse files Browse the repository at this point in the history
  • Loading branch information
amkrajewski committed Feb 12, 2024
1 parent 05c2595 commit d99492f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pysipfenn/misc/prototypeLibrary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@
2
Direct
0.00000 0.00000 0.00000
0.75000 0.25000 0.50000
0.75000 0.25000 0.50000
50 changes: 50 additions & 0 deletions pysipfenn/tests/test_Core_prototypeLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,53 @@ def test_correctContentFCC(self):
with self.subTest(msg="Has correct formula"):
self.assertEqual(fcc["structure"].formula, "Cu1")

def test_customPrototypeLoad(self):
"""Test that a custom prototype can be loaded. Then test that a custom prototype can be appended to the default
library and stay there."""

with resources.files('pysipfenn').joinpath('tests/testCaseFiles/prototypeLibrary-custom.yaml') as f:
self.c.parsePrototypeLibrary(customPath=f, verbose=True, printCustomLibrary=True)

with self.subTest(msg="Custom prototype present with correct parse"):
self.assertTrue("NicePhase" in self.c.prototypeLibrary)
self.assertEqual(self.c.prototypeLibrary["NicePhase"]["origin"], "https://somecustomsource.org")

with self.subTest(msg="Nice phase is a valid pymatgen Structure"):
self.assertTrue(isinstance(self.c.prototypeLibrary["NicePhase"]["structure"], Structure))
self.assertTrue(self.c.prototypeLibrary["NicePhase"]["structure"].is_valid())
self.assertEqual(self.c.prototypeLibrary["NicePhase"]["structure"].formula, "U1")

with self.subTest(msg="FCC prototype still present"):
self.assertTrue("FCC" in self.c.prototypeLibrary)

with self.subTest(msg="Test that it does not affect the default prototype library"):
otherC = pysipfenn.Calculator(autoLoad=False)
self.assertTrue("NicePhase" not in otherC.prototypeLibrary)

# Create a backup of the default library
self.c = pysipfenn.Calculator(autoLoad=False)
backup = self.c.prototypeLibrary.copy()

with resources.files('pysipfenn').joinpath('tests/testCaseFiles/prototypeLibrary-custom.yaml') as f:
self.c.appendPrototypeLibrary(customPath=f)

with self.subTest(msg="Custom prototype present and valid in a different Calculator instance"):
otherC = pysipfenn.Calculator(autoLoad=False)
self.assertTrue("NicePhase" in otherC.prototypeLibrary)
self.assertEqual(otherC.prototypeLibrary["NicePhase"]["origin"], "https://somecustomsource.org")
self.assertTrue(isinstance(otherC.prototypeLibrary["NicePhase"]["structure"], Structure))
self.assertTrue(otherC.prototypeLibrary["NicePhase"]["structure"].is_valid())
self.assertEqual(otherC.prototypeLibrary["NicePhase"]["structure"].formula, "U1")

with self.subTest(msg="FCC/BCC/HCP prototype still present in a different Calculator instance"):
self.assertTrue("FCC" in otherC.prototypeLibrary)
self.assertTrue("BCC" in otherC.prototypeLibrary)
self.assertTrue("HCP" in otherC.prototypeLibrary)

with self.subTest(msg="Restore the original prototype library"):
pysipfenn.overwritePrototypeLibrary(backup)





0 comments on commit d99492f

Please sign in to comment.