Exemplo n.º 1
0
 def should_return_false_for_decimals():
     assert is_collection(Decimal("1.0")) is False
     assert is_collection(Decimal("-1.0")) is False
     assert is_collection(Decimal("0.0")) is False
     assert is_collection(Decimal("NaN")) is False
     assert is_collection(Decimal("Inf")) is False
     assert is_collection(Decimal("-Inf")) is False
Exemplo n.º 2
0
 def should_return_false_for_floats():
     assert is_collection(1.0) is False
     assert is_collection(-1.0) is False
     assert is_collection(0.0) is False
     assert is_collection(float("NaN")) is False
     assert is_collection(float("Inf")) is False
     assert is_collection(float("-Inf")) is False
Exemplo n.º 3
0
 def a_keys_view_is_a_collection():
     assert is_collection({}.keys()) is True
     assert is_collection({1: 2, 3: 4}.keys()) is True
Exemplo n.º 4
0
 def should_return_true_for_sets():
     assert is_collection(set()) is True
     assert is_collection({0, 1, 2}) is True
     assert is_collection({"A", "B", "C"}) is True
Exemplo n.º 5
0
 def should_return_false_for_booleans():
     assert is_collection(True) is False
     assert is_collection(False) is False
Exemplo n.º 6
0
 def should_return_false_for_byte_strings():
     assert is_collection(b"ABC") is False
     assert is_collection(b"0") is False
     assert is_collection(b"") is False
Exemplo n.º 7
0
 def should_return_false_for_infinite_generators():
     assert is_collection(count()) is False
Exemplo n.º 8
0
 def should_return_false_for_range_function():
     assert is_collection(range) is False
Exemplo n.º 9
0
 def should_return_false_for_frozen_dicts():
     assert is_collection(FrozenDict()) is False
     assert is_collection(FrozenDict({"__iter__": True})) is False
     assert is_collection(FrozenDict({0: "A", 1: "B", 2: "C"})) is False
Exemplo n.º 10
0
 def null_is_not_a_collection():
     assert is_collection(None) is False
Exemplo n.º 11
0
 def a_frozen_dict_is_not_a_collection():
     assert is_collection(FrozenDict()) is False
     assert is_collection(FrozenDict({1: 2, 3: 4})) is False
Exemplo n.º 12
0
 def a_frozen_list_is_a_collection():
     assert is_collection(FrozenList()) is True
     assert is_collection(FrozenList([1, 2, 3])) is True
Exemplo n.º 13
0
 def an_infinite_generator_is_not_a_collection():
     assert is_collection(count()) is False
Exemplo n.º 14
0
 def a_range_is_a_collection():
     assert is_collection(range(10)) is True
Exemplo n.º 15
0
 def a_values_view_is_a_collection():
     assert is_collection({}.values()) is True
     assert is_collection({1: 2, 3: 4}.values()) is True
Exemplo n.º 16
0
 def should_return_true_for_values_view():
     assert is_collection({}.values()) is True
     assert is_collection({0: "A", 1: "B", 2: "C"}.values()) is True
Exemplo n.º 17
0
 def should_return_true_for_ranges():
     assert is_collection(range(10)) is True
Exemplo n.º 18
0
 def should_return_false_for_default_dicts():
     assert is_collection(defaultdict(list)) is False
Exemplo n.º 19
0
 def should_return_false_for_generator_function():
     assert is_collection(count) is False
Exemplo n.º 20
0
 def should_return_false_for_simple_objects():
     assert is_collection(object) is False
     assert is_collection(object()) is False
Exemplo n.º 21
0
 def should_return_false_for_none_object():
     assert is_collection(None) is False
Exemplo n.º 22
0
    def should_return_false_for_invalid_iterator_object():
        class NoIterator:
            __iter__ = None

        assert is_collection(NoIterator) is False
        assert is_collection(NoIterator()) is False
Exemplo n.º 23
0
 def should_return_false_for_ints():
     assert is_collection(1) is False
     assert is_collection(-1) is False
     assert is_collection(0) is False
Exemplo n.º 24
0
 def should_return_true_for_frozen_lists():
     assert is_collection(FrozenList()) is True
     assert is_collection(FrozenList([0, 1, 2])) is True
     assert is_collection(FrozenList(["A", "B", "C"])) is True
Exemplo n.º 25
0
 def should_return_true_for_tuples():
     assert is_collection(()) is True
     assert is_collection((0, 1, 1)) is True
     assert is_collection(("A", "B", "C")) is True
Exemplo n.º 26
0
 def should_return_true_for_named_tuples():
     named = namedtuple("named", "A B C")
     assert is_collection(named(0, 1, 2)) is True
Exemplo n.º 27
0
 def should_return_true_for_lists():
     assert is_collection([]) is True
     assert is_collection([0, 1, 2]) is True
     assert is_collection(["A", "B", "C"]) is True
Exemplo n.º 28
0
 def should_return_true_for_arrays():
     assert is_collection(array("b")) is True
     assert is_collection(array("b", [0, 1, 2])) is True
     assert is_collection(array("i")) is True
     assert is_collection(array("i", [0, 1, 2])) is True
Exemplo n.º 29
0
 def should_return_false_for_dicts():
     assert is_collection({}) is False
     assert is_collection({"__iter__": True}) is False
     assert is_collection({0: "A", 1: "B", 2: "C"}) is False
Exemplo n.º 30
0
 def a_defaultdict_is_not_a_collection():
     assert is_collection(defaultdict(list)) is False