From 7ac106096f8da32aa20bc2c4f18730d88345786a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 3 Oct 2015 20:24:28 +0200 Subject: [PATCH] add tests for config-module --- test/test_config.py | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/test_config.py diff --git a/test/test_config.py b/test/test_config.py new file mode 100644 index 00000000..3aaeb42c --- /dev/null +++ b/test/test_config.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright 2015 Mike Fährmann +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. + +import unittest +import gallery_dl.config as config +import os +import tempfile + +class TestConfig(unittest.TestCase): + + def setUp(self): + fd, self._configfile = tempfile.mkstemp() + with os.fdopen(fd, "w") as file: + file.write('{"a": "1", "b": {"c": "text"}}') + config.load(self._configfile) + + def tearDown(self): + config.clear() + os.remove(self._configfile) + + def test_get(self): + self.assertEqual(config.get("a"), "1") + self.assertEqual(config.get("b.c"), "text") + self.assertEqual(config.get("d"), None) + self.assertEqual(config.get("e.f.g", 123), 123) + + def test_set(self): + config.set("b.c", [1, 2, 3]) + config.set("e.f.g", 234) + self.assertEqual(config.get("b.c"), [1, 2, 3]) + self.assertEqual(config.get("e.f.g"), 234) + + def test_interpolate(self): + self.assertEqual(config.interpolate("a"), "1") + self.assertEqual(config.interpolate("b.a"), "1") + self.assertEqual(config.interpolate("b.c", "2"), "text") + self.assertEqual(config.interpolate("b.d", "2"), "2") + config.set("d", 123) + self.assertEqual(config.interpolate("b.d", "2"), 123) + self.assertEqual(config.interpolate("d.d", "2"), 123) + +if __name__ == '__main__': + unittest.main()