import unittest

from settings import merge_settings


class MergeSettingsTests(unittest.TestCase):
    def test_recursive_merge(self):
        self.assertEqual(
            merge_settings({"s": {"host": "x", "port": 80}}, {"s": {"port": 443}}),
            {"s": {"host": "x", "port": 443}},
        )

    def test_inputs_and_outputs_do_not_alias(self):
        base = {"s": {"host": "x"}, "flags": {"safe": True}}
        overlay = {"s": {"port": 443}}
        merged = merge_settings(base, overlay)
        merged["s"]["host"] = "changed"
        merged["flags"]["safe"] = False
        self.assertEqual(base, {"s": {"host": "x"}, "flags": {"safe": True}})


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