Exemplo n.º 1
0
 def test_getitem_by_indices(self) -> None:
     sut = MultipleTypesEntityCollection()
     entity_one = self._One()
     entity_other = self._Other()
     sut.append(entity_one, entity_other)
     self.assertSequenceEqual([entity_one], sut[0:1:1])
     self.assertSequenceEqual([entity_other], sut[1::1])
Exemplo n.º 2
0
 def test_getitem_by_entity_type(self) -> None:
     sut = MultipleTypesEntityCollection()
     entity_one = self._One()
     entity_other = self._Other()
     sut.append(entity_one, entity_other)
     self.assertSequenceEqual([entity_one], sut[self._One])
     self.assertSequenceEqual([entity_other], sut[self._Other])
     # Ensure that getting previously unseen entity types automatically creates and returns a new collection.
     self.assertSequenceEqual([], sut[Entity])
Exemplo n.º 3
0
 def test_getitem_by_index(self) -> None:
     sut = MultipleTypesEntityCollection()
     entity_one = self._One()
     entity_other = self._Other()
     sut.append(entity_one, entity_other)
     self.assertIs(entity_one, sut[0])
     self.assertIs(entity_other, sut[1])
     with self.assertRaises(IndexError):
         sut[2]
Exemplo n.º 4
0
 def test_append(self) -> None:
     sut = MultipleTypesEntityCollection()
     entity_one = self._One()
     entity_other1 = self._Other()
     entity_other2 = self._Other()
     entity_other3 = self._Other()
     sut.append(entity_one, entity_other1, entity_other2, entity_other3)
     self.assertSequenceEqual([entity_other1, entity_other2, entity_other3],
                              sut[self._Other])
Exemplo n.º 5
0
 def test_getitem_by_entity_type_name(self) -> None:
     sut = MultipleTypesEntityCollection()
     # Use an existing ancestry entity type, because converting an entity type name to an entity type only works for
     # entity types in a single module namespace.
     entity = Person(None)
     sut.append(entity)
     self.assertSequenceEqual([entity], sut['Person'])
     # Ensure that getting previously unseen entity types automatically creates and returns a new collection.
     with self.assertRaises(ValueError):
         sut['NonExistentEntityType']
Exemplo n.º 6
0
 def test_len(self) -> None:
     sut = MultipleTypesEntityCollection()
     entity_one = self._One()
     entity_other = self._Other()
     sut[self._One].append(entity_one)
     sut[self._Other].append(entity_other)
     self.assertEqual(2, len(sut))
Exemplo n.º 7
0
 def test_iter(self) -> None:
     sut = MultipleTypesEntityCollection()
     entity_one = self._One()
     entity_other = self._Other()
     sut[self._One].append(entity_one)
     sut[self._Other].append(entity_other)
     self.assertSequenceEqual([entity_one, entity_other], list(sut))
Exemplo n.º 8
0
 def test_contain(self) -> None:
     sut = MultipleTypesEntityCollection()
     entity_one = self._One()
     entity_other1 = self._Other()
     entity_other2 = self._Other()
     sut[self._One].append(entity_one)
     sut[self._Other].append(entity_other1)
     self.assertIn(entity_one, sut)
     self.assertIn(entity_other1, sut)
     self.assertNotIn(entity_other2, sut)
Exemplo n.º 9
0
 def test_add(self) -> None:
     sut1 = MultipleTypesEntityCollection()
     sut2 = MultipleTypesEntityCollection()
     entity1_one = self._One()
     entity1_other = self._One()
     entity2_one = self._Other()
     entity2_other = self._Other()
     sut1.append(entity1_one, entity1_other)
     sut2.append(entity2_one, entity2_other)
     sut_added = sut1 + sut2
     self.assertIsInstance(sut_added, MultipleTypesEntityCollection)
     self.assertSequenceEqual(
         [entity1_one, entity1_other, entity2_one, entity2_other],
         sut_added)
Exemplo n.º 10
0
 def __init__(self):
     self._entities = MultipleTypesEntityCollection()