def test_getitem(self): d = OrderedDictWithDefaults() d['name'] = 'Joseph' d.defaults_ = { 'surname': 'Wyndham' } self.assertEqual('Joseph', d['name']) self.assertEqual('Wyndham', d['surname'])
def test_contains(self): d = OrderedDictWithDefaults() self.assertEqual([], list(d.items())) d['key'] = 'Birds' d.defaults_ = {'value': '10'} self.assertTrue('key' in d) self.assertTrue('value' in d) self.assertFalse('test' in d)
def test_getitem(self): d = OrderedDictWithDefaults() d['name'] = 'Joseph' d.defaults_ = { 'surname': 'Wyndham' } self.assertEqual('Joseph', d['name']) self.assertEqual('Wyndham', d['surname'])
def test_keys(self): d = OrderedDictWithDefaults() d['name'] = 'Andrew' d['surname'] = 'Gray' d.defaults_ = {'address': 'N/A'} keys = list(d.keys()) self.assertTrue(len(keys) == 3) self.assertTrue('name' in keys) self.assertTrue('surname' in keys) self.assertTrue('address' in keys)
def test_contains(self): d = OrderedDictWithDefaults() self.assertEqual([], list(d.items())) d['key'] = 'Birds' d.defaults_ = { 'value': '10' } self.assertTrue('key' in d) self.assertTrue('value' in d) self.assertFalse('test' in d)
def test_itervalues(self): d = OrderedDictWithDefaults() self.assertEqual([], list(d.items())) d['key'] = 'Birds' d['len'] = '89' d.defaults_ = {'surname': 'Wyndham'} count = 0 for k in d.values(): self.assertTrue(k in ['Birds', '89', 'Wyndham']) count += 1 self.assertEqual(3, count)
def test_keys(self): d = OrderedDictWithDefaults() d['name'] = 'Andrew' d['surname'] = 'Gray' d.defaults_ = { 'address': 'N/A' } keys = list(d.keys()) self.assertTrue(len(keys) == 3) self.assertTrue('name' in keys) self.assertTrue('surname' in keys) self.assertTrue('address' in keys)
def replicate(target, source): """Replicate source *into* target. Source elements need not exist in target already, so source overrides common elements in target and otherwise adds elements to it. """ if not source: target = OrderedDictWithDefaults() return if hasattr(source, "defaults_"): target.defaults_ = pdeepcopy(source.defaults_) for key, val in source.items(): if isinstance(val, dict): if key not in target: target[key] = OrderedDictWithDefaults() if hasattr(val, 'defaults_'): target[key].defaults_ = pdeepcopy(val.defaults_) replicate(target[key], val) elif isinstance(val, list): target[key] = val[:] else: target[key] = val
def replicate( target, source ): """ Replicate source *into* target. Source elements need not exist in target already, so source overrides common elements in target and otherwise adds elements to it. """ if not source: target = OrderedDictWithDefaults() return if hasattr(source, "defaults_"): target.defaults_ = pdeepcopy(source.defaults_) for key,val in source.items(): if isinstance( val, dict ): if key not in target: target[key] = OrderedDictWithDefaults() if hasattr(val, 'defaults_'): target[key].defaults_ = pdeepcopy(val.defaults_) replicate( target[key], val ) elif isinstance( val, list ): target[key] = val[:] else: target[key] = val
def test_itervalues(self): d = OrderedDictWithDefaults() self.assertEqual([], list(d.items())) d['key'] = 'Birds' d['len'] = '89' d.defaults_ = { 'surname': 'Wyndham' } count = 0 for k in d.values(): self.assertTrue(k in ['Birds', '89', 'Wyndham']) count += 1 self.assertEqual(3, count)