Skip to content

Commit 714b346

Browse files
committed
TST: add explicit tests for by_key
Used internally for slicing so was implicitly covered.
1 parent dee6eca commit 714b346

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test_cycler.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
assert_raises, assert_true)
88
from itertools import product, cycle, chain
99
from operator import add, iadd, mul, imul
10+
from collections import defaultdict
1011

1112

1213
def _cycler_helper(c, length, keys, values):
@@ -300,3 +301,30 @@ def test_concat_fail():
300301
b = cycler('b', range(3))
301302
assert_raises(ValueError, concat, a, b)
302303
assert_raises(ValueError, a.concat, b)
304+
305+
306+
def _by_key_helper(cy):
307+
res = cy.by_key()
308+
target = defaultdict(list)
309+
for sty in cy:
310+
for k, v in sty.items():
311+
target[k].append(v)
312+
313+
assert_equal(res, target)
314+
315+
316+
def test_by_key_add():
317+
input_dict = dict(c=list('rgb'), lw=[1, 2, 3])
318+
cy = cycler(c=input_dict['c']) + cycler(lw=input_dict['lw'])
319+
res = cy.by_key()
320+
assert_equal(res, input_dict)
321+
yield _by_key_helper, cy
322+
323+
324+
def test_by_key_mul():
325+
input_dict = dict(c=list('rg'), lw=[1, 2, 3])
326+
cy = cycler(c=input_dict['c']) * cycler(lw=input_dict['lw'])
327+
res = cy.by_key()
328+
assert_equal(input_dict['lw'] * len(input_dict['c']),
329+
res['lw'])
330+
yield _by_key_helper, cy

0 commit comments

Comments
 (0)