|
7 | 7 | assert_raises, assert_true) |
8 | 8 | from itertools import product, cycle, chain |
9 | 9 | from operator import add, iadd, mul, imul |
| 10 | +from collections import defaultdict |
10 | 11 |
|
11 | 12 |
|
12 | 13 | def _cycler_helper(c, length, keys, values): |
@@ -95,6 +96,8 @@ def test_failures(): |
95 | 96 | assert_raises(ValueError, iadd, c1, c2) |
96 | 97 | assert_raises(ValueError, mul, c1, c2) |
97 | 98 | assert_raises(ValueError, imul, c1, c2) |
| 99 | + assert_raises(TypeError, iadd, c2, 'aardvark') |
| 100 | + assert_raises(TypeError, imul, c2, 'aardvark') |
98 | 101 |
|
99 | 102 | c3 = cycler(ec=c1) |
100 | 103 |
|
@@ -265,6 +268,8 @@ def test_eq(): |
265 | 268 | yield _eq_test_helper, a, c, False |
266 | 269 | d = cycler(c='ymk') |
267 | 270 | yield _eq_test_helper, b, d, False |
| 271 | + e = cycler(c='orange') |
| 272 | + yield _eq_test_helper, b, e, False |
268 | 273 |
|
269 | 274 |
|
270 | 275 | def test_cycler_exceptions(): |
@@ -296,3 +301,30 @@ def test_concat_fail(): |
296 | 301 | b = cycler('b', range(3)) |
297 | 302 | assert_raises(ValueError, concat, a, b) |
298 | 303 | 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