1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 17:49:37 +01:00

Move recorder chunk utils to shared collection utils (#118065)

This commit is contained in:
Jan Bouwhuis
2024-05-25 00:49:39 +02:00
committed by GitHub
parent 7522bbfa9d
commit c616fc036e
9 changed files with 72 additions and 60 deletions
+24
View File
@@ -0,0 +1,24 @@
"""Test collection utils."""
from homeassistant.util.collection import chunked_or_all
def test_chunked_or_all() -> None:
"""Test chunked_or_all can iterate chunk sizes larger than the passed in collection."""
all_items = []
incoming = (1, 2, 3, 4)
for chunk in chunked_or_all(incoming, 2):
assert len(chunk) == 2
all_items.extend(chunk)
assert all_items == [1, 2, 3, 4]
all_items = []
incoming = (1, 2, 3, 4)
for chunk in chunked_or_all(incoming, 5):
assert len(chunk) == 4
# Verify the chunk is the same object as the incoming
# collection since we want to avoid copying the collection
# if we don't need to
assert chunk is incoming
all_items.extend(chunk)
assert all_items == [1, 2, 3, 4]