Skip to content

Commit

Permalink
fix unit test for load_guess_group
Browse files Browse the repository at this point in the history
  • Loading branch information
freyso committed Jun 8, 2022
1 parent 487d9c9 commit d2299eb
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions tests/sphinx/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import os
import numpy as np
import unittest
import tempfile
import posixpath
from pathlib import Path
import warnings
import scipy.constants
from pyiron_atomistics.project import Project
Expand Down Expand Up @@ -399,33 +402,42 @@ def test_load_default_groups(self):
)
self.sphinx_band_structure.structure = backup

def test_load_default_groups(self):
def test_load_guess_group(self):
guess = self.sphinx_band_structure.input.sphinx.initialGuess

def reload_guess(filelist):
try:
self.sphinx_band_structure.restart_file_list = filelist
except IOError:
# proposed restart files won't exist - never mind.
pass
# ugly hack: restart_file_list cannot be emptied otherwise
self.sphinx_band_structure._restart_file_list = list ()
self.sphinx_band_structure.restart_file_list = filelist
del guess["rho"]
del guess["waves"]
self.sphinx_band_structure.load_guess_group ()

reload_guess (["./rho.sxb"])
self.assertEqual (guess.rho.file, "\"./rho.sxb\"")

reload_guess (["./waves.sxb"])
self.assertEqual (guess.waves.file, "\"./waves.sxb\"")
self.assertEqual (guess.rho.fromWaves, True)

reload_guess (["./rho.sxb", "./waves.sxb"])
self.assertEqual (guess.waves.file, "\"./waves.sxb\"")
self.assertEqual (guess.rho.file, "\"./rho.sxb\"")

reload_guess ([])
self.assertEqual (guess.rho.atomicOrbitals, True)
self.assertTrue ('lcao' in guess.waves)
with tempfile.TemporaryDirectory() as tmpdir:
# create temporary files to pass file existence checks
rho_file = posixpath.join (tmpdir, "rho.sxb")
waves_file = posixpath.join (tmpdir, "waves.sxb")
Path(rho_file).touch ()
Path(waves_file).touch ()

# test loading rho
reload_guess ([rho_file])
self.assertEqual (guess.rho.file, '"' + rho_file + '"')

# test loading waves
reload_guess ([waves_file])
self.assertEqual (guess.waves.file, '"' + waves_file + '"')
self.assertEqual (guess.rho.fromWaves, True)

# test loading rho + waves
reload_guess ([rho_file, waves_file])
self.assertEqual (guess.waves.file, '"' + waves_file + '"')
self.assertEqual (guess.rho.file, '"' + rho_file + '"')

# test default
reload_guess ([])
self.assertEqual (guess.rho.atomicOrbitals, True)
self.assertTrue ('lcao' in guess.waves)

def test_validate_ready_to_run(self):

Expand Down

0 comments on commit d2299eb

Please sign in to comment.