summaryrefslogtreecommitdiff
path: root/test/test_config.py
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2014-09-18 20:46:02 +0200
committerMarcel Hellkamp <marc@gsites.de>2014-09-18 20:46:02 +0200
commit58b64c5b2ae998281d35ce088ca1530bd0acacc7 (patch)
treebd01741ae7f65d10ed7394d79deb439fefecc121 /test/test_config.py
parent622ee60d09b63e336bf5f607937f3dfc5aaa71a0 (diff)
downloadbottle-58b64c5b2ae998281d35ce088ca1530bd0acacc7.tar.gz
Added lots of ConfigDict features.config-fancy
Diffstat (limited to 'test/test_config.py')
-rw-r--r--test/test_config.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/test/test_config.py b/test/test_config.py
index e953f84..3a4717b 100644
--- a/test/test_config.py
+++ b/test/test_config.py
@@ -1,5 +1,5 @@
import unittest
-from bottle import ConfigDict
+from bottle import ConfigDict, tob, touni
class TestConfDict(unittest.TestCase):
@@ -29,6 +29,28 @@ class TestConfDict(unittest.TestCase):
c['key'] = 'value2'
self.assertEqual(c['key'], 'value2')
+ def test_save_types(self):
+ """ Types that are considered save (immutable) are stored as is
+ (but may still be copied). """
+ c = ConfigDict()
+ for value in (True, False,
+ 1, -1024, 0.5,
+ tob('abc'), touni('abc'),
+ (1,2,3), frozenset([3,4,5]),
+ (1,2,3,(4,5),'6', frozenset([3,(4,5),6]))):
+ c['key'] = value
+ self.assertEquals(c['key'], value)
+
+ def test_immutable_values(self):
+ """ Config values must be immutable. For some types (list, set) we do this
+ automagically, even for nested structures. For others, we don't. """
+ c = ConfigDict()
+ c['key'] = [1,2,set([3,4]),5, '6']
+ self.assertEquals(c['key'], (1,2,frozenset([3,4]),5, '6'))
+ self.assertRaises(TypeError, c.__setitem__, 'key', dict())
+ self.assertRaises(TypeError, c.__setitem__, 'key', ['a', {}])
+ self.assertRaises(TypeError, c.__setitem__, 'key', ('a', {}))
+
def test_update(self):
c = ConfigDict()
c['key'] = 'value'