"""Test perpetual inventory helpers.""" from reporting.utils.perpetual_inventory import ( dict_from_collection, max_dict, min_dict, ) def test_dict_from_collection(): """Test dict_from_collection returns expected dict.""" test_collection_input = [ {'a': 1, 'b': 2, 'c': 3}, {'a': 4, 'b': 5, 'c': 6}, {'a': 7, 'b': 8, 'c': 9}, ] test_dict_output = { 1: [{'a': 1, 'b': 2, 'c': 3}], 4: [{'a': 4, 'b': 5, 'c': 6}], 7: [{'a': 7, 'b': 8, 'c': 9}], } assert dict_from_collection(test_collection_input, 'a') == test_dict_output def test_min_dict(): """Return dict with min value for key in collection.""" test_dict_input = {'key': [{'x': 1}, {'x': 2}, {'x': 3}]} expected_output = {'key': {'x': 1}} output = min_dict(test_dict_input, 'x') assert output == expected_output def test_max_dict(): """Return dict with max value for key in collection.""" test_dict_input = {'key': [{'x': 1}, {'x': 2}, {'x': 3}]} expected_output = {'key': {'x': 3}} output = max_dict(test_dict_input, 'x') assert output == expected_output