Skip to content

Commit 1dc2965

Browse files
Merge pull request #52 from tacaswell/fillout_datamodel
MNT/TST: fill out the data-model and update tests
2 parents 16010dd + f28a407 commit 1dc2965

File tree

3 files changed

+67
-49
lines changed

3 files changed

+67
-49
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ matrix:
66
- python: 3.4
77
- python: 3.5
88
- python: 3.6
9+
- python: 3.7
910
- python: "nightly"
1011
env: PRE=--pre
1112
allow_failures:
1213
- python : "nightly"
1314

1415
install:
15-
- python setup.py install
16-
- pip install pytest pytest-cov coverage
16+
- python -m pip install --upgrade pip
17+
- python -m pip install -v .
18+
- python -m pip install $PRE --upgrade pytest pytest-cov coverage
1719

1820
script:
1921
- coverage run run_tests.py

cycler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ def __eq__(self, other):
324324

325325
return all(a == b for a, b in zip(self, other))
326326

327+
def __ne__(self, other):
328+
return not (self == other)
329+
330+
__hash__ = None
331+
327332
def __repr__(self):
328333
op_map = {zip: '+', product: '*'}
329334
if self._right is None:

test_cycler.py

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,73 +26,84 @@ def _cycler_helper(c, length, keys, values):
2626

2727
def _cycles_equal(c1, c2):
2828
assert list(c1) == list(c2)
29+
assert c1 == c2
2930

3031

31-
def test_creation():
32-
c = cycler(c='rgb')
33-
yield _cycler_helper, c, 3, ['c'], [['r', 'g', 'b']]
34-
c = cycler(c=list('rgb'))
35-
yield _cycler_helper, c, 3, ['c'], [['r', 'g', 'b']]
36-
c = cycler(cycler(c='rgb'))
37-
yield _cycler_helper, c, 3, ['c'], [['r', 'g', 'b']]
32+
@pytest.mark.parametrize('c', [cycler(c='rgb'),
33+
cycler(c=list('rgb')),
34+
cycler(cycler(c='rgb'))],
35+
ids=['from string',
36+
'from list',
37+
'from cycler'])
38+
def test_creation(c):
39+
_cycler_helper(c, 3, ['c'], [['r', 'g', 'b']])
3840

3941

40-
def test_compose():
42+
def test_add():
4143
c1 = cycler(c='rgb')
4244
c2 = cycler(lw=range(3))
43-
c3 = cycler(lw=range(15))
4445
# addition
45-
yield _cycler_helper, c1+c2, 3, ['c', 'lw'], [list('rgb'), range(3)]
46-
yield _cycler_helper, c2+c1, 3, ['c', 'lw'], [list('rgb'), range(3)]
47-
yield _cycles_equal, c2+c1, c1+c2
46+
_cycler_helper(c1+c2, 3, ['c', 'lw'], [list('rgb'), range(3)])
47+
_cycler_helper(c2+c1, 3, ['c', 'lw'], [list('rgb'), range(3)])
48+
_cycles_equal(c2+c1, c1+c2)
49+
50+
51+
def test_add_len_mismatch():
4852
# miss-matched add lengths
53+
c1 = cycler(c='rgb')
54+
c3 = cycler(lw=range(15))
4955
with pytest.raises(ValueError):
5056
c1 + c3
5157
with pytest.raises(ValueError):
5258
c3 + c1
5359

60+
61+
def test_prod():
62+
c1 = cycler(c='rgb')
63+
c2 = cycler(lw=range(3))
64+
c3 = cycler(lw=range(15))
5465
# multiplication
5566
target = zip(*product(list('rgb'), range(3)))
56-
yield (_cycler_helper, c1 * c2, 9, ['c', 'lw'], target)
67+
_cycler_helper(c1 * c2, 9, ['c', 'lw'], target)
5768

5869
target = zip(*product(range(3), list('rgb')))
59-
yield (_cycler_helper, c2 * c1, 9, ['lw', 'c'], target)
70+
_cycler_helper(c2 * c1, 9, ['lw', 'c'], target)
6071

6172
target = zip(*product(range(15), list('rgb')))
62-
yield (_cycler_helper, c3 * c1, 45, ['lw', 'c'], target)
73+
_cycler_helper(c3 * c1, 45, ['lw', 'c'], target)
6374

6475

6576
def test_inplace():
6677
c1 = cycler(c='rgb')
6778
c2 = cycler(lw=range(3))
6879
c2 += c1
69-
yield _cycler_helper, c2, 3, ['c', 'lw'], [list('rgb'), range(3)]
80+
_cycler_helper(c2, 3, ['c', 'lw'], [list('rgb'), range(3)])
7081

7182
c3 = cycler(c='rgb')
7283
c4 = cycler(lw=range(3))
7384
c3 *= c4
7485
target = zip(*product(list('rgb'), range(3)))
75-
yield (_cycler_helper, c3, 9, ['c', 'lw'], target)
86+
_cycler_helper(c3, 9, ['c', 'lw'], target)
7687

7788

7889
def test_constructor():
7990
c1 = cycler(c='rgb')
8091
c2 = cycler(ec=c1)
81-
yield _cycler_helper, c1+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2
92+
_cycler_helper(c1+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2)
8293
c3 = cycler(c=c1)
83-
yield _cycler_helper, c3+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2
94+
_cycler_helper(c3+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2)
8495
# Using a non-string hashable
8596
c4 = cycler(1, range(3))
86-
yield _cycler_helper, c4+c1, 3, [1, 'c'], [range(3), ['r', 'g', 'b']]
97+
_cycler_helper(c4+c1, 3, [1, 'c'], [range(3), ['r', 'g', 'b']])
8798

8899
# addition using cycler()
89-
yield (_cycler_helper, cycler(c='rgb', lw=range(3)),
90-
3, ['c', 'lw'], [list('rgb'), range(3)])
91-
yield (_cycler_helper, cycler(lw=range(3), c='rgb'),
92-
3, ['c', 'lw'], [list('rgb'), range(3)])
100+
_cycler_helper(cycler(c='rgb', lw=range(3)),
101+
3, ['c', 'lw'], [list('rgb'), range(3)])
102+
_cycler_helper(cycler(lw=range(3), c='rgb'),
103+
3, ['c', 'lw'], [list('rgb'), range(3)])
93104
# Purposely mixing them
94-
yield (_cycler_helper, cycler(c=range(3), lw=c1),
95-
3, ['c', 'lw'], [range(3), list('rgb')])
105+
_cycler_helper(cycler(c=range(3), lw=c1),
106+
3, ['c', 'lw'], [range(3), list('rgb')])
96107

97108

98109
def test_failures():
@@ -114,24 +125,24 @@ def test_simplify():
114125
c1 = cycler(c='rgb')
115126
c2 = cycler(ec=c1)
116127
for c in [c1 * c2, c2 * c1, c1 + c2]:
117-
yield _cycles_equal, c, c.simplify()
128+
_cycles_equal(c, c.simplify())
118129

119130

120131
def test_multiply():
121132
c1 = cycler(c='rgb')
122-
yield _cycler_helper, 2*c1, 6, ['c'], ['rgb'*2]
133+
_cycler_helper(2*c1, 6, ['c'], ['rgb'*2])
123134

124135
c2 = cycler(ec=c1)
125136
c3 = c1 * c2
126137

127-
yield _cycles_equal, 2*c3, c3*2
138+
_cycles_equal(2*c3, c3*2)
128139

129140

130141
def test_mul_fails():
131142
c1 = cycler(c='rgb')
132-
pytest.raises(TypeError, mul, c1, 2.0)
133-
pytest.raises(TypeError, mul, c1, 'a')
134-
pytest.raises(TypeError, mul, c1, [])
143+
pytest.raises(TypeError, mul, c1, 2.0)
144+
pytest.raises(TypeError, mul, c1, 'a')
145+
pytest.raises(TypeError, mul, c1, [])
135146

136147

137148
def test_getitem():
@@ -141,7 +152,7 @@ def test_getitem():
141152
slice(None, None, -1),
142153
slice(1, 5, None),
143154
slice(0, 5, 2)):
144-
yield _cycles_equal, c1[slc], cycler(3, widths[slc])
155+
_cycles_equal(c1[slc], cycler(3, widths[slc]))
145156

146157

147158
def test_fail_getime():
@@ -164,14 +175,14 @@ def test_repr():
164175
c_sum_rpr = "(cycler('c', ['r', 'g', 'b']) + cycler('3rd', [0, 1, 2]))"
165176
c_prod_rpr = "(cycler('c', ['r', 'g', 'b']) * cycler('3rd', [0, 1, 2]))"
166177

167-
yield _repr_tester_helper, '__repr__', c + c2, c_sum_rpr
168-
yield _repr_tester_helper, '__repr__', c * c2, c_prod_rpr
178+
_repr_tester_helper('__repr__', c + c2, c_sum_rpr)
179+
_repr_tester_helper('__repr__', c * c2, c_prod_rpr)
169180

170181
sum_html = "<table><th>'3rd'</th><th>'c'</th><tr><td>0</td><td>'r'</td></tr><tr><td>1</td><td>'g'</td></tr><tr><td>2</td><td>'b'</td></tr></table>"
171182
prod_html = "<table><th>'3rd'</th><th>'c'</th><tr><td>0</td><td>'r'</td></tr><tr><td>1</td><td>'r'</td></tr><tr><td>2</td><td>'r'</td></tr><tr><td>0</td><td>'g'</td></tr><tr><td>1</td><td>'g'</td></tr><tr><td>2</td><td>'g'</td></tr><tr><td>0</td><td>'b'</td></tr><tr><td>1</td><td>'b'</td></tr><tr><td>2</td><td>'b'</td></tr></table>"
172183

173-
yield _repr_tester_helper, '_repr_html_', c + c2, sum_html
174-
yield _repr_tester_helper, '_repr_html_', c * c2, prod_html
184+
_repr_tester_helper('_repr_html_', c + c2, sum_html)
185+
_repr_tester_helper('_repr_html_', c * c2, prod_html)
175186

176187

177188
def test_call():
@@ -264,17 +275,17 @@ def _eq_test_helper(a, b, res):
264275
def test_eq():
265276
a = cycler(c='rgb')
266277
b = cycler(c='rgb')
267-
yield _eq_test_helper, a, b, True
268-
yield _eq_test_helper, a, b[::-1], False
278+
_eq_test_helper(a, b, True)
279+
_eq_test_helper(a, b[::-1], False)
269280
c = cycler(lw=range(3))
270-
yield _eq_test_helper, a+c, c+a, True
271-
yield _eq_test_helper, a+c, c+b, True
272-
yield _eq_test_helper, a*c, c*a, False
273-
yield _eq_test_helper, a, c, False
281+
_eq_test_helper(a+c, c+a, True)
282+
_eq_test_helper(a+c, c+b, True)
283+
_eq_test_helper(a*c, c*a, False)
284+
_eq_test_helper(a, c, False)
274285
d = cycler(c='ymk')
275-
yield _eq_test_helper, b, d, False
286+
_eq_test_helper(b, d, False)
276287
e = cycler(c='orange')
277-
yield _eq_test_helper, b, e, False
288+
_eq_test_helper(b, e, False)
278289

279290

280291
def test_cycler_exceptions():
@@ -323,15 +334,15 @@ def test_by_key_add():
323334
cy = cycler(c=input_dict['c']) + cycler(lw=input_dict['lw'])
324335
res = cy.by_key()
325336
assert res == input_dict
326-
yield _by_key_helper, cy
337+
_by_key_helper(cy)
327338

328339

329340
def test_by_key_mul():
330341
input_dict = dict(c=list('rg'), lw=[1, 2, 3])
331342
cy = cycler(c=input_dict['c']) * cycler(lw=input_dict['lw'])
332343
res = cy.by_key()
333344
assert input_dict['lw'] * len(input_dict['c']) == res['lw']
334-
yield _by_key_helper, cy
345+
_by_key_helper(cy)
335346

336347

337348
def test_contains():

0 commit comments

Comments
 (0)