import pytest from src.backend.utils import collections as coll @pytest.mark.parametrize( "collection_type", [ list, set, tuple, ], ) def test_filter_values(collection_type): mapping = {"a": 1, "b": 2, "c": None} collection = collection_type([1, None]) assert coll.filter_values(mapping, collection) == {"b": 2} def test_group_dicts_by_type(): dicts = [ {"type": "A", "k": "a1", "v": "v1"}, {"type": "A", "k": "a2", "v": "v2"}, {"type": "B", "k": "b1", "v": "v1"}, ] assert coll.group_dicts_by_type(dicts, "type", "k", "v") == { "A": {"a1": "v1", "a2": "v2"}, "B": {"b1": "v1"}, } def test_group_dicts_by_type_empty(): dicts = [] assert coll.group_dicts_by_type(dicts, "type", "k", "v") == {} @pytest.mark.asyncio async def test_async_dict(): expected = {"a": "A", "b": "B", "c": "C"} sample_keys = expected.keys() async def func(key): return key.upper() result = await coll.async_dict(func, sample_keys) assert result == expected