示例#1
0
 def test_iter(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     sut.append(entity1, entity2, entity3)
     self.assertSequenceEqual([entity1, entity2, entity3], list(sut))
示例#2
0
 def test_getitem_by_indices(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     sut.append(entity1, entity2, entity3)
     self.assertSequenceEqual([entity1, entity3], sut[0::2])
示例#3
0
 def test_len(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     sut.append(entity1, entity2, entity3)
     self.assertEqual(3, len(sut))
示例#4
0
    def test_contains(self) -> None:
        sut = SingleTypeEntityCollection()
        entity1 = Entity()
        entity2 = Entity()
        sut.append(entity1)

        self.assertIn(entity1, sut)
        self.assertNotIn(entity2, sut)
示例#5
0
 def test_clear(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     sut.append(entity1, entity2, entity3)
     sut.clear()
     self.assertSequenceEqual([], sut)
示例#6
0
 def test_list(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     sut.append(entity1, entity2, entity3)
     self.assertIs(entity1, sut[0])
     self.assertIs(entity2, sut[1])
     self.assertIs(entity3, sut[2])
示例#7
0
 def test_remove(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     entity4 = Entity()
     sut.append(entity1, entity2, entity3, entity4)
     sut.remove(entity4, entity2)
     self.assertSequenceEqual([entity1, entity3], sut)
示例#8
0
    def test_delitem_by_index(self) -> None:
        sut = SingleTypeEntityCollection()
        entity1 = Entity()
        entity2 = Entity()
        entity3 = Entity()
        sut.append(entity1, entity2, entity3)

        del sut[1]

        self.assertSequenceEqual([entity1, entity3], sut)
示例#9
0
    def test_delitem_by_entity_id(self) -> None:
        sut = SingleTypeEntityCollection()
        entity1 = Entity('1')
        entity2 = Entity('2')
        entity3 = Entity('3')
        sut.append(entity1, entity2, entity3)

        del sut['2']

        self.assertSequenceEqual([entity1, entity3], sut)
示例#10
0
 def test_add(self) -> None:
     sut1 = SingleTypeEntityCollection()
     sut2 = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     sut1.append(entity1)
     sut2.append(entity2)
     sut_added = sut1 + sut2
     self.assertIsInstance(sut_added, SingleTypeEntityCollection)
     self.assertSequenceEqual([entity1, entity2], sut_added)
示例#11
0
 def test_getitem_by_index(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     sut.append(entity1, entity2, entity3)
     self.assertIs(entity1, sut[0])
     self.assertIs(entity2, sut[1])
     self.assertIs(entity3, sut[2])
     with self.assertRaises(IndexError):
         sut[3]
示例#12
0
 def test_append(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     sut.append(entity3)
     sut.append(entity2)
     sut.append(entity1)
     # Append an already appended value again, and assert that it was ignored.
     sut.append(entity1)
     self.assertSequenceEqual([entity3, entity2, entity1], sut)
示例#13
0
 def test_getitem_by_entity_id(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity('1')
     entity2 = Entity('2')
     entity3 = Entity('3')
     sut.append(entity1, entity2, entity3)
     self.assertIs(entity1, sut['1'])
     self.assertIs(entity2, sut['2'])
     self.assertIs(entity3, sut['3'])
     with self.assertRaises(KeyError):
         sut['4']
示例#14
0
 def test_prepend(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity('1')
     entity2 = Entity('2')
     entity3 = Entity('3')
     sut.prepend(entity3)
     sut.prepend(entity2)
     sut.prepend(entity1)
     # Prepend an already prepended value again, and assert that it was ignored.
     sut.prepend(entity1)
     self.assertIs(entity1, sut['1'])
     self.assertIs(entity2, sut['2'])
     self.assertIs(entity3, sut['3'])
示例#15
0
 def test_set_like_functionality(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     entity4 = Entity()
     entity5 = Entity()
     entity6 = Entity()
     entity7 = Entity()
     entity8 = Entity()
     entity9 = Entity()
     # Ensure duplicates are skipped.
     sut.append(entity1, entity2, entity3, entity1, entity2, entity3,
                entity1, entity2, entity3)
     # Ensure skipped duplicates do not affect further new values.
     sut.append(entity1, entity2, entity3, entity4, entity5, entity6,
                entity7, entity8, entity9)
     self.assertSequenceEqual([
         entity1, entity2, entity3, entity4, entity5, entity6, entity7,
         entity8, entity9
     ], sut)
示例#16
0
 def test_replace(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     entity4 = Entity()
     entity5 = Entity()
     entity6 = Entity()
     sut.append(entity1, entity2, entity3)
     sut.replace(entity4, entity5, entity6)
     self.assertSequenceEqual([entity4, entity5, entity6], sut)
示例#17
0
 def test_entity_type_with_instance(self) -> None:
     self.assertEqual(Entity, Entity().entity_type())
示例#18
0
 def test_id(self) -> None:
     entity_id = '000000001'
     sut = Entity(entity_id)
     self.assertEqual(entity_id, sut.id)