##// END OF EJS Templates
copy values in Config.merge
MinRK -
Show More
@@ -200,14 +200,14 class Config(dict):
200 to_update = {}
200 to_update = {}
201 for k, v in iteritems(other):
201 for k, v in iteritems(other):
202 if k not in self:
202 if k not in self:
203 to_update[k] = v
203 to_update[k] = copy.deepcopy(v)
204 else: # I have this key
204 else: # I have this key
205 if isinstance(v, Config) and isinstance(self[k], Config):
205 if isinstance(v, Config) and isinstance(self[k], Config):
206 # Recursively merge common sub Configs
206 # Recursively merge common sub Configs
207 self[k].merge(v)
207 self[k].merge(v)
208 else:
208 else:
209 # Plain updates for non-Configs
209 # Plain updates for non-Configs
210 to_update[k] = v
210 to_update[k] = copy.deepcopy(v)
211
211
212 self.update(to_update)
212 self.update(to_update)
213
213
@@ -357,4 +357,19 class TestConfigContainers(TestCase):
357 obj = Containers(config=c)
357 obj = Containers(config=c)
358 self.assertEqual(obj.d, {'a':'b', 'c':'d', 'e':'f'})
358 self.assertEqual(obj.d, {'a':'b', 'c':'d', 'e':'f'})
359
359
360 def test_update_twice(self):
361 c = Config()
362 c.MyConfigurable.a = 5
363 m = MyConfigurable(config=c)
364 self.assertEqual(m.a, 5)
365
366 c2 = Config()
367 c2.MyConfigurable.a = 10
368 m.update_config(c2)
369 self.assertEqual(m.a, 10)
370
371 c2.MyConfigurable.a = 15
372 m.update_config(c2)
373 self.assertEqual(m.a, 15)
374
360
375
@@ -324,4 +324,14 class TestConfig(TestCase):
324 foo = cfg['foo']
324 foo = cfg['foo']
325 assert isinstance(foo, LazyConfigValue)
325 assert isinstance(foo, LazyConfigValue)
326 self.assertIn('foo', cfg)
326 self.assertIn('foo', cfg)
327
328 def test_merge_copies(self):
329 c = Config()
330 c2 = Config()
331 c2.Foo.trait = []
332 c.merge(c2)
333 c2.Foo.trait.append(1)
334 self.assertIsNot(c.Foo, c2.Foo)
335 self.assertEqual(c.Foo.trait, [])
336 self.assertEqual(c2.Foo.trait, [1])
327
337
General Comments 0
You need to be logged in to leave comments. Login now