Skip to content
Closed

Cycler #4258

Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5e23ba2
WIP : first pass at adding a Cycler
tacaswell Mar 21, 2015
5539698
WIP : version 2 of cycler classes
tacaswell Mar 21, 2015
958b0b6
MNT : tweak Cycler API
tacaswell Mar 22, 2015
6b0696d
MNT : Cycler-family API tweaks
tacaswell Mar 22, 2015
2f57756
ENH : added in-place operations
tacaswell Mar 22, 2015
4aef726
ENH : added verbose repr
tacaswell Mar 22, 2015
105fcd6
MNT : make keys property return a copy
tacaswell Mar 22, 2015
a0c387a
MNT : simplify repr
tacaswell Mar 22, 2015
2355776
ENH : make `cycler` deal with Cycler input
tacaswell Mar 22, 2015
74e61e1
MNT : remove second version of Cycler classes
tacaswell Mar 23, 2015
e6910e4
ENH : add to_list method
tacaswell Mar 23, 2015
1532863
PRF : make __len__ more efficient
tacaswell Mar 23, 2015
d5ec6d8
TST : first round of tests for Cycler
tacaswell Apr 22, 2015
0da274f
API : make __iter__ be finite
tacaswell Apr 27, 2015
52b5dfd
DOC/WIP : first draft a docs for cycler
tacaswell Apr 27, 2015
d4195f7
WIP : more edits to docs
tacaswell May 5, 2015
3e8bd8e
ENH : add simplify
tacaswell May 6, 2015
6fea7a4
ENH : add integer multiplication
tacaswell May 6, 2015
2ffc5e1
TST : test commutativity of cycler addition
tacaswell May 6, 2015
126d7df
ENH : implement `__getitem__` for Cycler
tacaswell May 6, 2015
a56ea63
API : Only allow addition of equal length cycles
tacaswell May 6, 2015
58610f4
DOC : more edits to docs
tacaswell May 6, 2015
c76b976
DOC : more work on documentation
tacaswell May 7, 2015
14df70f
ENH: Add a rich display hook to Cycler.
danielballan May 7, 2015
2600179
Merge pull request #11 from danielballan/cycler-html
tacaswell May 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST : first round of tests for Cycler
Covers everything but the repr

Tests '+' behavior which may be changed.
  • Loading branch information
tacaswell committed Apr 22, 2015
commit d5ec6d8cef088b0e56a3e3face01f280ad14bd26
83 changes: 83 additions & 0 deletions lib/matplotlib/tests/test_cycler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six
from six.moves import zip
from matplotlib.cycler import cycler
from nose.tools import assert_equal, assert_raises
from itertools import product
from operator import add, iadd, mul, imul


def _cycler_helper(c, length, keys, values):
assert_equal(len(c), length)
assert_equal(len(c), len(list(c.finite_iter())))
assert_equal(len(c), len(c.to_list()))
assert_equal(c.keys, set(keys))

for k, vals in zip(keys, values):
for v, v_target in zip(c, vals):
assert_equal(v[k], v_target)


def test_creation():
c = cycler('c', 'rgb')
yield _cycler_helper, c, 3, ['c'], [['r', 'g', 'b']]
c = cycler('c', list('rgb'))
yield _cycler_helper, c, 3, ['c'], [['r', 'g', 'b']]


def test_compose():
c1 = cycler('c', 'rgb')
c2 = cycler('lw', range(3))
c3 = cycler('lw', range(15))
# addition
yield _cycler_helper, c1+c2, 3, ['c', 'lw'], [list('rgb'), range(3)]
yield _cycler_helper, c2+c1, 3, ['c', 'lw'], [list('rgb'), range(3)]
# miss-matched add lengths
yield _cycler_helper, c1+c3, 3, ['c', 'lw'], [list('rgb'), range(3)]
yield _cycler_helper, c3+c1, 3, ['c', 'lw'], [list('rgb'), range(3)]

# multiplication
target = zip(*product(list('rgb'), range(3)))
yield (_cycler_helper, c1 * c2, 9, ['c', 'lw'], target)

target = zip(*product(range(3), list('rgb')))
yield (_cycler_helper, c2 * c1, 9, ['lw', 'c'], target)

target = zip(*product(range(15), list('rgb')))
yield (_cycler_helper, c3 * c1, 45, ['lw', 'c'], target)


def test_inplace():
c1 = cycler('c', 'rgb')
c2 = cycler('lw', range(3))
c2 += c1
yield _cycler_helper, c2, 3, ['c', 'lw'], [list('rgb'), range(3)]

c3 = cycler('c', 'rgb')
c4 = cycler('lw', range(3))
c3 *= c4
target = zip(*product(list('rgb'), range(3)))
yield (_cycler_helper, c3, 9, ['c', 'lw'], target)


def test_constructor():
c1 = cycler('c', 'rgb')
c2 = cycler('ec', c1)
yield _cycler_helper, c1+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2
c3 = cycler('c', c1)
yield _cycler_helper, c3+c2, 3, ['c', 'ec'], [['r', 'g', 'b']]*2


def test_failures():
c1 = cycler('c', 'rgb')
c2 = cycler('c', c1)
assert_raises(ValueError, add, c1, c2)
assert_raises(ValueError, iadd, c1, c2)
assert_raises(ValueError, mul, c1, c2)
assert_raises(ValueError, imul, c1, c2)

c3 = cycler('ec', c1)

assert_raises(ValueError, cycler, 'c', c2 + c3)