forked from diffpy/diffpy.pdfgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pdfdataset.py
127 lines (112 loc) · 3.52 KB
/
test_pdfdataset.py
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
##############################################################################
#
# PDFgui by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2008 trustees of the Michigan State University.
# All rights reserved.
#
# File coded by: Pavol Juhas
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE.txt for license information.
#
##############################################################################
"""Unit tests for pdfdataset.py
"""
import unittest
from diffpy.pdfgui.control.pdfdataset import PDFDataSet
from diffpy.pdfgui.tests.testutils import datafile
##############################################################################
class TestPDFDataSet(unittest.TestCase):
def setUp(self):
self.pdfds = PDFDataSet("test data set")
return
def tearDown(self):
self.pdfds = None
return
# def test___init__(self):
# """check PDFDataSet.__init__()
# """
# return
#
# def test_clear(self):
# """check PDFDataSet.clear()
# """
# return
#
# def test_setvar(self):
# """check PDFDataSet.setvar()
# """
# return
#
# def test_getvar(self):
# """check PDFDataSet.getvar()
# """
# return
#
def test_read(self):
"""check PDFDataSet.read()"""
# neutron data -------------------------------------------------
fn_550K = datafile("550K.gr")
self.pdfds.read(fn_550K)
self.assertEqual("N", self.pdfds.stype)
self.assertEqual(32.0, self.pdfds.qmax)
# there are 2000 points in the file
npts = len(self.pdfds.robs)
self.assertEqual(2000, npts)
# drobs are all zero
self.assertEqual(npts * [0.0], self.pdfds.drobs)
# dGobs should be defined
self.assertTrue(min(self.pdfds.dGobs) > 0)
# x-ray data ---------------------------------------------------
fx_Ni = datafile("Ni_2-8.chi.gr")
self.pdfds.read(fx_Ni)
self.assertEqual("X", self.pdfds.stype)
self.assertEqual(40.0, self.pdfds.qmax)
# there are 2000 points in the file
npts = len(self.pdfds.robs)
self.assertEqual(2000, npts)
# drobs are all zero
self.assertEqual(npts * [0.0], self.pdfds.drobs)
# dGobs should be defined
self.assertTrue(min(self.pdfds.dGobs) > 0)
return
def test_readStr(self):
"""check PDFDataSet.readStr()"""
# read Ni xray data, but invalidate the last dGobs
fx_Ni = datafile("Ni_2-8.chi.gr")
with open(fx_Ni) as fp:
sNi = fp.read()
lastdGobs = sNi.rstrip().rindex(" ")
sNi_no_dGobs = sNi[:lastdGobs] + " -1.3e-3"
self.pdfds.readStr(sNi_no_dGobs)
# there are 2000 points in the file
npts = len(self.pdfds.robs)
self.assertEqual(2000, npts)
# dGobs should be all zero
self.assertEqual(npts * [0.0], self.pdfds.dGobs)
return
# def test_write(self):
# """check PDFDataSet.write()
# """
# return
#
# def test_writeStr(self):
# """check PDFDataSet.writeStr()
# """
# return
#
# def test_copy(self):
# """check PDFDataSet.copy()
# """
# return
#
# def test_close(self):
# """check PDFDataSet.close()
# """
# return
# End of class TestPDFDataSet
if __name__ == "__main__":
unittest.main()
# End of file