66
77import pytest
88
9- from diffpy .structure import PDFFitStructure , Structure , loadStructure
9+ from diffpy .structure import PDFFitStructure , Structure , load_structure , loadStructure
1010from diffpy .structure .structureerrors import StructureFormatError
1111
1212
@@ -19,22 +19,22 @@ def prepare_fixture(self, datafile):
1919 def test_xcfg (self ):
2020 """Check loading of atomeye xcfg format."""
2121 f = self .datafile ("BubbleRaftShort.xcfg" )
22- stru = loadStructure (f )
22+ stru = load_structure (f )
2323 self .assertTrue (type (stru ) is Structure )
24- self .assertRaises (StructureFormatError , loadStructure , f , "xyz" )
24+ self .assertRaises (StructureFormatError , load_structure , f , "xyz" )
2525 return
2626
2727 def test_discus (self ):
2828 """Check loading of discus file format."""
2929 f = self .datafile ("Ni-discus.stru" )
30- stru = loadStructure (f )
30+ stru = load_structure (f )
3131 self .assertTrue (type (stru ) is PDFFitStructure )
3232 return
3333
3434 def test_cif (self ):
3535 """Check loading of CIF file format."""
3636 f = self .datafile ("PbTe.cif" )
37- stru = loadStructure (f )
37+ stru = load_structure (f )
3838 self .assertTrue (isinstance (stru , Structure ))
3939 self .assertFalse (isinstance (stru , PDFFitStructure ))
4040 return
@@ -45,25 +45,51 @@ def test_badfile(self):
4545 self .assertRaises (StructureFormatError , loadStructure , f )
4646 return
4747
48+ def test_load_bad_file (self ):
49+ """Check loading of CIF file format."""
50+ f = self .datafile ("Ni-bad.stru" )
51+ self .assertRaises (StructureFormatError , load_structure , f )
52+ return
53+
4854 def test_goodkwarg (self ):
4955 """Check loading of CIF file and passing of parser keyword
5056 argument."""
5157 f = self .datafile ("graphite.cif" )
52- stru = loadStructure (f , eps = 1e-10 )
58+ stru = load_structure (f , eps = 1e-10 )
5359 self .assertEqual (8 , len (stru ))
5460 return
5561
5662 def test_badkwarg (self ):
5763 """Check loading of xyz file format with invalid keyword
5864 argument."""
5965 f = self .datafile ("bucky.xyz" )
60- self .assertRaises (TypeError , loadStructure , f , eps = 1e-10 )
66+ self .assertRaises (TypeError , load_structure , f , eps = 1e-10 )
6167 return
6268
6369
6470# End of class TestLoadStructure
6571
72+
6673# ----------------------------------------------------------------------------
74+ @pytest .mark .parametrize (
75+ "filename, expected" ,
76+ [ # C1: Load the cif file in Path object, expected to load the Structure instance.
77+ ("PbTe.cif" , (True , False )),
78+ ],
79+ )
80+ def test_load_structure_cif_in_path (datafile , filename , expected ):
81+ from pathlib import Path
82+
83+ f = datafile (filename )
84+ f_path = Path (f )
85+ stru = load_structure (f_path )
86+ actual = (
87+ isinstance (stru , Structure ),
88+ isinstance (stru , PDFFitStructure ),
89+ )
90+
91+ assert actual == expected
92+
6793
6894if __name__ == "__main__" :
6995 unittest .main ()
0 commit comments