changeset 196:13527d70e9e3

An additional unit test with a TOML style configuration file
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 03 May 2019 21:59:51 +0200
parents 28e6c1413947
children 7865f28038a4
files tests/data/conf24.toml tests/test.py
diffstat 2 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/data/conf24.toml	Fri May 03 21:59:51 2019 +0200
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+
+tmpdir = '{{_tmpdir}}\4'
+
+[db.user]
+name = "the_database_user_2"
+__doc2 = "Overwriting a comment"
+pwd="the-database-password-2"
+
+[db.locinfo.ro]
+hostname = "3rd-host"
--- a/tests/test.py	Fri May 03 21:51:09 2019 +0200
+++ b/tests/test.py	Fri May 03 21:59:51 2019 +0200
@@ -223,6 +223,33 @@
             u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
             url)
 
+    def test02_load_with_toml(self):
+        cfg = self._load(
+            os.path.join(TESTDATADIR, "conf20.yml"),
+            os.path.join(TESTDATADIR, "conf21.yml"),
+            # .ini replaced with an equivalent .toml
+            os.path.join(TESTDATADIR, "conf24.toml"))
+
+        self.assertEqual(u("the_database_user_2"),
+                         cfg.getvar_s("db.user.name"))
+        self.assertEqual(u("the-database-password-2"),
+                         cfg.getvar_s("db.user.pwd"))
+
+        tmpdir = cfg.getvar_s("tmpdir")
+        self.assertEqual(u(os.getcwd()) + u("/tmp\\4"), tmpdir)
+
+        self.assertEqual(u("3rd-host"),
+                         cfg.getvar_s("db.locinfo.ro.hostname"))
+        self.assertEqual(u("localhost"),
+                         cfg.getvar_s("db.locinfo.rw.hostname"))
+
+        self.assertEqual(5432, cfg.getvar_s("db.locinfo.ro.port"))
+
+        url = cfg.getvar_s("db.engines.ro.url")
+        self.assertEqual(
+            u("postgresql+psycopg2://the_database_user_2:the-database-password-2@3rd-host:5432/my_database_catalog"),
+            url)        
+
     def test03_namespace(self):
         cfg = self._load(
             os.path.join(TESTDATADIR, "conf20.yml"),