summaryrefslogtreecommitdiff
path: root/test/test_config.py
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2016-08-27 18:46:56 +0200
committerMarcel Hellkamp <marc@gsites.de>2016-08-27 18:48:18 +0200
commit12445eb24194a77ec2dd448de055edee23dbc514 (patch)
tree433c3ce91fb3b1c9bbabd3cc1c97e56a53233b56 /test/test_config.py
parentb255427a879fa7511a8c5b881485d65914617633 (diff)
downloadbottle-12445eb24194a77ec2dd448de055edee23dbc514.tar.gz
Improved ConfigDict.load_config() documentation and functionality.
The issue #784 criticized that values under the [DEFAULT] section are injected into all other sections while the documentation states that these values are only injected into the root namespace. The actual behavior is correct and the documentation was wrong. See configparser.ConfigParser() documentation for the exact behavior. There is no easy way to change this behavior. This patch: - fixes #784: ConfigDict.load_config() and 'DEFAULT' sections. - Improves documentation. - Enables extended value string interpolation for Python 3. - Enables empty (none) values. - Enables customisation by passing configparser.ConfigParser() parameters to ConfigDict.load_config() - Introduces the special [ROOT] section as an replacement for [DEFAULT].
Diffstat (limited to 'test/test_config.py')
-rw-r--r--test/test_config.py44
1 files changed, 42 insertions, 2 deletions
diff --git a/test/test_config.py b/test/test_config.py
index 6dbcc0e..25525a6 100644
--- a/test/test_config.py
+++ b/test/test_config.py
@@ -1,9 +1,14 @@
+import os
import sys
+import tempfile
import unittest
+
+import functools
+
from bottle import ConfigDict
+
class TestConfDict(unittest.TestCase):
-
def test_isadict(self):
""" ConfigDict should behaves like a normal dict. """
# It is a dict-subclass, so this kind of pointless, but it doen't hurt.
@@ -47,7 +52,7 @@ class TestConfDict(unittest.TestCase):
c.meta_set('bool', 'filter', bool)
c.meta_set('int', 'filter', int)
c['bool'] = 'I am so true!'
- c['int'] = '6'
+ c['int'] = '6'
self.assertTrue(c['bool'] is True)
self.assertEqual(c['int'], 6)
self.assertRaises(ValueError, lambda: c.update(int='not an int'))
@@ -128,3 +133,38 @@ class TestConfDict(unittest.TestCase):
del fallback['key2']
self.assertTrue('key2' not in primary)
self.assertTrue('key2' not in fallback)
+
+
+class TestINIConfigLoader(unittest.TestCase):
+ @classmethod
+ def setUpClass(self):
+ self.config_file = tempfile.NamedTemporaryFile(suffix='.example.ini',
+ delete=True)
+ self.config_file.write(b'[DEFAULT]\n'
+ b'default: 45\n'
+ b'[bottle]\n'
+ b'port = 8080\n'
+ b'[ROOT]\n'
+ b'namespace.key = test\n'
+ b'[NameSpace.Section]\n'
+ b'sub.namespace.key = test2\n'
+ b'default = otherDefault\n'
+ b'[compression]\n'
+ b'status=single\n')
+ self.config_file.flush()
+
+ @classmethod
+ def tearDownClass(self):
+ self.config_file.close()
+
+ def test_load_config(self):
+ c = ConfigDict()
+ c.load_config(self.config_file.name)
+ self.assertDictEqual({
+ 'compression.default': '45',
+ 'compression.status': 'single',
+ 'default': '45',
+ 'namespace.key': 'test',
+ 'namespace.section.default': 'otherDefault',
+ 'namespace.section.sub.namespace.key': 'test2',
+ 'port': '8080'}, c)