# This code has been automatically generated by:
# dev_scripts/test_codegen/generate_test_for_xmlization_of_concrete_classes.py
# Do NOT edit or append.


"""Test XML de/serialization of concrete classes."""


# pylint: disable=missing-docstring


import io
import xml.etree.ElementTree as ET
import unittest
from typing import Optional

import aas_core3.xmlization as aas_xmlization
import aas_core3.verification as aas_verification

import tests.common
import tests.common_xmlization


class Test_Extension(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Extension`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "extension"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/extension/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/extension/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "extension"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_AdministrativeInformation(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.AdministrativeInformation`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "administrativeInformation"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/administrativeInformation/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/administrativeInformation/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "administrativeInformation"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Qualifier(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Qualifier`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "qualifier"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/qualifier/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/qualifier/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "qualifier"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_AssetAdministrationShell(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.AssetAdministrationShell`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "assetAdministrationShell"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/assetAdministrationShell/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/assetAdministrationShell/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "assetAdministrationShell"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_AssetInformation(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.AssetInformation`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "assetInformation"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/assetInformation/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/assetInformation/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "assetInformation"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Resource(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Resource`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "resource"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/resource/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/resource/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "resource"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_SpecificAssetID(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.SpecificAssetID`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "specificAssetId"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/specificAssetId/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/specificAssetId/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "specificAssetId"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Submodel(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Submodel`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "submodel"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/submodel/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/submodel/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "submodel"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_RelationshipElement(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.RelationshipElement`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "relationshipElement"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/relationshipElement/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/relationshipElement/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "relationshipElement"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_SubmodelElementList(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.SubmodelElementList`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "submodelElementList"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/submodelElementList/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/submodelElementList/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "submodelElementList"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_SubmodelElementCollection(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.SubmodelElementCollection`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "submodelElementCollection"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/submodelElementCollection/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/submodelElementCollection/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "submodelElementCollection"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Property(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Property`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "property"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/property/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/property/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "property"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_MultiLanguageProperty(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.MultiLanguageProperty`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "multiLanguageProperty"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/multiLanguageProperty/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/multiLanguageProperty/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "multiLanguageProperty"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Range(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Range`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "range"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/range/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/range/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "range"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_ReferenceElement(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.ReferenceElement`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "referenceElement"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/referenceElement/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/referenceElement/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "referenceElement"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Blob(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Blob`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "blob"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/blob/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/blob/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "blob"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_File(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.File`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "file"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/file/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/file/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "file"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_AnnotatedRelationshipElement(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.AnnotatedRelationshipElement`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "annotatedRelationshipElement"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/annotatedRelationshipElement/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/annotatedRelationshipElement/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "annotatedRelationshipElement"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Entity(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Entity`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "entity"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/entity/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/entity/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "entity"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_EventPayload(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.EventPayload`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "SelfContained"
                / "Expected"
                / "eventPayload"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                instance = aas_xmlization.event_payload_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(instance))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(instance, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(instance))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "SelfContained"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/eventPayload/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.event_payload_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "SelfContained"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/eventPayload/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                instance = aas_xmlization.event_payload_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(instance))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "SelfContained"
                / "Expected"
                / "eventPayload"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.event_payload_from_iterparse(
                    iterator
                )

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.event_payload_from_stream(fid)

            got_from_file = aas_xmlization.event_payload_from_file(path)

            got_from_str = aas_xmlization.event_payload_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_BasicEventElement(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.BasicEventElement`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "basicEventElement"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/basicEventElement/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/basicEventElement/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "basicEventElement"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Operation(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Operation`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "operation"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/operation/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/operation/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "operation"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_OperationVariable(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.OperationVariable`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "operationVariable"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/operationVariable/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/operationVariable/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "operationVariable"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Capability(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Capability`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "capability"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/capability/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/capability/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "capability"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_ConceptDescription(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.ConceptDescription`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "conceptDescription"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/conceptDescription/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/conceptDescription/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "conceptDescription"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Reference(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Reference`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "reference"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/reference/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/reference/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "reference"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Key(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Key`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "key"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/key/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/key/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "key"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_LangStringNameType(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.LangStringNameType`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringNameType"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringNameType/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringNameType/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringNameType"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_LangStringTextType(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.LangStringTextType`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringTextType"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringTextType/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringTextType/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringTextType"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_Environment(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.Environment`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "SelfContained"
                / "Expected"
                / "environment"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                instance = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(instance))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(instance, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(instance))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "SelfContained"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/environment/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "SelfContained"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/environment/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                instance = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(instance))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "SelfContained"
                / "Expected"
                / "environment"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_EmbeddedDataSpecification(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.EmbeddedDataSpecification`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "embeddedDataSpecification"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/embeddedDataSpecification/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/embeddedDataSpecification/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "embeddedDataSpecification"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_LevelType(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.LevelType`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "levelType"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/levelType/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/levelType/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "levelType"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_ValueReferencePair(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.ValueReferencePair`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "valueReferencePair"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/valueReferencePair/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/valueReferencePair/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "valueReferencePair"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_ValueList(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.ValueList`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "valueList"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/valueList/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/valueList/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "valueList"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_LangStringPreferredNameTypeIEC61360(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.LangStringPreferredNameTypeIEC61360`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringPreferredNameTypeIec61360"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringPreferredNameTypeIec61360/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringPreferredNameTypeIec61360/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringPreferredNameTypeIec61360"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_LangStringShortNameTypeIEC61360(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.LangStringShortNameTypeIEC61360`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringShortNameTypeIec61360"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringShortNameTypeIec61360/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringShortNameTypeIec61360/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringShortNameTypeIec61360"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_LangStringDefinitionTypeIEC61360(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.LangStringDefinitionTypeIEC61360`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringDefinitionTypeIec61360"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringDefinitionTypeIec61360/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/langStringDefinitionTypeIec61360/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "langStringDefinitionTypeIec61360"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


class Test_DataSpecificationIEC61360(unittest.TestCase):
    """
    Test XML de/serialization of the concrete class
    :py:class:`aas_core3.types.DataSpecificationIEC61360`.
    """

    def test_ok(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "dataSpecificationIec61360"
            ).glob("**/*.xml")
        )

        for path in paths:
            text = path.read_text(encoding="utf-8")

            try:
                container = aas_xmlization.environment_from_str(text)
            except Exception as exception:  # pylint: disable=broad-except
                raise AssertionError(
                    f"Unexpected exception when de-serializing: {path}"
                ) from exception

            errors = list(aas_verification.verify(container))

            if len(errors) > 0:
                errors_joined = "\n\n".join(
                    f"{error.path}: {error.cause}" for error in errors
                )
                raise AssertionError(
                    f"One or more unexpected errors from {path}:\n{errors_joined}"
                )

            writer = io.StringIO()
            aas_xmlization.write(container, writer)

            # Check the round-trip
            original = ET.fromstring(text)
            tests.common_xmlization.remove_redundant_whitespace(original)

            serialized = ET.fromstring(aas_xmlization.to_str(container))
            tests.common_xmlization.remove_redundant_whitespace(serialized)

            tests.common_xmlization.assert_elements_equal(
                original, serialized, f"={path}"
            )

    def test_deserialization_failures(self) -> None:
        unserializable_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Unserializable"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/dataSpecificationIec61360/**/*.xml"

        paths = sorted(unserializable_dir.glob(glob_pattern))

        for path in paths:
            observed_exception: Optional[aas_xmlization.DeserializationException] = None

            try:
                _ = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                observed_exception = exception

            assert (
                observed_exception is not None
            ), f"Expected an exception, but got none for: {path}"

            tests.common.record_or_check(
                path=path.parent / (path.name + ".exception"),
                got=f"{observed_exception.path}: {observed_exception.cause}",
            )

    def test_verification_failures(self) -> None:
        invalid_dir = (
            tests.common.TEST_DATA_DIR
            / "Xml"
            / "ContainedInEnvironment"
            / "Unexpected"
            / "Invalid"
        )

        # The first ``*`` corresponds to the cause.
        glob_pattern = "*/dataSpecificationIec61360/**/*.xml"

        paths = sorted(invalid_dir.glob(glob_pattern))

        for path in paths:
            try:
                container = aas_xmlization.environment_from_str(
                    path.read_text(encoding="utf-8")
                )
            except aas_xmlization.DeserializationException as exception:
                raise AssertionError(
                    f"Unexpected failure in deserialization from {path} "
                    f"at {exception.path}: {exception.cause}"
                ) from exception

            errors = list(aas_verification.verify(container))

            self.assertGreater(
                len(errors),
                0,
                f"Expected verification errors from {path}, but got none",
            )

            tests.common.record_or_check(
                path=path.parent / (path.name + ".errors"),
                got="\n".join(f"{error.path}: {error.cause}" for error in errors),
            )

    def test_different_input_forms_give_equal_outcomes(self) -> None:
        paths = sorted(
            (
                tests.common.TEST_DATA_DIR
                / "Xml"
                / "ContainedInEnvironment"
                / "Expected"
                / "dataSpecificationIec61360"
            ).glob("**/*.xml")
        )

        for path in paths:
            with path.open("rt", encoding="utf-8") as fid:
                iterator = ET.iterparse(source=fid, events=["start", "end"])
                got_from_iterparse = aas_xmlization.environment_from_iterparse(iterator)

            with path.open("rt", encoding="utf-8") as fid:
                got_from_stream = aas_xmlization.environment_from_stream(fid)

            got_from_file = aas_xmlization.environment_from_file(path)

            got_from_str = aas_xmlization.environment_from_str(
                path.read_text(encoding="utf-8")
            )

            et_from_iterparse = ET.fromstring(aas_xmlization.to_str(got_from_iterparse))
            tests.common_xmlization.remove_redundant_whitespace(et_from_iterparse)

            et_from_stream = ET.fromstring(aas_xmlization.to_str(got_from_stream))
            tests.common_xmlization.remove_redundant_whitespace(et_from_stream)

            et_from_file = ET.fromstring(aas_xmlization.to_str(got_from_file))
            tests.common_xmlization.remove_redundant_whitespace(et_from_file)

            et_from_str = ET.fromstring(aas_xmlization.to_str(got_from_str))
            tests.common_xmlization.remove_redundant_whitespace(et_from_str)

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_stream, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_file, f"={path}"
            )

            tests.common_xmlization.assert_elements_equal(
                et_from_iterparse, et_from_str, f"={path}"
            )


if __name__ == "__main__":
    unittest.main()


# This code has been automatically generated by:
# dev_scripts/test_codegen/generate_test_for_xmlization_of_concrete_classes.py
# Do NOT edit or append.
