1from collections import defaultdict, namedtuple
2from itertools import count
3
4from graphql.pyutils import FrozenDict, FrozenList, is_collection
5
6
7def describe_is_collection():
8    def null_is_not_a_collection():
9        assert is_collection(None) is False
10
11    def a_string_is_not_a_collection():
12        assert is_collection("") is False
13        assert is_collection("text") is False
14
15    def a_byte_string_is_not_a_collection():
16        assert is_collection(b"") is False
17        assert is_collection(b"bytes") is False
18
19    def a_list_is_a_collection():
20        assert is_collection([]) is True
21        assert is_collection([1, 2, 3]) is True
22
23    def a_tuple_is_a_collection():
24        assert is_collection(()) is True
25        assert is_collection((1, 2, 3)) is True
26
27    def a_namedtuple_is_a_collection():
28        named = namedtuple("named", "a b c")
29        assert is_collection(named(1, 2, 3)) is True
30
31    def a_dict_is_not_a_collection():
32        assert is_collection({}) is False
33        assert is_collection({1: 2, 3: 4}) is False
34
35    def a_defaultdict_is_not_a_collection():
36        assert is_collection(defaultdict(list)) is False
37
38    def a_keys_view_is_a_collection():
39        assert is_collection({}.keys()) is True
40        assert is_collection({1: 2, 3: 4}.keys()) is True
41
42    def a_values_view_is_a_collection():
43        assert is_collection({}.values()) is True
44        assert is_collection({1: 2, 3: 4}.values()) is True
45
46    def a_range_is_a_collection():
47        assert is_collection(range(10)) is True
48
49    def range_function_itself_is_not_a_collection():
50        assert is_collection(range) is False
51
52    def an_infinite_generator_is_not_a_collection():
53        assert is_collection(count()) is False
54
55    def a_frozen_list_is_a_collection():
56        assert is_collection(FrozenList()) is True
57        assert is_collection(FrozenList([1, 2, 3])) is True
58
59    def a_frozen_dict_is_not_a_collection():
60        assert is_collection(FrozenDict()) is False
61        assert is_collection(FrozenDict({1: 2, 3: 4})) is False
62