Skip to content

Commit

Permalink
upf2json: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpintarelli committed Sep 12, 2019
1 parent d01aa4b commit 34fd304
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions aiida/backends/tests/fixtures/pseudos/O_raw.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions aiida/backends/tests/fixtures/pseudos/Ti_raw.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions aiida/backends/tests/orm/data/test_upf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import errno
import tempfile
import shutil
import json
import os

from aiida import orm
Expand All @@ -34,8 +35,12 @@ def setUpClass(cls, *args, **kwargs):
filepath_base = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, os.pardir, 'fixtures', 'pseudos'))
filepath_barium = os.path.join(filepath_base, 'Ba.pbesol-spn-rrkjus_psl.0.2.3-tot-pslib030.UPF')
filepath_oxygen = os.path.join(filepath_base, 'O.pbesol-n-rrkjus_psl.0.1-tested-pslib030.UPF')
filepath_oxygen_upf_v1 = os.path.join(filepath_base, 'o_lda_v1.2.uspp.F.UPF')
filepath_oxygen_json = os.path.join(filepath_base, 'O.json')
filepath_barium_json = os.path.join(filepath_base, 'Ba.json')
cls.pseudo_barium = orm.UpfData(file=filepath_barium).store()
cls.pseudo_oxygen = orm.UpfData(file=filepath_oxygen).store()
cls.pseudo_oxygen_upf1 = orm.UpfData(file=filepath_oxygen_upf_v1).store()

def setUp(self):
"""Setup a temporary directory to store UPF files."""
Expand Down Expand Up @@ -247,6 +252,22 @@ def test_missing_element_upf_v1(self):
with self.assertRaises(ParsingError):
_ = parse_upf(path_to_upf, check_filename=True)

def test_upf1_to_json_oxygen(self):
"""Test UPF check Oxygen UPF1 pp conversion"""
json_string, _ = self.pseudo_oxygen_upf1._prepare_json()
filepath_base = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir,
os.pardir, 'fixtures', 'pseudos'))
path_to_reference_json = os.path.join(filepath_base, 'O_raw.json')
self.AssertEqual(json_string, path_to_reference_json)

def test_upf2_to_json_barium(self):
"""Test UPF check Oxygen UPF1 pp conversion"""
json_string, _ = self.pseudo_barium._prepare_json()
filepath_base = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir,
os.pardir, 'fixtures', 'pseudos'))
path_to_reference_json = os.path.join(filepath_base, 'Ba_raw.json')
self.AssertEqual(json_string, path_to_reference_json)

def test_invalid_element_upf_v1(self):
"""Test parsers exception on invalid element name in UPF v1."""

Expand Down

0 comments on commit 34fd304

Please sign in to comment.