-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_loadstructure.py
More file actions
67 lines (51 loc) · 2.05 KB
/
test_loadstructure.py
File metadata and controls
67 lines (51 loc) · 2.05 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
#!/usr/bin/env python
"""Unit tests for the loadStructure factory."""
import unittest
import pytest
from diffpy.structure import PDFFitStructure, 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 = loadStructure(f)
self.assertTrue(type(stru) is Structure)
self.assertRaises(StructureFormatError, loadStructure, f, "xyz")
return
def test_discus(self):
"""check loading of discus file format"""
f = self.datafile("Ni-discus.stru")
stru = loadStructure(f)
self.assertTrue(type(stru) is PDFFitStructure)
return
def test_cif(self):
"""check loading of CIF file format"""
f = self.datafile("PbTe.cif")
stru = loadStructure(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_goodkwarg(self):
"""check loading of CIF file and passing of parser keyword argument."""
f = self.datafile("graphite.cif")
stru = loadStructure(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, loadStructure, f, eps=1e-10)
return
# End of class TestLoadStructure
# ----------------------------------------------------------------------------
if __name__ == "__main__":
unittest.main()