# -*- coding: utf-8 -*-
# Copyright (c) 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test Domain."""

import unittest

from neural_insights.components.model.domain import Domain


class TestDomain(unittest.TestCase):
    """Test Domain class."""

    def test_none_domain(self) -> None:
        """Test that unknown domain serializes as expected."""
        domain = Domain()

        expected = {
            "domain": "",
            "domain_flavour": "",
        }

        self.assertEqual(expected, domain.serialize())

    def test_domain_without_flavour(self) -> None:
        """Test that domain serializes as expected."""
        domain = Domain(domain="foo")

        expected = {
            "domain": "foo",
            "domain_flavour": "",
        }

        self.assertEqual(expected, domain.serialize())

    def test_domain_with_flavour(self) -> None:
        """Test that domain serializes as expected."""
        domain = Domain(domain="foo", domain_flavour="bar")

        expected = {
            "domain": "foo",
            "domain_flavour": "bar",
        }

        self.assertEqual(expected, domain.serialize())

    def test_domain_with_flavour_only_fails(self) -> None:
        """Test that domain can't be created given flavour only."""
        with self.assertRaisesRegex(ValueError, "Domain must be set when given flavour"):
            Domain(domain_flavour="bar")


if __name__ == "__main__":
    unittest.main()
