def test_strings_should_not_be_considered_a_collection(self): instance = create_instance(Collection(type=str, container=tuple)) with self.assertRaises(TypeError): instance.attr = b'123'
def test_collection_with_string(self): instance = create_instance(Collection(type=int, container=frozenset)) with self.assertRaises(TypeError): instance.attr = '123'
def test_collection_with_wrong_type(self): instance = create_instance(Collection(type=int, container=frozenset)) with self.assertRaises(TypeError): instance.attr = [1, '2', 3]
def test_collection_gets_stored_in_container(self): instance = create_instance(Collection(type=int, container=frozenset)) instance.attr = [1, 2, 3] self.assertEqual(frozenset([1, 2, 3]), instance.attr)
def test_empty_collection(self): instance = create_instance(Collection(type=int, container=frozenset)) instance.attr = [] self.assertEqual(frozenset(), instance.attr)
def test_container_instance_is_default(self): instance = create_instance(Collection(type=int, container=frozenset)) self.assertEqual(frozenset(), instance.attr)