test_utils.py 682 B

1234567891011121314151617181920212223242526
  1. from __future__ import absolute_import, unicode_literals
  2. import pytest
  3. from celery.utils import cached_property, chunks
  4. @pytest.mark.parametrize('items,n,expected', [
  5. (range(11), 2, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10]]),
  6. (range(11), 3, [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10]]),
  7. (range(10), 2, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]),
  8. ])
  9. def test_chunks(items, n, expected):
  10. x = chunks(iter(list(items)), n)
  11. assert list(x) == expected
  12. def test_cached_property():
  13. def fun(obj):
  14. return fun.value
  15. x = cached_property(fun)
  16. assert x.__get__(None) is x
  17. assert x.__set__(None, None) is x
  18. assert x.__delete__(None) is x