forked from astropy/astropy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_column.py
More file actions
121 lines (99 loc) · 4.46 KB
/
Copy pathtest_column.py
File metadata and controls
121 lines (99 loc) · 4.46 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
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
import numpy as np
from .. import Column
from .. import pprint
class TestColumn():
def test_1(self):
Column('a')
def test_subclass(self):
c = Column('a')
assert isinstance(c, np.ndarray)
c2 = c * 2
assert isinstance(c2, Column)
assert isinstance(c2, np.ndarray)
def test_numpy_ops(self):
"""Show that basic numpy operations with Column behave sensibly"""
arr = np.array([1, 2, 3])
c = Column('a', arr)
eq = c == arr
assert np.all(eq)
assert len(eq) == 3
assert type(eq) == Column
assert eq.dtype.str == '|b1'
eq = arr == c
assert np.all(eq)
lt = c - 1 < arr
assert np.all(lt)
def test_view(self):
c = np.array([1, 2, 3]).view(Column)
assert repr(c) == 'array([1, 2, 3])'
def test_format(self):
"""Show that the formatted output from str() works"""
MAX_LINES = pprint.MAX_LINES
pprint.MAX_LINES = 7
c1 = Column(name='a', data=np.arange(2000), dtype=float,
format='%6.2f')
assert str(c1) == (' a \n-------\n 0.00\n'
' 1.00\n ...\n1998.00\n1999.00')
pprint.MAX_LINES = MAX_LINES
def test_convert_numpy_array(self):
d = Column('a', [1, 2, 3], dtype='i8')
np_data = np.array(d)
assert np.all(np_data == d)
np_data = np.array(d, copy=False)
assert np.all(np_data == d)
np_data = np.array(d, dtype='i4')
assert np.all(np_data == d)
class TestAttrEqual():
"""Bunch of tests originally from ATpy that test the attrs_equal method."""
def test_5(self):
c1 = Column(name='a', dtype=int, units='mJy')
c2 = Column(name='a', dtype=int, units='mJy')
assert c1.attrs_equal(c2)
def test_6(self):
c1 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
c2 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
assert c1.attrs_equal(c2)
def test_7(self):
c1 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
c2 = Column(name='b', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
assert not c1.attrs_equal(c2)
def test_8(self):
c1 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
c2 = Column(name='a', dtype=float, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
assert not c1.attrs_equal(c2)
def test_9(self):
c1 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
c2 = Column(name='a', dtype=int, units='ergs/cm^2/s/Hz', format='%i',
description='test column', meta={'c': 8, 'd': 12})
assert not c1.attrs_equal(c2)
def test_10(self):
c1 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
c2 = Column(name='a', dtype=int, units='mJy', format='%g',
description='test column', meta={'c': 8, 'd': 12})
assert not c1.attrs_equal(c2)
def test_11(self):
c1 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
c2 = Column(name='a', dtype=int, units='mJy', format='%i',
description='another test column', meta={'c': 8, 'd': 12})
assert not c1.attrs_equal(c2)
def test_12(self):
c1 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
c2 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'e': 8, 'd': 12})
assert not c1.attrs_equal(c2)
def test_13(self):
c1 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 8, 'd': 12})
c2 = Column(name='a', dtype=int, units='mJy', format='%i',
description='test column', meta={'c': 9, 'd': 12})
assert not c1.attrs_equal(c2)