Esempio n. 1
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])
Esempio n. 2
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))
Esempio n. 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))
Esempio n. 4
0
    def test_contains(self) -> None:
        sut = SingleTypeEntityCollection()
        entity1 = Entity()
        entity2 = Entity()
        sut.append(entity1)

        self.assertIn(entity1, sut)
        self.assertNotIn(entity2, sut)
Esempio n. 5
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])
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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']
Esempio n. 9
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]
Esempio n. 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)
Esempio n. 11
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)
Esempio n. 12
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'])
Esempio n. 13
0
 def test_clear(self) -> None:
     sut = SingleTypeEntityCollection()
     entity1 = Entity()
     entity2 = Entity()
     entity3 = Entity()
     sut.append(entity1, entity2, entity3)
     sut.clear()
     self.assertSequenceEqual([], sut)
Esempio n. 14
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)
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
0
 def test_pickle(self) -> None:
     sut = SingleTypeEntityCollection()
     pickle.dumps(sut)