forked from diffpy/diffpy.utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestloaddata.py
More file actions
58 lines (47 loc) · 1.83 KB
/
testloaddata.py
File metadata and controls
58 lines (47 loc) · 1.83 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
#!/usr/bin/env python
"""Unit tests for diffpy.utils.parsers.loaddata
"""
# version
__id__ = '$Id$'
import unittest
import numpy
from diffpy.utils.parsers import loadData
from diffpy.utils.tests.testhelpers import datafile
loaddata01 = datafile('loaddata01.txt')
##############################################################################
class TestLoadData(unittest.TestCase):
def test_loadData_default(self):
"""check loadData() with default options
"""
d1c = numpy.arange(1, 6)
d2c = numpy.array([[3, 31], [4, 32], [5, 33]])
self.assertRaises(IOError, loadData, 'doesnotexist')
d = loadData(loaddata01)
self.failUnless(numpy.array_equal(d2c, d))
# the default minrows=10 makes it read from the third line
d = loadData(loaddata01)
self.failUnless(numpy.array_equal(d2c, d))
# the usecols=(0, 1) would make it read from the third line
d = loadData(loaddata01, minrows=1, usecols=(0, 1))
self.failUnless(numpy.array_equal(d2c, d))
# check the effect of usecols effect
d = loadData(loaddata01, usecols=(0,))
self.failUnless(numpy.array_equal(d2c[:,0], d))
d = loadData(loaddata01, usecols=(1,))
self.failUnless(numpy.array_equal(d2c[:,1], d))
return
def test_loadData_1column(self):
"""check loading of one-column data.
"""
d1c = numpy.arange(1, 6)
d = loadData(loaddata01, usecols=[0], minrows=1)
self.failUnless(numpy.array_equal(d1c, d))
d = loadData(loaddata01, usecols=[0], minrows=2)
self.failUnless(numpy.array_equal(d1c, d))
d = loadData(loaddata01, usecols=[0], minrows=3)
self.failIf(numpy.array_equal(d1c, d))
return
# End of class TestRoutines
if __name__ == '__main__':
unittest.main()
# End of file