Merge pull request #37279 from gtmanfred/2016.3

initialize super class of NamespacedDictWrapper
This commit is contained in:
Thomas S Hatch 2016-11-01 09:12:49 -06:00 committed by GitHub
commit 1a4833b3a1
2 changed files with 12 additions and 0 deletions

View File

@ -170,6 +170,7 @@ class NamespacedDictWrapper(collections.MutableMapping, dict):
self.pre_keys = (pre_keys,)
else:
self.pre_keys = pre_keys
super(NamespacedDictWrapper, self).__init__(self._dict())
def _dict(self):
r = self.__dict

View File

@ -5,6 +5,7 @@
'''
# Import python libs
from __future__ import absolute_import
import json
import tornado.stack_context
import tornado.gen
from tornado.testing import AsyncTestCase, gen_test
@ -185,3 +186,13 @@ class NamespacedDictWrapperTests(TestCase):
self._dict['prefix'] = {'foo': {'bar': 'baz'}}
w = NamespacedDictWrapper(self._dict, ('prefix', 'foo'))
self.assertEqual(w['bar'], 'baz')
def test_json_dumps_single_key(self):
self._dict['prefix'] = {'foo': {'bar': 'baz'}}
w = NamespacedDictWrapper(self._dict, 'prefix')
self.assertEqual(json.dumps(w), '{"foo": {"bar": "baz"}}')
def test_json_dumps_multiple_key(self):
self._dict['prefix'] = {'foo': {'bar': 'baz'}}
w = NamespacedDictWrapper(self._dict, ('prefix', 'foo'))
self.assertEqual(json.dumps(w), '{"bar": "baz"}')