def __init__(self, app, **kwargs): self.app = app self.config = dict2() self.config.update(self.__default_config__) self.config.update(kwargs) self.init(self.config)
def test_set_get(self): a = dict2() a.a = 10 a.b.c = 20 a.x = {'y': 30} self.assertEqual(a.a, 10) self.assertEqual(a.b.c, 20) self.assertEqual(a.x.y, 30)
def test_for_coverage_completion(self): # Sorry, these tests are a bit silly ;) a = dict2() self.assertEqual(repr(a), 'dict2({})') a.__something__ = 100 self.assertEqual(a.__something__, 100) self.assertNotIn('__something__', a) with self.assertRaises(AttributeError): print(a.__something_else__)
def test_set_get(self): obj = dict2() obj.a = 100 self.assertEqual(obj.a, 100) obj.b.c = 3.14 self.assertEqual(obj.b, {'c': 3.14}) self.assertEqual(obj.get_property('b.c'), 3.14) self.assertEqual(obj.get_property('b.a'), None) obj.c = {'hello': 'world'} self.assertEqual(obj.c.hello, 'world')
def test_update(self): obj = { 'a': 100, 'b': 'Hello', 'c': [{ 'a': 3.14 }, 'World'], 'd': { 'a': ['test'], 'b': { 'a': 6.28, 'b': [1, 2] } } } obj2 = dict2(d={}) obj2.update(obj) self.assertEqual(obj, obj2)
def test_dummy(self): obj = dict2() self.assertIn('dict2', repr(obj))
def test_get_set(self): d = dict2() d.a = 100 self.assertEqual(d.a, 100) d.b.a = 100 self.assertEqual(d.b.a, 100)
from drongo.utils import dict2 import pickle DEFAULT = pickle.dumps(dict2())