import sys
import unittest

from loesung import flach


class Tests(unittest.TestCase):
    def test_verschachtelt(self):
        self.assertEqual(flach({"a": {"b": 1, "c": {"d": 2}}, "e": 3}),
                         {"a.b": 1, "a.c.d": 2, "e": 3})

    def test_leere_dicts(self):
        self.assertEqual(flach({"a": {}, "b": 1}), {"b": 1})

    def test_typfehler(self):
        with self.assertRaises(TypeError):
            flach([1, 2])


if __name__ == "__main__":
    r = unittest.main(exit=False).result
    sys.exit(0 if r.wasSuccessful() else 1)
