# HG changeset patch # User Franz Glasner # Date 1521380681 -3600 # Node ID 84b9578cacce7ceb30a27e63e9285eee25451deb # Parent 75738d488e9d7471063dbfe8325e117f7ad1dd21 Start with unit tests diff -r 75738d488e9d -r 84b9578cacce CHANGES.txt --- a/CHANGES.txt Sun Mar 18 14:21:48 2018 +0100 +++ b/CHANGES.txt Sun Mar 18 14:44:41 2018 +0100 @@ -1,7 +1,7 @@ .. -*- coding: utf-8; mode: rst; -*- .. -.. Valid tags: doc, feature, bugfix +.. Valid tags: doc, feature, bugfix, test .. _changelog: @@ -17,7 +17,12 @@ .. change:: :tags: doc - Begin the documentation with `Sphinx `_. + Begin the documentation with `Sphinx `_ + + .. change:: + :tags: test + + Begin formal unittests .. changelog:: :version: 0.5 diff -r 75738d488e9d -r 84b9578cacce MANIFEST.in --- a/MANIFEST.in Sun Mar 18 14:21:48 2018 +0100 +++ b/MANIFEST.in Sun Mar 18 14:44:41 2018 +0100 @@ -1,3 +1,5 @@ include .hg* *.txt requirement* -recursive-include doc *.* +graft doc +graft tests prune doc/_build +global-exclude *.pyc *.pyo diff -r 75738d488e9d -r 84b9578cacce doc/conf.py --- a/doc/conf.py Sun Mar 18 14:21:48 2018 +0100 +++ b/doc/conf.py Sun Mar 18 14:44:41 2018 +0100 @@ -209,4 +209,4 @@ # -- Options for changelog --------------------------------------------------- -changelog_inner_tag_sort = ['feature', 'bugfix', 'doc'] +changelog_inner_tag_sort = ['feature', 'bugfix', 'test', 'doc'] diff -r 75738d488e9d -r 84b9578cacce tests/data/conf1.ini --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/conf1.ini Sun Mar 18 14:44:41 2018 +0100 @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +[config] +key1 = the value +key2 = :int:2 +key3 = :float:5.7 +key4 = :bool:yes +key5 = :bool:off diff -r 75738d488e9d -r 84b9578cacce tests/data/conf1.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/conf1.py Sun Mar 18 14:44:41 2018 +0100 @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +key1 = u"the value" +key2 = 2 +key3 = 5.7 +key4 = True +key5 = False diff -r 75738d488e9d -r 84b9578cacce tests/data/conf1.yml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/conf1.yml Sun Mar 18 14:44:41 2018 +0100 @@ -0,0 +1,9 @@ +# -*- coding: utf-8; mode: yaml; indent-tabs-mode: nil; -*- +%YAML 1.1 +--- + +key1: the value +key2: 2 +key3: 5.7 +key4: true +key5: false diff -r 75738d488e9d -r 84b9578cacce tests/data/conf2.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/conf2.py Sun Mar 18 14:44:41 2018 +0100 @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + +__all__ = ["key1", "nonexistingkey"] + +key1 = u"the next value" +key2 = "non-exported value" diff -r 75738d488e9d -r 84b9578cacce tests/data/conf3.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/data/conf3.py Sun Mar 18 14:44:41 2018 +0100 @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +key1 = u"the next value " +_key2 = "non-exported value" diff -r 75738d488e9d -r 84b9578cacce tests/test.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test.py Sun Mar 18 14:44:41 2018 +0100 @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +import sys +import os +import unittest + +sys.path.insert( + 0, + os.path.abspath( + os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))) + +import configmix +import configmix.ini +import configmix.yaml +import configmix.py +from configmix.compat import u + + +TESTDATADIR = os.path.join( + os.path.abspath(os.path.dirname(__file__)), + "data") + + +class T01Basic(unittest.TestCase): + + """Check with low-level internal interfaces""" + + def __check_types(self, cfg): + self.assertEqual(u("the value"), + cfg.get("key1")) + self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) + self.assertEqual(2, cfg.get("key2")) + self.assertEqual(5.7, cfg.get("key3")) + self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) + self.assertTrue(cfg.get("key4")) + self.assertTrue(isinstance(cfg.get("key4"), bool)) + self.assertFalse(cfg.get("key5")) + self.assertTrue(isinstance(cfg.get("key5"), bool)) + + def test01_ini_types(self): + cfg = configmix.ini.load(os.path.join(TESTDATADIR, "conf1.ini")) + self.__check_types(cfg) + + def test02_py_types(self): + cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf1.py")) + self.__check_types(cfg) + + def test03_yaml_types(self): + with open(os.path.join(TESTDATADIR, "conf1.yml"), "rt") as f: + cfg = configmix.yaml.safe_load(f) + self.__check_types(cfg) + + def test04_py_export_all(self): + # When __all__ is given only it's keys are exported + cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf2.py")) + self.assertEqual(u("the next value"), cfg.get("key1")) + self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) + self.assertTrue(cfg.get("key2") is None) + + def test05_py_hide_private(self): + # When no __all__ is given all symbols with leading "_" are hidden + cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf3.py")) + self.assertEqual(u("the next value "), cfg.get("key1")) + self.assertTrue(isinstance(cfg.get("key1"), type(u('')))) + self.assertTrue(cfg.get("_key2") is None) + + +if __name__ == "__main__": + unittest.main()