Ejemplo n.º 1
0
    def test_add(self) -> None:
        """Tests the `add` method."""
        with self.subTest("Successful addition"):
            container = PropertiesContainer()
            container.add(self.property)
            self.assertIn(self.property, container)

        with self.subTest("Unsuccessful addition if object already exists"):
            container = PropertiesContainer()
            container.add(self.property)
            with self.assertRaises(ValueError):
                container.add(self.property)
Ejemplo n.º 2
0
    def test_contains(self) -> None:
        """Tests the `__contains__` method."""
        container = PropertiesContainer()
        container.add(self.property)

        with self.subTest("object check"):
            self.assertIn(self.property, container)

        with self.subTest("type check"):
            self.assertIn(OccupiedModals, container)

        with self.subTest("str check"):
            self.assertIn("OccupiedModals", container)

        with self.subTest("TypeError"):
            with self.assertRaises(TypeError):
                self.assertIn(1, container)
Ejemplo n.º 3
0
    def test_remove(self) -> None:
        """Tests the `remove` method."""
        with self.subTest("Remove via object"):
            container = PropertiesContainer()
            container.add(self.property)
            container.remove(self.property)
            self.assertNotIn(self.property, container)

        with self.subTest("Remove via type"):
            container = PropertiesContainer()
            container.add(self.property)
            container.remove(OccupiedModals)
            self.assertNotIn(OccupiedModals, container)

        with self.subTest("Remove via str"):
            container = PropertiesContainer()
            container.add(self.property)
            container.remove("OccupiedModals")
            self.assertNotIn("OccupiedModals", container)

        with self.subTest("TypeError"):
            container = PropertiesContainer()
            container.add(self.property)
            with self.assertRaises(TypeError):
                container.remove(1)

        with self.subTest("KeyError"):
            container = PropertiesContainer()
            container.add(self.property)
            with self.assertRaises(KeyError):
                container.remove("MissingProperty")
Ejemplo n.º 4
0
    def test_discard(self) -> None:
        """Tests the `discard` method."""
        with self.subTest("Discard via object"):
            container = PropertiesContainer()
            container.add(self.property)
            container.discard(self.property)
            self.assertNotIn(self.property, container)

        with self.subTest("Discard via type"):
            container = PropertiesContainer()
            container.add(self.property)
            container.discard(OccupiedModals)
            self.assertNotIn(OccupiedModals, container)

        with self.subTest("Discard via str"):
            container = PropertiesContainer()
            container.add(self.property)
            container.discard("OccupiedModals")
            self.assertNotIn("OccupiedModals", container)

        with self.subTest("TypeError"):
            container = PropertiesContainer()
            container.add(self.property)
            with self.assertRaises(TypeError):
                container.discard(1)  # type: ignore[arg-type]
Ejemplo n.º 5
0
 def test_iter(self) -> None:
     """Tests the `iter` method."""
     container = PropertiesContainer()
     container.add(self.property)
     properties = list(container)
     self.assertEqual(properties, [self.property])
Ejemplo n.º 6
0
 def test_len(self) -> None:
     """Tests the `len` method."""
     container = PropertiesContainer()
     self.assertEqual(len(container), 0)
     container.add(self.property)
     self.assertEqual(len(container), 1)
Ejemplo n.º 7
0
 def test_clear(self) -> None:
     """Tests the `clear` method."""
     container = PropertiesContainer()
     container.add(self.property)
     container.clear()
     self.assertNotIn(self.property, container)
Ejemplo n.º 8
0
    def test_pop(self) -> None:
        """Tests the `pop` method."""
        with self.subTest("Pop via object"):
            container = PropertiesContainer()
            container.add(self.property)
            prop = container.pop()
            self.assertNotIn(self.property, container)
            self.assertEqual(prop, self.property)

        with self.subTest("Pop via type"):
            container = PropertiesContainer()
            container.add(self.property)
            prop = container.pop()
            self.assertNotIn(OccupiedModals, container)
            self.assertEqual(prop, self.property)

        with self.subTest("Pop via str"):
            container = PropertiesContainer()
            container.add(self.property)
            prop = container.pop()
            self.assertNotIn("OccupiedModals", container)
            self.assertEqual(prop, self.property)

        with self.subTest("KeyError"):
            container = PropertiesContainer()
            with self.assertRaises(KeyError):
                _ = container.pop()