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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
from pathlib import Path
import pytest
from ase.calculators.calculator import Calculator
def test_directory_and_label():
def normalize(path):
"""Helper function to normalize path"""
return str(Path(path))
calc = Calculator()
assert calc.directory == '.'
assert calc.label is None
calc.directory = 'somedir'
assert calc.directory == 'somedir'
assert calc.label == 'somedir/'
# We cannot redundantly specify directory
with pytest.raises(ValueError):
calc = Calculator(directory='somedir',
label='anotherdir/label')
# Test only directory in directory
calc = Calculator(directory='somedir',
label='label')
assert calc.directory == 'somedir'
assert calc.label == 'somedir/label'
wdir = '/home/somedir'
calc = Calculator(directory=wdir,
label='label')
assert calc.directory == normalize(wdir)
assert calc.label == normalize(wdir) + '/label'
# Test we can handle pathlib directories
wdir = Path('/home/somedir')
calc = Calculator(directory=wdir,
label='label')
assert calc.directory == normalize(wdir)
assert calc.label == normalize(wdir) + '/label'
with pytest.raises(ValueError):
calc = Calculator(directory=wdir,
label='somedir/label')
# Passing in empty directories with directories in label should be OK
for wdir in ['somedir', '/home/directory']:
label = wdir + '/label'
expected_label = normalize(wdir) + '/label'
calc = Calculator(directory='', label=label)
assert calc.label == expected_label
assert calc.directory == normalize(wdir)
calc = Calculator(directory='.', label=label)
assert calc.label == expected_label
assert calc.directory == normalize(wdir)
def test_deprecated_get_spin_polarized():
calc = Calculator()
with pytest.warns(FutureWarning):
spinpol = calc.get_spin_polarized()
assert spinpol is False
|