summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2014-06-15 15:23:08 +0100
committerMark McLoughlin <markmc@redhat.com>2014-06-15 15:24:10 +0100
commit6dc86f2d678843b462c3f307d8df59e6dd18b3c5 (patch)
treefbbe1f02c73c7657cfbbebdbba38205ea997c6b4
parent1746fd2908bec7dd215d06667c615174237809cc (diff)
downloadoslo-config-6dc86f2d678843b462c3f307d8df59e6dd18b3c5.tar.gz
Add test case for hyphenated option names
Add some tests to show the broken behaviour in #127993 and to help ensure that fixing it doesn't break correct behaviour in other places. Related-Bug: #1279973 Change-Id: I69b2c4e3f27a3e193ca10cef32dd752d6a6fcc8b
-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):