summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-06-18 19:58:15 +0000
committerGerrit Code Review <review@openstack.org>2014-06-18 19:58:15 +0000
commit582e1a39a57903472b3d99ce6293fda8e044c846 (patch)
tree8b88ddf8728e1934455212b5357e088f0efe4b04
parent782fd6e78e66c07992d5fd22891062a6851a8e1c (diff)
parent6dc86f2d678843b462c3f307d8df59e6dd18b3c5 (diff)
downloadoslo-config-582e1a39a57903472b3d99ce6293fda8e044c846.tar.gz
Merge "Add test case for hyphenated option names"
-rw-r--r--tests/test_cfg.py129
1 files changed, 128 insertions, 1 deletions
diff --git a/tests/test_cfg.py b/tests/test_cfg.py
index d979215..66ad67a 100644
--- a/tests/test_cfg.py
+++ b/tests/test_cfg.py
@@ -1,4 +1,4 @@
-# Copyright 2012 Red Hat, Inc.
+# Copyright 2014 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -1647,6 +1647,133 @@ class MappingInterfaceTestCase(BaseTestCase):
self.assertEqual(self.conf.blaa, self.conf['blaa'])
+class OptNameSeparatorTestCast(BaseTestCase):
+
+ scenarios = [
+ ('hyphen',
+ dict(opt_name='foo-bar',
+ opt_dest='foo_bar',
+ broken_opt_dest='foo-bar',
+ cf_name='foo_bar',
+ broken_cf_name='foo-bar',
+ cli_name='foo-bar',
+ broken_cli_name='foo_bar',
+ broken=True)), # FIXME(markmc): see #1279973
+ ('underscore',
+ dict(opt_name='foo_bar',
+ opt_dest='foo_bar',
+ broken_opt_dest='foo-bar',
+ cf_name='foo_bar',
+ broken_cf_name='foo-bar',
+ cli_name='foo_bar',
+ broken_cli_name='foo_bar',
+ broken=False)),
+ ]
+
+ def test_attribute_and_key_name(self):
+ self.conf.register_opt(cfg.StrOpt(self.opt_name))
+
+ self.assertTrue(hasattr(self.conf, self.opt_dest))
+ self.assertFalse(hasattr(self.conf, self.broken_opt_dest))
+ self.assertIn(self.opt_dest, self.conf)
+ self.assertNotIn(self.broken_opt_dest, self.conf)
+
+ def test_cli_opt_name(self):
+ self.conf.register_cli_opt(cfg.BoolOpt(self.opt_name))
+
+ self.conf(['--' + self.cli_name])
+
+ self.assertTrue(getattr(self.conf, self.opt_dest))
+
+ def test_config_file_opt_name(self):
+ self.conf.register_opt(cfg.BoolOpt(self.opt_name))
+
+ paths = self.create_tempfiles([('test',
+ '[DEFAULT]\n' +
+ self.cf_name + ' = True\n' +
+ self.broken_cf_name + ' = False\n')])
+
+ self.conf(['--config-file', paths[0]])
+
+ self.assertTrue(getattr(self.conf, self.opt_dest))
+
+ def test_deprecated_name(self):
+ self.conf.register_opt(cfg.StrOpt('foobar',
+ deprecated_name=self.opt_name))
+
+ self.assertTrue(hasattr(self.conf, 'foobar'))
+ self.assertFalse(hasattr(self.conf, self.opt_dest))
+ self.assertFalse(hasattr(self.conf, self.broken_opt_dest))
+ self.assertIn('foobar', self.conf)
+ self.assertNotIn(self.opt_dest, self.conf)
+ self.assertNotIn(self.broken_opt_dest, self.conf)
+
+ def test_deprecated_name_cli(self):
+ self.conf.register_cli_opt(cfg.BoolOpt('foobar',
+ deprecated_name=self.opt_name))
+
+ # FIXME(markmc): this should be self.cli_name, see #1279973
+ if self.broken:
+ self.conf(['--' + self.broken_cli_name])
+ else:
+ self.conf(['--' + self.cli_name])
+
+ self.assertTrue(self.conf.foobar)
+
+ def test_deprecated_name_config_file(self):
+ self.conf.register_opt(cfg.BoolOpt('foobar',
+ deprecated_name=self.opt_name))
+
+ paths = self.create_tempfiles([('test',
+ '[DEFAULT]\n' +
+ self.cf_name + ' = True\n')])
+
+ self.conf(['--config-file', paths[0]])
+
+ self.assertTrue(self.conf.foobar)
+
+ def test_deprecated_opts(self):
+ oldopts = [cfg.DeprecatedOpt(self.opt_name)]
+ self.conf.register_opt(cfg.StrOpt('foobar',
+ deprecated_opts=oldopts))
+
+ self.assertTrue(hasattr(self.conf, 'foobar'))
+ self.assertFalse(hasattr(self.conf, self.opt_dest))
+ self.assertFalse(hasattr(self.conf, self.broken_opt_dest))
+ self.assertIn('foobar', self.conf)
+ self.assertNotIn(self.opt_dest, self.conf)
+ self.assertNotIn(self.broken_opt_dest, self.conf)
+
+ def test_deprecated_opts_cli(self):
+ oldopts = [cfg.DeprecatedOpt(self.opt_name)]
+ self.conf.register_cli_opt(cfg.BoolOpt('foobar',
+ deprecated_opts=oldopts))
+
+ self.conf(['--' + self.cli_name])
+
+ self.assertTrue(self.conf.foobar)
+
+ def test_deprecated_opts_config_file(self):
+ oldopts = [cfg.DeprecatedOpt(self.opt_name)]
+ self.conf.register_opt(cfg.BoolOpt('foobar',
+ deprecated_opts=oldopts))
+
+ # FIXME(markmc): this should be self.cf_name, see #1279973
+ if self.broken:
+ paths = self.create_tempfiles([('test',
+ '[DEFAULT]\n' +
+ self.broken_cf_name +
+ ' = True\n')])
+ else:
+ paths = self.create_tempfiles([('test',
+ '[DEFAULT]\n' +
+ self.cf_name + ' = True\n')])
+
+ self.conf(['--config-file', paths[0]])
+
+ self.assertTrue(self.conf.foobar)
+
+
class ReRegisterOptTestCase(BaseTestCase):
def test_conf_file_re_register_opt(self):