Skip to content

Commit

Permalink
Tests: Ensure no overwriting of CdTe example thermo obj
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Mar 31, 2024
1 parent 01072b0 commit 9584137
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pip_install_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
pytest -vv -m "not mpl_image_compare" tests # all non-plotting tests
- name: Plotting Tests
if: always() # run even if non-plotting tests fail
id: plotting_tests # Add an ID to this step for reference
run: |
pytest --mpl -m "mpl_image_compare" tests # all plotting tests
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
pytest -vv -m "not mpl_image_compare" tests # all non-plotting tests
- name: Plotting Tests
if: always() # run even if non-plotting tests fail
id: plotting_tests # Add an ID to this step for reference
run: |
pytest --mpl -m "mpl_image_compare" tests # all plotting tests
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
pytest -vv -m "not mpl_image_compare" tests # all non-plotting tests
- name: Plotting Tests
if: always() # run even if non-plotting tests fail
id: plotting_tests # Add an ID to this step for reference
run: |
pytest --mpl -m "mpl_image_compare" tests # all plotting tests
Expand Down
2 changes: 1 addition & 1 deletion examples/CdTe/CdTe_example_defect_dict.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/CdTe/CdTe_example_thermo.json

Large diffs are not rendered by default.

36 changes: 35 additions & 1 deletion tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_DefectsParser_CdTe(self):
json_filename="CdTe_example_defect_dict.json",
) # for testing in test_thermodynamics.py
print([warn.message for warn in w]) # for debugging
self._check_default_CdTe_DefectsParser_outputs(default_dp, w)
self._check_default_CdTe_DefectsParser_outputs(default_dp, w) # saves CdTe_example_thermo.json

# test reloading DefectsParser
reloaded_defect_dict = loadfn(os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_defect_dict.json"))
Expand All @@ -342,6 +342,10 @@ def test_DefectsParser_CdTe(self):

@custom_mpl_image_compare(filename="CdTe_example_defects_plot.png")
def test_DefectsParser_CdTe_without_multiprocessing(self):
shutil.move( # avoid overwriting
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json"),
os.path.join(self.CdTe_EXAMPLE_DIR, "orig_CdTe_example_thermo.json"),
)
# test same behaviour without multiprocessing:
with warnings.catch_warnings(record=True) as w:
dp = DefectsParser(
Expand All @@ -355,10 +359,18 @@ def test_DefectsParser_CdTe_without_multiprocessing(self):

# integration test using parsed CdTe thermo and chempots for plotting:
default_thermo = dp.get_defect_thermodynamics(chempots=self.CdTe_chempots)
shutil.move(
os.path.join(self.CdTe_EXAMPLE_DIR, "orig_CdTe_example_thermo.json"),
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json"),
)
return default_thermo.plot(limit="CdTe-Te")

@custom_mpl_image_compare(filename="CdTe_example_defects_plot.png")
def test_DefectsParser_CdTe_filterwarnings(self):
shutil.move( # avoid overwriting
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json"),
os.path.join(self.CdTe_EXAMPLE_DIR, "orig_CdTe_example_thermo.json"),
)
# check using filterwarnings works as expected:
warnings.filterwarnings("ignore", "Multiple")
with warnings.catch_warnings(record=True) as w:
Expand All @@ -372,9 +384,17 @@ def test_DefectsParser_CdTe_filterwarnings(self):

# integration test using parsed CdTe thermo and chempots for plotting:
default_thermo = dp.get_defect_thermodynamics(chempots=self.CdTe_chempots)
shutil.move(
os.path.join(self.CdTe_EXAMPLE_DIR, "orig_CdTe_example_thermo.json"),
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json"),
)
return default_thermo.plot(limit="CdTe-Te")

def test_DefectsParser_CdTe_dist_tol(self):
shutil.move( # avoid overwriting
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json"),
os.path.join(self.CdTe_EXAMPLE_DIR, "orig_CdTe_example_thermo.json"),
)
# test with reduced dist_tol:
# Int_Te_3_Unperturbed merged with Int_Te_3 with default dist_tol = 1.5, now no longer merged
with warnings.catch_warnings(record=True) as w:
Expand All @@ -383,6 +403,10 @@ def test_DefectsParser_CdTe_dist_tol(self):
)
print([warn.message for warn in w]) # for debugging
self._check_default_CdTe_DefectsParser_outputs(dp, w, dist_tol=0.1)
shutil.move(
os.path.join(self.CdTe_EXAMPLE_DIR, "orig_CdTe_example_thermo.json"),
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json"),
)

@custom_mpl_image_compare(filename="CdTe_Te_Cd_+1_eigenvalue_plot.png")
def test_DefectsParser_CdTe_no_dielectric_json(self):
Expand Down Expand Up @@ -410,6 +434,11 @@ def test_DefectsParser_CdTe_no_dielectric_json(self):
return fig

def test_DefectsParser_CdTe_custom_settings(self):
shutil.move( # avoid overwriting
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json"),
os.path.join(self.CdTe_EXAMPLE_DIR, "orig_CdTe_example_thermo.json"),
)

# test custom settings:
with warnings.catch_warnings(record=True) as w:
dp = DefectsParser(
Expand Down Expand Up @@ -438,6 +467,11 @@ def test_DefectsParser_CdTe_custom_settings(self):
self._check_default_CdTe_DefectsParser_outputs(dp, w, test_attributes=False) # same energies as
# above

shutil.move(
os.path.join(self.CdTe_EXAMPLE_DIR, "orig_CdTe_example_thermo.json"),
os.path.join(self.CdTe_EXAMPLE_DIR, "CdTe_example_thermo.json"),
)

# test changed attributes:
assert dp.output_path == self.CdTe_EXAMPLE_DIR
assert dp.dielectric == [9.13, 9.13, 9.13]
Expand Down

0 comments on commit 9584137

Please sign in to comment.