8000 TST : first round of tests for Cycler · danielballan/matplotlib@d5ec6d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit d5ec6d8

Browse files
committed
TST : first round of tests for Cycler
Covers everything but the repr Tests '+' behavior which may be changed.
1 parent 1532863 commit d5ec6d8

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

lib/matplotlib/tests/test_cycler.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import six
5+
from six.moves import zip
6+
from matplotlib.cycler import cycler
7+
from nose.tools import assert_equal, assert_raises
8+
from itertools import product
9+
from operator import add, iadd, mul, imul
10+
11+
12+
def _cycler_helper(c, length, keys, values):
13+
assert_equal(len(c), length)
14+
assert_equal(len(c), len(list(c.finite_iter())))
15+
assert_equal(len(c), len(c.to_list()))
16+
assert_equal(c.keys, set(keys))
17+
18+
for k, vals in zip(keys, values):
19+
for v, v_target in zip(c, vals):
20+
assert_equal(v[k], v_target)
21+
22+
23+
def test_creation():
24+
c = cycler('c', 'rgb')
25+
yield _cycler_helper, c, 3, ['c'], [['r', 'g', 'b']]
26+
c = cycler('c', list('rgb'))
27+
yield _cycler_helper, c, 3, ['c'], [['r', 'g', 'b']]
28+
29+
30+
def test_compose():
31+
c1 = cycler('c', 'rgb')
32+
c2 = cycler('lw', range(3))
33+
c3 = cycler('lw', range(15))
34+
# addition
35+
yield _cycler_helper, c1+c2, 3, ['c', 'lw'], [list('rgb'), range(3)]
36+
yield _cycler_helper, c2+c1, 3, ['c', 'lw'], [list('rgb'), range(3)]
37+
# miss-matched add lengths
38+
yield _cycler_helper, c1+c3, 3, ['c', 'lw'], [list('rgb'), range(3)]
39+
yield _cycler_helper, c3+c1, 3, ['c', 'lw'], [list('rgb'), range(3)]
40+
41+
# multiplication
42+
target = zip(*product(list('rgb'), range(3)))
43+
yield (_cycler_helper, c1 * c2, 9, ['c', 'lw'], target)
44+
45+
target = zip(*product(range(3), list('rgb')))
46+
yield (_cycler_helper, c2 * c1, 9, ['lw', 'c'], target)
47+
48+
target = zip(*product(range(15), list('rgb')))
49+
yield (_cycler_helper, c3 * c1, 45, ['lw', 'c'], target)
50+
51+
52+
def test_inplace():
53+
c1 = cycler('c', 'rgb')
54+
c2 = cycler('lw', range(3))
55+
c2 += c1
56+
yield _cycler_helper, c2, 3, ['c', 'lw'], [list('rgb'), range(3)]
57+
58+
c3 = cycler('c', 'rgb')
59+
c4 = cycler('lw', range(3))
60+
c3 *= c4
61+
target = zip(*product(list('rgb'), range(3)))
62+
yield (_cycler_helper, c3, 9, ['c', 'lw'], target)
63+
64+
65+
def test_constructor():
66+
c1 = cycler('c', 'rgb')
67+
c2 = cycler('ec', c1)
68+
yield _cycler_helper, c1+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2
69+
c3 = cycler('c', c1)
70+
yield _cycler_helper, c3+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2
71+
72+
73+
def test_failures():
74+
c1 = cycler('c', 'rgb')
75+
c2 = cycler('c', c1)
76+
assert_raises(ValueError, add, c1, c2)
77+
assert_raises(ValueError, iadd, c1, c2)
78+
assert_raises(ValueError, mul, c1, c2)
79+
assert_raises(ValueError, imul, c1, c2)
80+
81+
c3 = cycler('ec', c1)
82+
83+
assert_raises(ValueError, cycler, 'c', c2 + c3)

0 commit comments

Comments
 (0)
0