"""
Test mixins for MetadataContainer functionality.

Provides reusable test cases for any class that uses the MetadataContainer mixin.
"""


class MetadataContainerTestMixin:
    """
    Mixin providing standard tests for MetadataContainer behavior.

    Classes using this mixin must implement:
    - create_test_object() -> object with MetadataContainer mixin
    """

    def create_test_object(self):
        """
        Create an instance of the object to test.
        Must be implemented by test class.
        """
        raise NotImplementedError("Test class must implement create_test_object()")

    def test_set_and_get_metadata(self):
        """Test basic metadata storage and retrieval."""
        obj = self.create_test_object()

        # Set various types of metadata
        obj.set_metadata("string_key", "string_value")
        obj.set_metadata("int_key", 42)
        obj.set_metadata("list_key", [1, 2, 3])
        obj.set_metadata("dict_key", {"nested": "value"})

        # Verify retrieval
        self.assertEqual(obj.get_metadata("string_key"), "string_value")
        self.assertEqual(obj.get_metadata("int_key"), 42)
        self.assertEqual(obj.get_metadata("list_key"), [1, 2, 3])
        self.assertEqual(obj.get_metadata("dict_key"), {"nested": "value"})

    def test_get_nonexistent_metadata(self):
        """Test that getting nonexistent metadata returns None."""
        obj = self.create_test_object()

        result = obj.get_metadata("nonexistent_key")
        self.assertIsNone(result, "Nonexistent metadata should return None")

    def test_update_metadata(self):
        """Test that metadata values can be updated."""
        obj = self.create_test_object()

        # Set initial value
        obj.set_metadata("key", "initial")
        self.assertEqual(obj.get_metadata("key"), "initial")

        # Update value
        obj.set_metadata("key", "updated")
        self.assertEqual(
            obj.get_metadata("key"),
            "updated",
            "Metadata should be updateable")

    def test_metadata_isolation(self):
        """Test that metadata is isolated between instances."""
        obj1 = self.create_test_object()
        obj2 = self.create_test_object()

        obj1.set_metadata("key", "value1")
        obj2.set_metadata("key", "value2")

        self.assertEqual(obj1.get_metadata("key"), "value1")
        self.assertEqual(obj2.get_metadata("key"), "value2")
        self.assertNotEqual(obj1.get_metadata("key"), obj2.get_metadata("key"))
