1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
# fmt: off
"""Test module for explicitly unittesting errors generated by VASP calculator"""
import pytest
from ase.build import molecule
from ase.calculators.calculator import CalculationFailed
from ase.calculators.vasp import Vasp
@pytest.fixture(name='atoms')
def fixture_atoms():
return molecule('H2', vacuum=5, pbc=True)
def test_bad_executable_stderr(atoms, tmp_path, monkeypatch):
monkeypatch.setenv('VASP_PP_PATH', str(tmp_path))
(tmp_path / 'H').mkdir()
with open(tmp_path / 'H' / 'POTCAR', 'w') as fout:
fout.write('\n')
calc = Vasp(encut=100, command=str(tmp_path / '_NO_VASP_EXEC_'), pp='.',
directory=tmp_path)
atoms.calc = calc
try:
atoms.get_potential_energy()
except CalculationFailed as exc:
exc_str = str(exc)
# stderr capture should put stderr in exception text
assert 'stderr' in exc_str
# content of stderr should be in exception, and mention path to
# failed executable
assert str(tmp_path / '_NO_VASP_EXEC') in exc_str
|