class Test(unittest.TestCase): def setUp(self): self.obj = PropertyObject({ 'name': 'cola', 'list': [ { 'count': 1 }, { 'count': 2 }, ] }) def testPropertyObject(self): assert 'name' in self.obj assert self.obj['name'] == 'cola' assert self.obj.name == 'cola' assert isinstance(self.obj.list, list) assert self.obj.list[0].count == 1 self.obj.update(**{'list': [ { 'count': 3 }, ]}) assert self.obj.name == 'cola' assert self.obj.list[2].count == 3 def testPickle(self): c = pickle.dumps(main_conf) new_conf = pickle.loads(c) self.assertEqual(new_conf.master.port, 11103)
class Test(unittest.TestCase): def setUp(self): self.obj = PropertyObject({ 'name': 'cola', 'list': [ { 'count': 1 }, { 'count': 2 }, ] }) def testPropertyObject(self): assert 'name' in self.obj assert self.obj['name'] == 'cola' assert self.obj.name == 'cola' assert isinstance(self.obj.list, list) assert self.obj.list[0].count == 1 self.obj.update(**{'list': [{'count': 3}, ]}) assert self.obj.name == 'cola' assert self.obj.list[2].count == 3 def testPickle(self): c = pickle.dumps(main_conf) new_conf = pickle.loads(c) self.assertEqual(new_conf.master.port, 11103)
def __init__(self, user_conf=None, **user_defines): self.main_conf = main_conf if user_conf is not None: if isinstance(user_conf, str): self.user_conf = Config(user_conf) else: self.user_conf = user_conf else: self.user_conf = PropertyObject(dict()) self.user_defines = PropertyObject(user_defines) dicts = PropertyObject({}) for obj in (self.main_conf, self.user_conf, self.user_defines): dicts.update(obj) for k in dicts: if not k.startswith('_'): setattr(self, k, getattr(dicts, k))