summaryrefslogtreecommitdiff
path: root/tests/test_cfg.py
diff options
context:
space:
mode:
authorMehdi Abaakouk <sileht@sileht.net>2014-09-10 15:29:08 +0200
committerMehdi Abaakouk <sileht@sileht.net>2014-09-10 16:58:29 +0200
commita50ea6f2827bedf95188442cfb50d2348cbb3194 (patch)
tree593bc7dfccdcb95e514a049dff50c563f115df5b /tests/test_cfg.py
parent83236b0d7dbdbaa5c2ebe73925ee0f1928d16aff (diff)
downloadoslo-config-a50ea6f2827bedf95188442cfb50d2348cbb3194.tar.gz
Looks for variable subtitution in the same group
When we do a variable subtitution we must try to look if the option is avialable into the same group and then into the default one for backward compatibilty. Otherwise variable subtitution doesn't works when we change the group of an option and deprecated the DEFAULT group. Change-Id: Ie5750ee028a58fba6da225a8c4b4221e23db829f Closes-bug: #1367790
Diffstat (limited to 'tests/test_cfg.py')
-rw-r--r--tests/test_cfg.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_cfg.py b/tests/test_cfg.py
index 7b6d282..dab7542 100644
--- a/tests/test_cfg.py
+++ b/tests/test_cfg.py
@@ -2101,8 +2101,55 @@ class TemplateSubstitutionTestCase(BaseTestCase):
self.assertTrue(hasattr(self.conf, 'ba'))
self.assertTrue(hasattr(self.conf.ba, 'r'))
+ self.assertEqual(self.conf.foo, '123')
self.assertEqual(self.conf.ba.r, 123)
+ def test_sub_group_from_default_deprecated(self):
+ self.conf.register_group(cfg.OptGroup('ba'))
+ self.conf.register_cli_opt(cfg.StrOpt(
+ 'foo', default='123', deprecated_group='DEFAULT'), group='ba')
+ self.conf.register_cli_opt(cfg.IntOpt('r', default='$foo'), group='ba')
+
+ self.conf([])
+
+ self.assertTrue(hasattr(self.conf, 'ba'))
+ self.assertTrue(hasattr(self.conf.ba, 'foo'))
+ self.assertEqual(self.conf.ba.foo, '123')
+ self.assertTrue(hasattr(self.conf.ba, 'r'))
+ self.assertEqual(self.conf.ba.r, 123)
+
+ def test_sub_group_from_args_deprecated(self):
+ self.conf.register_group(cfg.OptGroup('ba'))
+ self.conf.register_cli_opt(cfg.StrOpt(
+ 'foo', default='123', deprecated_group='DEFAULT'), group='ba')
+ self.conf.register_cli_opt(cfg.IntOpt('r', default='$foo'), group='ba')
+
+ self.conf(['--ba-foo=4242'])
+
+ self.assertTrue(hasattr(self.conf, 'ba'))
+ self.assertTrue(hasattr(self.conf.ba, 'foo'))
+ self.assertTrue(hasattr(self.conf.ba, 'r'))
+ self.assertEqual(self.conf.ba.foo, '4242')
+ self.assertEqual(self.conf.ba.r, 4242)
+
+ def test_sub_group_from_configfile_deprecated(self):
+ self.conf.register_group(cfg.OptGroup('ba'))
+ self.conf.register_cli_opt(cfg.StrOpt(
+ 'foo', default='123', deprecated_group='DEFAULT'), group='ba')
+ self.conf.register_cli_opt(cfg.IntOpt('r', default='$foo'), group='ba')
+
+ paths = self.create_tempfiles([('test',
+ '[DEFAULT]\n'
+ 'foo=4242\n')])
+
+ self.conf(['--config-file', paths[0]])
+
+ self.assertTrue(hasattr(self.conf, 'ba'))
+ self.assertTrue(hasattr(self.conf.ba, 'foo'))
+ self.assertTrue(hasattr(self.conf.ba, 'r'))
+ self.assertEqual(self.conf.ba.foo, '4242')
+ self.assertEqual(self.conf.ba.r, 4242)
+
class ConfigDirTestCase(BaseTestCase):