forked from diffpy/diffpy.structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_loadstructure.py
More file actions
95 lines (74 loc) · 2.78 KB
/
test_loadstructure.py
File metadata and controls
95 lines (74 loc) · 2.78 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
"""Unit tests for the loadStructure factory."""
import unittest
import pytest
from diffpy.structure import PDFFitStructure, Structure, load_structure, loadStructure
from diffpy.structure.structureerrors import StructureFormatError
##############################################################################
class TestLoadStructure(unittest.TestCase):
@pytest.fixture(autouse=True)
def prepare_fixture(self, datafile):
self.datafile = datafile
def test_xcfg(self):
"""Check loading of atomeye xcfg format."""
f = self.datafile("BubbleRaftShort.xcfg")
stru = load_structure(f)
self.assertTrue(type(stru) is Structure)
self.assertRaises(StructureFormatError, load_structure, f, "xyz")
return
def test_discus(self):
"""Check loading of discus file format."""
f = self.datafile("Ni-discus.stru")
stru = load_structure(f)
self.assertTrue(type(stru) is PDFFitStructure)
return
def test_cif(self):
"""Check loading of CIF file format."""
f = self.datafile("PbTe.cif")
stru = load_structure(f)
self.assertTrue(isinstance(stru, Structure))
self.assertFalse(isinstance(stru, PDFFitStructure))
return
def test_badfile(self):
"""Check loading of CIF file format."""
f = self.datafile("Ni-bad.stru")
self.assertRaises(StructureFormatError, loadStructure, f)
return
def test_load_bad_file(self):
"""Check loading of CIF file format."""
f = self.datafile("Ni-bad.stru")
self.assertRaises(StructureFormatError, load_structure, f)
return
def test_goodkwarg(self):
"""Check loading of CIF file and passing of parser keyword
argument."""
f = self.datafile("graphite.cif")
stru = load_structure(f, eps=1e-10)
self.assertEqual(8, len(stru))
return
def test_badkwarg(self):
"""Check loading of xyz file format with invalid keyword
argument."""
f = self.datafile("bucky.xyz")
self.assertRaises(TypeError, load_structure, f, eps=1e-10)
return
# End of class TestLoadStructure
# ----------------------------------------------------------------------------
@pytest.mark.parametrize(
"filename, expected",
[ # C1: Load the cif file in Path object, expected to load the Structure instance.
("PbTe.cif", (True, False)),
],
)
def test_load_structure_cif_in_path(datafile, filename, expected):
from pathlib import Path
f = datafile(filename)
f_path = Path(f)
stru = load_structure(f_path)
actual = (
isinstance(stru, Structure),
isinstance(stru, PDFFitStructure),
)
assert actual == expected
if __name__ == "__main__":
unittest.main()