test_utils.py 631 B

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