summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2013-02-17 15:22:44 +0000
committerMark McLoughlin <markmc@redhat.com>2013-02-17 15:44:00 +0000
commitf63ea05f7c36ece6aad0fdc8e02f4d5d30c673a3 (patch)
treefc46499db82de0829e1137b1d620bceb46cb787f /tests
parent8ce59472653439d646309395bf195ec6163ff29a (diff)
downloadoslo-f63ea05f7c36ece6aad0fdc8e02f4d5d30c673a3.tar.gz
oslo-f63ea05f7c36ece6aad0fdc8e02f4d5d30c673a3.tar.xz
oslo-f63ea05f7c36ece6aad0fdc8e02f4d5d30c673a3.zip
Use oslo-config-2013.1b3
The cfg API is now available via the oslo-config library, so switch to it and remove the copied-and-pasted version. Add the 2013.1b3 tarball to tools/pip-requires - this will be changed to 'oslo-config>=2013.1' when oslo-config is published to pypi. This will happen in time for grizzly final. Remove the 'deps = pep8==1.3.3' and 'deps = pyflakes' from tox.ini as it means all the other deps get installed with easy_install which can't install oslo-config from the URL. Change-Id: I4815aeb8a9341a31a250e920157f15ee15cfc5bc
Diffstat (limited to 'tests')
-rw-r--r--tests/testmods/bar_foo_opt.py2
-rw-r--r--tests/testmods/baz_qux_opt.py2
-rw-r--r--tests/testmods/blaa_opt.py2
-rw-r--r--tests/unit/rpc/common.py2
-rw-r--r--tests/unit/rpc/test_common.py3
-rw-r--r--tests/unit/rpc/test_fake.py3
-rw-r--r--tests/unit/rpc/test_kombu.py2
-rw-r--r--tests/unit/rpc/test_kombu_ssl.py3
-rw-r--r--tests/unit/rpc/test_qpid.py2
-rw-r--r--tests/unit/rpc/test_zmq.py2
-rw-r--r--tests/unit/test_cfg.py1785
-rw-r--r--tests/unit/test_deprecated.py3
-rw-r--r--tests/unit/test_iniparser.py127
-rw-r--r--tests/unit/test_log.py3
-rw-r--r--tests/unit/test_notifier.py3
-rw-r--r--tests/unit/test_plugin.py3
-rw-r--r--tests/unit/test_service.py2
-rw-r--r--tests/unit/test_version.py3
-rw-r--r--tests/unit/test_wsgi.py7
-rw-r--r--tests/utils.py2
20 files changed, 29 insertions, 1932 deletions
diff --git a/tests/testmods/bar_foo_opt.py b/tests/testmods/bar_foo_opt.py
index 88d0bbf..0057f11 100644
--- a/tests/testmods/bar_foo_opt.py
+++ b/tests/testmods/bar_foo_opt.py
@@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstack.common import cfg
+from oslo.config import cfg
CONF = cfg.CONF
diff --git a/tests/testmods/baz_qux_opt.py b/tests/testmods/baz_qux_opt.py
index b2c7ecb..c9814ea 100644
--- a/tests/testmods/baz_qux_opt.py
+++ b/tests/testmods/baz_qux_opt.py
@@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstack.common import cfg
+from oslo.config import cfg
CONF = cfg.CONF
diff --git a/tests/testmods/blaa_opt.py b/tests/testmods/blaa_opt.py
index b320a72..a7b06b2 100644
--- a/tests/testmods/blaa_opt.py
+++ b/tests/testmods/blaa_opt.py
@@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstack.common import cfg
+from oslo.config import cfg
CONF = cfg.CONF
diff --git a/tests/unit/rpc/common.py b/tests/unit/rpc/common.py
index 2d1e2b6..5a655c6 100644
--- a/tests/unit/rpc/common.py
+++ b/tests/unit/rpc/common.py
@@ -24,8 +24,8 @@ import time
import eventlet
from eventlet import greenthread
+from oslo.config import cfg
-from openstack.common import cfg
from openstack.common import exception
from openstack.common.gettextutils import _
from openstack.common import jsonutils
diff --git a/tests/unit/rpc/test_common.py b/tests/unit/rpc/test_common.py
index fd59929..976da84 100644
--- a/tests/unit/rpc/test_common.py
+++ b/tests/unit/rpc/test_common.py
@@ -20,7 +20,8 @@ Unit Tests for 'common' functons used through rpc code.
import logging
import sys
-from openstack.common import cfg
+from oslo.config import cfg
+
from openstack.common import exception
from openstack.common import importutils
from openstack.common import jsonutils
diff --git a/tests/unit/rpc/test_fake.py b/tests/unit/rpc/test_fake.py
index 17e4a68..a38250b 100644
--- a/tests/unit/rpc/test_fake.py
+++ b/tests/unit/rpc/test_fake.py
@@ -22,7 +22,8 @@ Unit Tests for remote procedure calls using fake_impl
import eventlet
eventlet.monkey_patch()
-from openstack.common import cfg
+from oslo.config import cfg
+
from openstack.common import rpc
from openstack.common.rpc import impl_fake
from tests.unit.rpc import common
diff --git a/tests/unit/rpc/test_kombu.py b/tests/unit/rpc/test_kombu.py
index 1bd23d5..cadb630 100644
--- a/tests/unit/rpc/test_kombu.py
+++ b/tests/unit/rpc/test_kombu.py
@@ -27,8 +27,8 @@ import logging
import time
import mock
+from oslo.config import cfg
-from openstack.common import cfg
from openstack.common import exception
from openstack.common.rpc import amqp as rpc_amqp
from openstack.common.rpc import common as rpc_common
diff --git a/tests/unit/rpc/test_kombu_ssl.py b/tests/unit/rpc/test_kombu_ssl.py
index 5507f91..688c992 100644
--- a/tests/unit/rpc/test_kombu_ssl.py
+++ b/tests/unit/rpc/test_kombu_ssl.py
@@ -22,7 +22,8 @@ Unit Tests for remote procedure calls using kombu + ssl
import eventlet
eventlet.monkey_patch()
-from openstack.common import cfg
+from oslo.config import cfg
+
from tests import utils as test_utils
diff --git a/tests/unit/rpc/test_qpid.py b/tests/unit/rpc/test_qpid.py
index 016c5b9..ea68b47 100644
--- a/tests/unit/rpc/test_qpid.py
+++ b/tests/unit/rpc/test_qpid.py
@@ -29,8 +29,8 @@ import fixtures
import time
import testtools
import mox
+from oslo.config import cfg
-from openstack.common import cfg
from openstack.common import context
from openstack.common.rpc import amqp as rpc_amqp
from tests import utils
diff --git a/tests/unit/rpc/test_zmq.py b/tests/unit/rpc/test_zmq.py
index 1de78e7..8c9a966 100644
--- a/tests/unit/rpc/test_zmq.py
+++ b/tests/unit/rpc/test_zmq.py
@@ -26,8 +26,8 @@ import os
import socket
import fixtures
+from oslo.config import cfg
-from openstack.common import cfg
from openstack.common import exception
from openstack.common.gettextutils import _
from openstack.common import processutils
diff --git a/tests/unit/test_cfg.py b/tests/unit/test_cfg.py
deleted file mode 100644
index 7b6123c..0000000
--- a/tests/unit/test_cfg.py
+++ /dev/null
@@ -1,1785 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 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
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import os
-import shutil
-import StringIO
-import sys
-import tempfile
-
-import fixtures
-
-from openstack.common.cfg import *
-from tests import utils
-
-
-class ExceptionsTestCase(utils.BaseTestCase):
-
- def test_error(self):
- msg = str(Error('foobar'))
- self.assertEquals(msg, 'foobar')
-
- def test_args_already_parsed_error(self):
- msg = str(ArgsAlreadyParsedError('foobar'))
- self.assertEquals(msg, 'arguments already parsed: foobar')
-
- def test_no_such_opt_error(self):
- msg = str(NoSuchOptError('foo'))
- self.assertEquals(msg, 'no such option: foo')
-
- def test_no_such_opt_error_with_group(self):
- msg = str(NoSuchOptError('foo', OptGroup('bar')))
- self.assertEquals(msg, 'no such option in group bar: foo')
-
- def test_no_such_group_error(self):
- msg = str(NoSuchGroupError('bar'))
- self.assertEquals(msg, 'no such group: bar')
-
- def test_duplicate_opt_error(self):
- msg = str(DuplicateOptError('foo'))
- self.assertEquals(msg, 'duplicate option: foo')
-
- def test_required_opt_error(self):
- msg = str(RequiredOptError('foo'))
- self.assertEquals(msg, 'value required for option: foo')
-
- def test_required_opt_error_with_group(self):
- msg = str(RequiredOptError('foo', OptGroup('bar')))
- self.assertEquals(msg, 'value required for option: bar.foo')
-
- def test_template_substitution_error(self):
- msg = str(TemplateSubstitutionError('foobar'))
- self.assertEquals(msg, 'template substitution error: foobar')
-
- def test_config_files_not_found_error(self):
- msg = str(ConfigFilesNotFoundError(['foo', 'bar']))
- self.assertEquals(msg, 'Failed to read some config files: foo,bar')
-
- def test_config_file_parse_error(self):
- msg = str(ConfigFileParseError('foo', 'foobar'))
- self.assertEquals(msg, 'Failed to parse foo: foobar')
-
-
-class BaseTestCase(utils.BaseTestCase):
-
- class TestConfigOpts(ConfigOpts):
- def __call__(self, args=None):
- return ConfigOpts.__call__(self,
- args=args,
- prog='test',
- version='1.0',
- usage='%(prog)s FOO BAR',
- default_config_files=[])
-
- def setUp(self):
- super(BaseTestCase, self).setUp()
- self.useFixture(fixtures.NestedTempfile())
- self.conf = self.TestConfigOpts()
-
- self.tempdirs = []
-
- def create_tempfiles(self, files, ext='.conf'):
- tempfiles = []
- for (basename, contents) in files:
- if not os.path.isabs(basename):
- (fd, path) = tempfile.mkstemp(prefix=basename, suffix=ext)
- else:
- path = basename + ext
- fd = os.open(path, os.O_CREAT | os.O_WRONLY)
- tempfiles.append(path)
- try:
- os.write(fd, contents)
- finally:
- os.close(fd)
- return tempfiles
-
-
-class UsageTestCase(BaseTestCase):
-
- def test_print_usage(self):
- f = StringIO.StringIO()
- self.conf([])
- self.conf.print_usage(file=f)
- self.assertTrue('usage: test FOO BAR' in f.getvalue())
- self.assertTrue('optional:' not in f.getvalue())
-
-
-class HelpTestCase(BaseTestCase):
-
- def test_print_help(self):
- f = StringIO.StringIO()
- self.conf([])
- self.conf.print_help(file=f)
- self.assertTrue('usage: test FOO BAR' in f.getvalue())
- self.assertTrue('optional' in f.getvalue())
- self.assertTrue('-h, --help' in f.getvalue())
-
-
-class FindConfigFilesTestCase(BaseTestCase):
-
- def test_find_config_files(self):
- config_files = [os.path.expanduser('~/.blaa/blaa.conf'),
- '/etc/foo.conf']
-
- self.stubs.Set(sys, 'argv', ['foo'])
- self.stubs.Set(os.path, 'exists', lambda p: p in config_files)
-
- self.assertEquals(find_config_files(project='blaa'), config_files)
-
- def test_find_config_files_with_extension(self):
- config_files = ['/etc/foo.json']
-
- self.stubs.Set(sys, 'argv', ['foo'])
- self.stubs.Set(os.path, 'exists', lambda p: p in config_files)
-
- self.assertEquals(find_config_files(project='blaa'), [])
- self.assertEquals(find_config_files(project='blaa', extension='.json'),
- config_files)
-
-
-class CliOptsTestCase(BaseTestCase):
-
- def _do_cli_test(self, opt_class, default, cli_args, value):
- self.conf.register_cli_opt(opt_class('foo', default=default,
- deprecated_name='oldfoo'))
-
- self.conf(cli_args)
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, value)
-
- def test_str_default(self):
- self._do_cli_test(StrOpt, None, [], None)
-
- def test_str_arg(self):
- self._do_cli_test(StrOpt, None, ['--foo', 'bar'], 'bar')
-
- def test_str_arg_deprecated(self):
- self._do_cli_test(StrOpt, None, ['--oldfoo', 'bar'], 'bar')
-
- def test_bool_default(self):
- self._do_cli_test(BoolOpt, False, [], False)
-
- def test_bool_arg(self):
- self._do_cli_test(BoolOpt, None, ['--foo'], True)
-
- def test_bool_arg_deprecated(self):
- self._do_cli_test(BoolOpt, None, ['--oldfoo'], True)
-
- def test_bool_arg_inverse(self):
- self._do_cli_test(BoolOpt, None, ['--foo', '--nofoo'], False)
-
- def test_bool_arg_inverse_deprecated(self):
- self._do_cli_test(BoolOpt, None, ['--oldfoo', '--nooldfoo'], False)
-
- def test_int_default(self):
- self._do_cli_test(IntOpt, 10, [], 10)
-
- def test_int_arg(self):
- self._do_cli_test(IntOpt, None, ['--foo=20'], 20)
-
- def test_int_arg_deprecated(self):
- self._do_cli_test(IntOpt, None, ['--oldfoo=20'], 20)
-
- def test_float_default(self):
- self._do_cli_test(FloatOpt, 1.0, [], 1.0)
-
- def test_float_arg(self):
- self._do_cli_test(FloatOpt, None, ['--foo', '2.0'], 2.0)
-
- def test_float_arg_deprecated(self):
- self._do_cli_test(FloatOpt, None, ['--oldfoo', '2.0'], 2.0)
-
- def test_list_default(self):
- self._do_cli_test(ListOpt, ['bar'], [], ['bar'])
-
- def test_list_arg(self):
- self._do_cli_test(ListOpt, None,
- ['--foo', 'blaa,bar'], ['blaa', 'bar'])
-
- def test_list_arg_with_spaces(self):
- self._do_cli_test(ListOpt, None,
- ['--foo', 'blaa ,bar'], ['blaa', 'bar'])
-
- def test_list_arg_deprecated(self):
- self._do_cli_test(ListOpt, None,
- ['--oldfoo', 'blaa,bar'], ['blaa', 'bar'])
-
- def test_multistr_default(self):
- self._do_cli_test(MultiStrOpt, ['bar'], [], ['bar'])
-
- def test_multistr_arg(self):
- self._do_cli_test(MultiStrOpt, None,
- ['--foo', 'blaa', '--foo', 'bar'], ['blaa', 'bar'])
-
- def test_multistr_arg_deprecated(self):
- self._do_cli_test(MultiStrOpt, None,
- ['--oldfoo', 'blaa', '--oldfoo', 'bar'],
- ['blaa', 'bar'])
-
- def test_help(self):
- self.stubs.Set(sys, 'stdout', StringIO.StringIO())
- self.assertRaises(SystemExit, self.conf, ['--help'])
- self.assertTrue('FOO BAR' in sys.stdout.getvalue())
- self.assertTrue('--version' in sys.stdout.getvalue())
- self.assertTrue('--help' in sys.stdout.getvalue())
- self.assertTrue('--config-file' in sys.stdout.getvalue())
-
- def test_version(self):
- self.stubs.Set(sys, 'stderr', StringIO.StringIO())
- self.assertRaises(SystemExit, self.conf, ['--version'])
- self.assertTrue('1.0' in sys.stderr.getvalue())
-
- def test_config_file(self):
- paths = self.create_tempfiles([('1', '[DEFAULT]'),
- ('2', '[DEFAULT]')])
-
- self.conf(['--config-file', paths[0], '--config-file', paths[1]])
-
- self.assertEquals(self.conf.config_file, paths)
-
-
-class PositionalTestCase(BaseTestCase):
-
- def _do_pos_test(self, opt_class, default, cli_args, value):
- self.conf.register_cli_opt(opt_class('foo',
- default=default,
- positional=True))
-
- self.conf(cli_args)
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, value)
-
- def test_positional_str_default(self):
- self._do_pos_test(StrOpt, None, [], None)
-
- def test_positional_str_arg(self):
- self._do_pos_test(StrOpt, None, ['bar'], 'bar')
-
- def test_positional_int_default(self):
- self._do_pos_test(IntOpt, 10, [], 10)
-
- def test_positional_int_arg(self):
- self._do_pos_test(IntOpt, None, ['20'], 20)
-
- def test_positional_float_default(self):
- self._do_pos_test(FloatOpt, 1.0, [], 1.0)
-
- def test_positional_float_arg(self):
- self._do_pos_test(FloatOpt, None, ['2.0'], 2.0)
-
- def test_positional_list_default(self):
- self._do_pos_test(ListOpt, ['bar'], [], ['bar'])
-
- def test_positional_list_arg(self):
- self._do_pos_test(ListOpt, None,
- ['blaa,bar'], ['blaa', 'bar'])
-
- def test_positional_multistr_default(self):
- self._do_pos_test(MultiStrOpt, ['bar'], [], ['bar'])
-
- def test_positional_multistr_arg(self):
- self._do_pos_test(MultiStrOpt, None,
- ['blaa', 'bar'], ['blaa', 'bar'])
-
- def test_positional_bool(self):
- self.assertRaises(ValueError, BoolOpt, 'foo', positional=True)
-
- def test_required_positional_opt(self):
- self.conf.register_cli_opt(StrOpt('foo',
- required=True,
- positional=True))
-
- self.conf(['bar'])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar')
-
- def test_missing_required_cli_opt(self):
- self.conf.register_cli_opt(StrOpt('foo',
- required=True,
- positional=True))
- self.assertRaises(RequiredOptError, self.conf, [])
-
-
-class ConfigFileOptsTestCase(BaseTestCase):
-
- def _do_deprecated_test_use(self, opt_class, value, result):
- self.conf.register_opt(opt_class('newfoo', deprecated_name='oldfoo'))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'oldfoo = %s\n' % value)])
-
- self.conf(['--config-file', paths[0]])
- self.assertTrue(hasattr(self.conf, 'newfoo'))
- self.assertEquals(self.conf.newfoo, result)
-
- def _do_deprecated_test_ignore(self, opt_class, value, result):
- self.conf.register_opt(opt_class('newfoo', deprecated_name='oldfoo'))
-
- paths2 = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'newfoo = %s\n' % value)])
-
- self.conf(['--config-file', paths2[0]])
- self.assertTrue(hasattr(self.conf, 'newfoo'))
- self.assertEquals(self.conf.newfoo, result)
-
- def test_conf_file_str_default(self):
- self.conf.register_opt(StrOpt('foo', default='bar'))
-
- paths = self.create_tempfiles([('test', '[DEFAULT]\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar')
-
- def test_conf_file_str_value(self):
- self.conf.register_opt(StrOpt('foo'))
-
- paths = self.create_tempfiles([('test', '[DEFAULT]\n''foo = bar\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar')
-
- def test_conf_file_str_value_override(self):
- self.conf.register_cli_opt(StrOpt('foo'))
-
- paths = self.create_tempfiles([('1',
- '[DEFAULT]\n'
- 'foo = baar\n'),
- ('2',
- '[DEFAULT]\n'
- 'foo = baaar\n')])
-
- self.conf(['--foo', 'bar',
- '--config-file', paths[0],
- '--config-file', paths[1]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'baaar')
-
- def test_conf_file_str_value_override_use_deprecated(self):
- """last option should always win, even if last uses deprecated"""
- self.conf.register_cli_opt(StrOpt('newfoo', deprecated_name='oldfoo'))
-
- paths = self.create_tempfiles([('0',
- '[DEFAULT]\n'
- 'newfoo = middle\n'),
- ('1',
- '[DEFAULT]\n'
- 'oldfoo = last\n')])
-
- self.conf(['--newfoo', 'first',
- '--config-file', paths[0],
- '--config-file', paths[1]])
-
- self.assertTrue(hasattr(self.conf, 'newfoo'))
- self.assertFalse(hasattr(self.conf, 'oldfoo'))
- self.assertEquals(self.conf.newfoo, 'last')
-
- def test_conf_file_str_use_deprecated(self):
- self._do_deprecated_test_use(StrOpt, 'value1', 'value1')
-
- def test_conf_file_str_ignore_deprecated(self):
- self._do_deprecated_test_ignore(StrOpt, 'value2', 'value2')
-
- def test_conf_file_bool_default(self):
- self.conf.register_opt(BoolOpt('foo', default=False))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, False)
-
- def test_conf_file_bool_value(self):
- self.conf.register_opt(BoolOpt('foo'))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = true\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, True)
-
- def test_conf_file_bool_value_override(self):
- self.conf.register_cli_opt(BoolOpt('foo'))
-
- paths = self.create_tempfiles([('1',
- '[DEFAULT]\n'
- 'foo = 0\n'),
- ('2',
- '[DEFAULT]\n'
- 'foo = yes\n')])
-
- self.conf(['--foo',
- '--config-file', paths[0],
- '--config-file', paths[1]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, True)
-
- def test_conf_file_bool_use_deprecated(self):
- self._do_deprecated_test_use(BoolOpt, 'yes', True)
-
- def test_conf_file_bool_ignore_deprecated(self):
- self._do_deprecated_test_ignore(BoolOpt, 'no', False)
-
- def test_conf_file_int_default(self):
- self.conf.register_opt(IntOpt('foo', default=666))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 666)
-
- def test_conf_file_int_value(self):
- self.conf.register_opt(IntOpt('foo'))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = 666\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 666)
-
- def test_conf_file_int_value_override(self):
- self.conf.register_cli_opt(IntOpt('foo'))
-
- paths = self.create_tempfiles([('1',
- '[DEFAULT]\n'
- 'foo = 66\n'),
- ('2',
- '[DEFAULT]\n'
- 'foo = 666\n')])
-
- self.conf(['--foo', '6',
- '--config-file', paths[0],
- '--config-file', paths[1]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 666)
-
- def test_conf_file_int_use_deprecated(self):
- self._do_deprecated_test_use(IntOpt, '66', 66)
-
- def test_conf_file_int_ignore_deprecated(self):
- self._do_deprecated_test_ignore(IntOpt, '64', 64)
-
- def test_conf_file_float_default(self):
- self.conf.register_opt(FloatOpt('foo', default=6.66))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 6.66)
-
- def test_conf_file_float_value(self):
- self.conf.register_opt(FloatOpt('foo'))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = 6.66\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 6.66)
-
- def test_conf_file_float_value_override(self):
- self.conf.register_cli_opt(FloatOpt('foo'))
-
- paths = self.create_tempfiles([('1',
- '[DEFAULT]\n'
- 'foo = 6.6\n'),
- ('2',
- '[DEFAULT]\n'
- 'foo = 6.66\n')])
-
- self.conf(['--foo', '6',
- '--config-file', paths[0],
- '--config-file', paths[1]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 6.66)
-
- def test_conf_file_float_use_deprecated(self):
- self._do_deprecated_test_use(FloatOpt, '66.54', 66.54)
-
- def test_conf_file_float_ignore_deprecated(self):
- self._do_deprecated_test_ignore(FloatOpt, '64.54', 64.54)
-
- def test_conf_file_list_default(self):
- self.conf.register_opt(ListOpt('foo', default=['bar']))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, ['bar'])
-
- def test_conf_file_list_value(self):
- self.conf.register_opt(ListOpt('foo'))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = bar\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, ['bar'])
-
- def test_conf_file_list_value_override(self):
- self.conf.register_cli_opt(ListOpt('foo'))
-
- paths = self.create_tempfiles([('1',
- '[DEFAULT]\n'
- 'foo = bar,bar\n'),
- ('2',
- '[DEFAULT]\n'
- 'foo = b,a,r\n')])
-
- self.conf(['--foo', 'bar',
- '--config-file', paths[0],
- '--config-file', paths[1]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, ['b', 'a', 'r'])
-
- def test_conf_file_list_use_deprecated(self):
- self._do_deprecated_test_use(ListOpt, 'a,b,c', ['a', 'b', 'c'])
-
- def test_conf_file_list_ignore_deprecated(self):
- self._do_deprecated_test_ignore(ListOpt, 'd,e,f', ['d', 'e', 'f'])
-
- def test_conf_file_list_spaces_use_deprecated(self):
- self._do_deprecated_test_use(ListOpt, 'a, b, c', ['a', 'b', 'c'])
-
- def test_conf_file_list_spaces_ignore_deprecated(self):
- self._do_deprecated_test_ignore(ListOpt, 'd, e, f', ['d', 'e', 'f'])
-
- def test_conf_file_multistr_default(self):
- self.conf.register_opt(MultiStrOpt('foo', default=['bar']))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, ['bar'])
-
- def test_conf_file_multistr_value(self):
- self.conf.register_opt(MultiStrOpt('foo'))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = bar\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, ['bar'])
-
- def test_conf_file_multistr_values_append_deprecated(self):
- self.conf.register_cli_opt(MultiStrOpt('foo',
- deprecated_name='oldfoo'))
-
- paths = self.create_tempfiles([('1',
- '[DEFAULT]\n'
- 'foo = bar1\n'),
- ('2',
- '[DEFAULT]\n'
- 'oldfoo = bar2\n'
- 'oldfoo = bar3\n')])
-
- self.conf(['--foo', 'bar0',
- '--config-file', paths[0],
- '--config-file', paths[1]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
-
- self.assertEquals(self.conf.foo, ['bar0', 'bar1', 'bar2', 'bar3'])
-
- def test_conf_file_multistr_values_append(self):
- self.conf.register_cli_opt(MultiStrOpt('foo'))
-
- paths = self.create_tempfiles([('1',
- '[DEFAULT]\n'
- 'foo = bar1\n'),
- ('2',
- '[DEFAULT]\n'
- 'foo = bar2\n'
- 'foo = bar3\n')])
-
- self.conf(['--foo', 'bar0',
- '--config-file', paths[0],
- '--config-file', paths[1]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
-
- self.assertEquals(self.conf.foo, ['bar0', 'bar1', 'bar2', 'bar3'])
-
- def test_conf_file_multistr_deprecated(self):
- self.conf.register_opt(MultiStrOpt('newfoo', deprecated_name='oldfoo'))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'oldfoo= bar1\n'
- 'oldfoo = bar2\n')])
-
- self.conf(['--config-file', paths[0]])
- self.assertTrue(hasattr(self.conf, 'newfoo'))
- self.assertEquals(self.conf.newfoo, ['bar1', 'bar2'])
-
- def test_conf_file_multiple_opts(self):
- self.conf.register_opts([StrOpt('foo'), StrOpt('bar')])
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = bar\n'
- 'bar = foo\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar')
- self.assertTrue(hasattr(self.conf, 'bar'))
- self.assertEquals(self.conf.bar, 'foo')
-
- def test_conf_file_raw_value(self):
- self.conf.register_opt(StrOpt('foo'))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = bar-%08x\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar-%08x')
-
-
-class OptGroupsTestCase(BaseTestCase):
-
- def test_arg_group(self):
- blaa_group = OptGroup('blaa', 'blaa options')
- self.conf.register_group(blaa_group)
- self.conf.register_cli_opt(StrOpt('foo'), group=blaa_group)
-
- self.conf(['--blaa-foo', 'bar'])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'bar')
-
- def test_autocreate_group(self):
- self.conf.register_cli_opt(StrOpt('foo'), group='blaa')
-
- self.conf(['--blaa-foo', 'bar'])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'bar')
-
- def test_arg_group_by_name(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_cli_opt(StrOpt('foo'), group='blaa')
-
- self.conf(['--blaa-foo', 'bar'])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'bar')
-
- def test_arg_group_with_default(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_cli_opt(StrOpt('foo', default='bar'), group='blaa')
-
- self.conf([])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'bar')
-
- def test_arg_group_with_conf_and_group_opts(self):
- self.conf.register_cli_opt(StrOpt('conf'), group='blaa')
- self.conf.register_cli_opt(StrOpt('group'), group='blaa')
-
- self.conf(['--blaa-conf', 'foo', '--blaa-group', 'bar'])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'conf'))
- self.assertEquals(self.conf.blaa.conf, 'foo')
- self.assertTrue(hasattr(self.conf.blaa, 'group'))
- self.assertEquals(self.conf.blaa.group, 'bar')
-
- def test_arg_group_in_config_file(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_opt(StrOpt('foo'), group='blaa')
-
- paths = self.create_tempfiles([('test',
- '[blaa]\n'
- 'foo = bar\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'bar')
-
- def test_arg_group_in_config_file_with_deprecated(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_opt(StrOpt('foo', deprecated_name='oldfoo'),
- group='blaa')
-
- paths = self.create_tempfiles([('test',
- '[blaa]\n'
- 'oldfoo = bar\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'bar')
-
-
-class MappingInterfaceTestCase(BaseTestCase):
-
- def test_mapping_interface(self):
- self.conf.register_cli_opt(StrOpt('foo'))
-
- self.conf(['--foo', 'bar'])
-
- self.assertTrue('foo' in self.conf)
- self.assertTrue('config_file' in self.conf)
- self.assertEquals(len(self.conf), 3)
- self.assertEquals(self.conf['foo'], 'bar')
- self.assertEquals(self.conf.get('foo'), 'bar')
- self.assertTrue('bar' in self.conf.values())
-
- def test_mapping_interface_with_group(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_cli_opt(StrOpt('foo'), group='blaa')
-
- self.conf(['--blaa-foo', 'bar'])
-
- self.assertTrue('blaa' in self.conf)
- self.assertTrue('foo' in self.conf['blaa'])
- self.assertEquals(len(self.conf['blaa']), 1)
- self.assertEquals(self.conf['blaa']['foo'], 'bar')
- self.assertEquals(self.conf['blaa'].get('foo'), 'bar')
- self.assertTrue('bar' in self.conf['blaa'].values())
- self.assertEquals(self.conf.blaa, self.conf['blaa'])
-
-
-class ReRegisterOptTestCase(BaseTestCase):
-
- def test_conf_file_re_register_opt(self):
- opt = StrOpt('foo')
- self.assertTrue(self.conf.register_opt(opt))
- self.assertFalse(self.conf.register_opt(opt))
-
- def test_conf_file_re_register_opt_in_group(self):
- group = OptGroup('blaa')
- self.conf.register_group(group)
- self.conf.register_group(group) # not an error
- opt = StrOpt('foo')
- self.assertTrue(self.conf.register_opt(opt, group=group))
- self.assertFalse(self.conf.register_opt(opt, group='blaa'))
-
-
-class TemplateSubstitutionTestCase(BaseTestCase):
-
- def _prep_test_str_sub(self, foo_default=None, bar_default=None):
- self.conf.register_cli_opt(StrOpt('foo', default=foo_default))
- self.conf.register_cli_opt(StrOpt('bar', default=bar_default))
-
- def _assert_str_sub(self):
- self.assertTrue(hasattr(self.conf, 'bar'))
- self.assertEquals(self.conf.bar, 'blaa')
-
- def test_str_sub_default_from_default(self):
- self._prep_test_str_sub(foo_default='blaa', bar_default='$foo')
-
- self.conf([])
-
- self._assert_str_sub()
-
- def test_str_sub_default_from_default_recurse(self):
- self.conf.register_cli_opt(StrOpt('blaa', default='blaa'))
- self._prep_test_str_sub(foo_default='$blaa', bar_default='$foo')
-
- self.conf([])
-
- self._assert_str_sub()
-
- def test_str_sub_default_from_arg(self):
- self._prep_test_str_sub(bar_default='$foo')
-
- self.conf(['--foo', 'blaa'])
-
- self._assert_str_sub()
-
- def test_str_sub_default_from_config_file(self):
- self._prep_test_str_sub(bar_default='$foo')
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = blaa\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self._assert_str_sub()
-
- def test_str_sub_arg_from_default(self):
- self._prep_test_str_sub(foo_default='blaa')
-
- self.conf(['--bar', '$foo'])
-
- self._assert_str_sub()
-
- def test_str_sub_arg_from_arg(self):
- self._prep_test_str_sub()
-
- self.conf(['--foo', 'blaa', '--bar', '$foo'])
-
- self._assert_str_sub()
-
- def test_str_sub_arg_from_config_file(self):
- self._prep_test_str_sub()
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = blaa\n')])
-
- self.conf(['--config-file', paths[0], '--bar=$foo'])
-
- self._assert_str_sub()
-
- def test_str_sub_config_file_from_default(self):
- self._prep_test_str_sub(foo_default='blaa')
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'bar = $foo\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self._assert_str_sub()
-
- def test_str_sub_config_file_from_arg(self):
- self._prep_test_str_sub()
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'bar = $foo\n')])
-
- self.conf(['--config-file', paths[0], '--foo=blaa'])
-
- self._assert_str_sub()
-
- def test_str_sub_config_file_from_config_file(self):
- self._prep_test_str_sub()
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'bar = $foo\n'
- 'foo = blaa\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self._assert_str_sub()
-
- def test_str_sub_group_from_default(self):
- self.conf.register_cli_opt(StrOpt('foo', default='blaa'))
- self.conf.register_group(OptGroup('ba'))
- self.conf.register_cli_opt(StrOpt('r', default='$foo'), group='ba')
-
- self.conf([])
-
- self.assertTrue(hasattr(self.conf, 'ba'))
- self.assertTrue(hasattr(self.conf.ba, 'r'))
- self.assertEquals(self.conf.ba.r, 'blaa')
-
- def test_config_dir(self):
- snafu_group = OptGroup('snafu')
- self.conf.register_group(snafu_group)
- self.conf.register_cli_opt(StrOpt('foo'))
- self.conf.register_cli_opt(StrOpt('bell'), group=snafu_group)
-
- dir = tempfile.mkdtemp()
- self.tempdirs.append(dir)
-
- paths = self.create_tempfiles([(os.path.join(dir, '00-test'),
- '[DEFAULT]\n'
- 'foo = bar-00\n'
- '[snafu]\n'
- 'bell = whistle-00\n'),
- (os.path.join(dir, '02-test'),
- '[snafu]\n'
- 'bell = whistle-02\n'
- '[DEFAULT]\n'
- 'foo = bar-02\n'),
- (os.path.join(dir, '01-test'),
- '[DEFAULT]\n'
- 'foo = bar-01\n')])
-
- self.conf(['--foo', 'bar',
- '--config-dir', os.path.dirname(paths[0])])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar-02')
- self.assertTrue(hasattr(self.conf, 'snafu'))
- self.assertTrue(hasattr(self.conf.snafu, 'bell'))
- self.assertEquals(self.conf.snafu.bell, 'whistle-02')
-
- def test_config_dir_file_precedence(self):
- snafu_group = OptGroup('snafu')
- self.conf.register_group(snafu_group)
- self.conf.register_cli_opt(StrOpt('foo'))
- self.conf.register_cli_opt(StrOpt('bell'), group=snafu_group)
-
- dir = tempfile.mkdtemp()
- self.tempdirs.append(dir)
-
- paths = self.create_tempfiles([(os.path.join(dir, '00-test'),
- '[DEFAULT]\n'
- 'foo = bar-00\n'),
- ('01-test',
- '[snafu]\n'
- 'bell = whistle-01\n'
- '[DEFAULT]\n'
- 'foo = bar-01\n'),
- ('03-test',
- '[snafu]\n'
- 'bell = whistle-03\n'
- '[DEFAULT]\n'
- 'foo = bar-03\n'),
- (os.path.join(dir, '02-test'),
- '[DEFAULT]\n'
- 'foo = bar-02\n')])
-
- self.conf(['--foo', 'bar',
- '--config-file', paths[1],
- '--config-dir', os.path.dirname(paths[0]),
- '--config-file', paths[2], ])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar-02')
- self.assertTrue(hasattr(self.conf, 'snafu'))
- self.assertTrue(hasattr(self.conf.snafu, 'bell'))
- self.assertEquals(self.conf.snafu.bell, 'whistle-03')
-
-
-class ReparseTestCase(BaseTestCase):
-
- def test_reparse(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_cli_opt(StrOpt('foo', default='r'), group='blaa')
-
- paths = self.create_tempfiles([('test',
- '[blaa]\n'
- 'foo = b\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'b')
-
- self.conf(['--blaa-foo', 'a'])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'a')
-
- self.conf([])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'r')
-
-
-class OverridesTestCase(BaseTestCase):
-
- def test_default_none(self):
- self.conf.register_opt(StrOpt('foo', default='foo'))
- self.conf([])
- self.assertEquals(self.conf.foo, 'foo')
- self.conf.set_default('foo', None)
- self.assertEquals(self.conf.foo, None)
- self.conf.clear_default('foo')
- self.assertEquals(self.conf.foo, 'foo')
-
- def test_override_none(self):
- self.conf.register_opt(StrOpt('foo', default='foo'))
- self.conf([])
- self.assertEquals(self.conf.foo, 'foo')
- self.conf.set_override('foo', None)
- self.assertEquals(self.conf.foo, None)
- self.conf.clear_override('foo')
- self.assertEquals(self.conf.foo, 'foo')
-
- def test_no_default_override(self):
- self.conf.register_opt(StrOpt('foo'))
- self.conf([])
- self.assertEquals(self.conf.foo, None)
- self.conf.set_default('foo', 'bar')
- self.assertEquals(self.conf.foo, 'bar')
- self.conf.clear_default('foo')
- self.assertEquals(self.conf.foo, None)
-
- def test_default_override(self):
- self.conf.register_opt(StrOpt('foo', default='foo'))
- self.conf([])
- self.assertEquals(self.conf.foo, 'foo')
- self.conf.set_default('foo', 'bar')
- self.assertEquals(self.conf.foo, 'bar')
- self.conf.clear_default('foo')
- self.assertEquals(self.conf.foo, 'foo')
-
- def test_override(self):
- self.conf.register_opt(StrOpt('foo'))
- self.conf.set_override('foo', 'bar')
- self.conf([])
- self.assertEquals(self.conf.foo, 'bar')
- self.conf.clear_override('foo')
- self.assertEquals(self.conf.foo, None)
-
- def test_group_no_default_override(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_opt(StrOpt('foo'), group='blaa')
- self.conf([])
- self.assertEquals(self.conf.blaa.foo, None)
- self.conf.set_default('foo', 'bar', group='blaa')
- self.assertEquals(self.conf.blaa.foo, 'bar')
- self.conf.clear_default('foo', group='blaa')
- self.assertEquals(self.conf.blaa.foo, None)
-
- def test_group_default_override(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_opt(StrOpt('foo', default='foo'), group='blaa')
- self.conf([])
- self.assertEquals(self.conf.blaa.foo, 'foo')
- self.conf.set_default('foo', 'bar', group='blaa')
- self.assertEquals(self.conf.blaa.foo, 'bar')
- self.conf.clear_default('foo', group='blaa')
- self.assertEquals(self.conf.blaa.foo, 'foo')
-
- def test_group_override(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_opt(StrOpt('foo'), group='blaa')
- self.assertEquals(self.conf.blaa.foo, None)
- self.conf.set_override('foo', 'bar', group='blaa')
- self.conf([])
- self.assertEquals(self.conf.blaa.foo, 'bar')
- self.conf.clear_override('foo', group='blaa')
- self.assertEquals(self.conf.blaa.foo, None)
-
- def test_cli_bool_default(self):
- self.conf.register_cli_opt(BoolOpt('foo'))
- self.conf.set_default('foo', True)
- self.assertTrue(self.conf.foo)
- self.conf([])
- self.assertTrue(self.conf.foo)
- self.conf.set_default('foo', False)
- self.assertFalse(self.conf.foo)
- self.conf.clear_default('foo')
- self.assertTrue(self.conf.foo is None)
-
- def test_cli_bool_override(self):
- self.conf.register_cli_opt(BoolOpt('foo'))
- self.conf.set_override('foo', True)
- self.assertTrue(self.conf.foo)
- self.conf([])
- self.assertTrue(self.conf.foo)
- self.conf.set_override('foo', False)
- self.assertFalse(self.conf.foo)
- self.conf.clear_override('foo')
- self.assertTrue(self.conf.foo is None)
-
-
-class ResetAndClearTestCase(BaseTestCase):
-
- def test_clear(self):
- self.conf.register_cli_opt(StrOpt('foo'))
- self.conf.register_cli_opt(StrOpt('bar'), group='blaa')
-
- self.assertEquals(self.conf.foo, None)
- self.assertEquals(self.conf.blaa.bar, None)
-
- self.conf(['--foo', 'foo', '--blaa-bar', 'bar'])
-
- self.assertEquals(self.conf.foo, 'foo')
- self.assertEquals(self.conf.blaa.bar, 'bar')
-
- self.conf.clear()
-
- self.assertEquals(self.conf.foo, None)
- self.assertEquals(self.conf.blaa.bar, None)
-
- def test_reset_and_clear_with_defaults_and_overrides(self):
- self.conf.register_cli_opt(StrOpt('foo'))
- self.conf.register_cli_opt(StrOpt('bar'), group='blaa')
-
- self.conf.set_default('foo', 'foo')
- self.conf.set_override('bar', 'bar', group='blaa')
-
- self.conf(['--foo', 'foofoo'])
-
- self.assertEquals(self.conf.foo, 'foofoo')
- self.assertEquals(self.conf.blaa.bar, 'bar')
-
- self.conf.clear()
-
- self.assertEquals(self.conf.foo, 'foo')
- self.assertEquals(self.conf.blaa.bar, 'bar')
-
- self.conf.reset()
-
- self.assertEquals(self.conf.foo, None)
- self.assertEquals(self.conf.blaa.bar, None)
-
-
-class UnregisterOptTestCase(BaseTestCase):
-
- def test_unregister_opt(self):
- opts = [StrOpt('foo'), StrOpt('bar')]
-
- self.conf.register_opts(opts)
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertTrue(hasattr(self.conf, 'bar'))
-
- self.conf.unregister_opt(opts[0])
-
- self.assertFalse(hasattr(self.conf, 'foo'))
- self.assertTrue(hasattr(self.conf, 'bar'))
-
- self.conf([])
-
- self.assertRaises(ArgsAlreadyParsedError,
- self.conf.unregister_opt, opts[1])
-
- self.conf.clear()
-
- self.assertTrue(hasattr(self.conf, 'bar'))
-
- self.conf.unregister_opts(opts)
-
- def test_unregister_opt_from_group(self):
- opt = StrOpt('foo')
-
- self.conf.register_opt(opt, group='blaa')
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
-
- self.conf.unregister_opt(opt, group='blaa')
-
- self.assertFalse(hasattr(self.conf.blaa, 'foo'))
-
-
-class ImportOptTestCase(BaseTestCase):
-
- def test_import_opt(self):
- self.assertFalse(hasattr(CONF, 'blaa'))
- CONF.import_opt('blaa', 'tests.testmods.blaa_opt')
- self.assertTrue(hasattr(CONF, 'blaa'))
-
- def test_import_opt_in_group(self):
- self.assertFalse(hasattr(CONF, 'bar'))
- CONF.import_opt('foo', 'tests.testmods.bar_foo_opt', group='bar')
- self.assertTrue(hasattr(CONF, 'bar'))
- self.assertTrue(hasattr(CONF.bar, 'foo'))
-
- def test_import_opt_import_errror(self):
- self.assertRaises(ImportError, CONF.import_opt,
- 'blaa', 'tests.testmods.blaablaa_opt')
-
- def test_import_opt_no_such_opt(self):
- self.assertRaises(NoSuchOptError, CONF.import_opt,
- 'blaablaa', 'tests.testmods.blaa_opt')
-
- def test_import_opt_no_such_group(self):
- self.assertRaises(NoSuchGroupError, CONF.import_opt,
- 'blaa', 'tests.testmods.blaa_opt', group='blaa')
-
-
-class ImportGroupTestCase(BaseTestCase):
-
- def test_import_group(self):
- self.assertFalse(hasattr(CONF, 'qux'))
- CONF.import_group('qux', 'tests.testmods.baz_qux_opt')
- self.assertTrue(hasattr(CONF, 'qux'))
- self.assertTrue(hasattr(CONF.qux, 'baz'))
-
- def test_import_group_import_error(self):
- self.assertRaises(ImportError, CONF.import_group,
- 'qux', 'tests.testmods.bazzz_quxxx_opt')
-
- def test_import_group_no_such_group(self):
- self.assertRaises(NoSuchGroupError, CONF.import_group,
- 'quxxx', 'tests.testmods.baz_qux_opt')
-
-
-class RequiredOptsTestCase(BaseTestCase):
-
- def setUp(self):
- BaseTestCase.setUp(self)
- self.conf.register_opt(StrOpt('boo', required=False))
-
- def test_required_opt(self):
- self.conf.register_opt(StrOpt('foo', required=True))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = bar')])
-
- self.conf(['--config-file', paths[0]])
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar')
-
- def test_required_cli_opt(self):
- self.conf.register_cli_opt(StrOpt('foo', required=True))
-
- self.conf(['--foo', 'bar'])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar')
-
- def test_required_cli_opt_with_dash(self):
- self.conf.register_cli_opt(StrOpt('foo-bar', required=True))
-
- self.conf(['--foo-bar', 'baz'])
-
- self.assertTrue(hasattr(self.conf, 'foo_bar'))
- self.assertEquals(self.conf.foo_bar, 'baz')
-
- def test_missing_required_opt(self):
- self.conf.register_opt(StrOpt('foo', required=True))
- self.assertRaises(RequiredOptError, self.conf, [])
-
- def test_missing_required_cli_opt(self):
- self.conf.register_cli_opt(StrOpt('foo', required=True))
- self.assertRaises(RequiredOptError, self.conf, [])
-
- def test_required_group_opt(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_opt(StrOpt('foo', required=True), group='blaa')
-
- paths = self.create_tempfiles([('test',
- '[blaa]\n'
- 'foo = bar')])
-
- self.conf(['--config-file', paths[0]])
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'bar')
-
- def test_required_cli_group_opt(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_cli_opt(StrOpt('foo', required=True), group='blaa')
-
- self.conf(['--blaa-foo', 'bar'])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'foo'))
- self.assertEquals(self.conf.blaa.foo, 'bar')
-
- def test_missing_required_group_opt(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_opt(StrOpt('foo', required=True), group='blaa')
- self.assertRaises(RequiredOptError, self.conf, [])
-
- def test_missing_required_cli_group_opt(self):
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_cli_opt(StrOpt('foo', required=True), group='blaa')
- self.assertRaises(RequiredOptError, self.conf, [])
-
- def test_required_opt_with_default(self):
- self.conf.register_cli_opt(StrOpt('foo', required=True))
- self.conf.set_default('foo', 'bar')
-
- self.conf([])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar')
-
- def test_required_opt_with_override(self):
- self.conf.register_cli_opt(StrOpt('foo', required=True))
- self.conf.set_override('foo', 'bar')
-
- self.conf([])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar')
-
-
-class SadPathTestCase(BaseTestCase):
-
- def test_unknown_attr(self):
- self.conf([])
- self.assertFalse(hasattr(self.conf, 'foo'))
- self.assertRaises(NoSuchOptError, getattr, self.conf, 'foo')
-
- def test_unknown_attr_is_attr_error(self):
- self.conf([])
- self.assertFalse(hasattr(self.conf, 'foo'))
- self.assertRaises(AttributeError, getattr, self.conf, 'foo')
-
- def test_unknown_group_attr(self):
- self.conf.register_group(OptGroup('blaa'))
-
- self.conf([])
-
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertFalse(hasattr(self.conf.blaa, 'foo'))
- self.assertRaises(NoSuchOptError, getattr, self.conf.blaa, 'foo')
-
- def test_ok_duplicate(self):
- opt = StrOpt('foo')
- self.conf.register_cli_opt(opt)
- opt2 = StrOpt('foo')
- self.conf.register_cli_opt(opt2)
-
- self.conf([])
-
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, None)
-
- def test_error_duplicate(self):
- self.conf.register_cli_opt(StrOpt('foo', help='bar'))
- self.assertRaises(DuplicateOptError,
- self.conf.register_cli_opt, StrOpt('foo'))
-
- def test_error_duplicate_with_different_dest(self):
- self.conf.register_cli_opt(StrOpt('foo', dest='f'))
- self.conf.register_cli_opt(StrOpt('foo'))
- self.assertRaises(DuplicateOptError, self.conf, [])
-
- def test_error_duplicate_short(self):
- self.conf.register_cli_opt(StrOpt('foo', short='f'))
- self.conf.register_cli_opt(StrOpt('bar', short='f'))
- self.assertRaises(DuplicateOptError, self.conf, [])
-
- def test_no_such_group(self):
- group = OptGroup('blaa')
- self.assertRaises(NoSuchGroupError, self.conf.register_cli_opt,
- StrOpt('foo'), group=group)
-
- def test_already_parsed(self):
- self.conf([])
-
- self.assertRaises(ArgsAlreadyParsedError,
- self.conf.register_cli_opt, StrOpt('foo'))
-
- def test_bad_cli_arg(self):
- self.conf.register_opt(BoolOpt('foo'))
-
- self.stubs.Set(sys, 'stderr', StringIO.StringIO())
-
- self.assertRaises(SystemExit, self.conf, ['--foo'])
-
- self.assertTrue('error' in sys.stderr.getvalue())
- self.assertTrue('--foo' in sys.stderr.getvalue())
-
- def _do_test_bad_cli_value(self, opt_class):
- self.conf.register_cli_opt(opt_class('foo'))
-
- self.stubs.Set(sys, 'stderr', StringIO.StringIO())
-
- self.assertRaises(SystemExit, self.conf, ['--foo', 'bar'])
-
- self.assertTrue('foo' in sys.stderr.getvalue())
- self.assertTrue('bar' in sys.stderr.getvalue())
-
- def test_bad_int_arg(self):
- self._do_test_bad_cli_value(IntOpt)
-
- def test_bad_float_arg(self):
- self._do_test_bad_cli_value(FloatOpt)
-
- def test_conf_file_not_found(self):
- (fd, path) = tempfile.mkstemp()
-
- os.remove(path)
-
- self.assertRaises(ConfigFilesNotFoundError,
- self.conf, ['--config-file', path])
-
- def test_conf_file_broken(self):
- paths = self.create_tempfiles([('test', 'foo')])
-
- self.assertRaises(ConfigFileParseError,
- self.conf, ['--config-file', paths[0]])
-
- def _do_test_conf_file_bad_value(self, opt_class):
- self.conf.register_opt(opt_class('foo'))
-
- paths = self.create_tempfiles([('test',
- '[DEFAULT]\n'
- 'foo = bar\n')])
-
- self.conf(['--config-file', paths[0]])
-
- self.assertRaises(ConfigFileValueError, getattr, self.conf, 'foo')
-
- def test_conf_file_bad_bool(self):
- self._do_test_conf_file_bad_value(BoolOpt)
-
- def test_conf_file_bad_int(self):
- self._do_test_conf_file_bad_value(IntOpt)
-
- def test_conf_file_bad_float(self):
- self._do_test_conf_file_bad_value(FloatOpt)
-
- def test_str_sub_from_group(self):
- self.conf.register_group(OptGroup('f'))
- self.conf.register_cli_opt(StrOpt('oo', default='blaa'), group='f')
- self.conf.register_cli_opt(StrOpt('bar', default='$f.oo'))
-
- self.conf([])
-
- self.assertFalse(hasattr(self.conf, 'bar'))
- self.assertRaises(TemplateSubstitutionError, getattr, self.conf, 'bar')
-
- def test_set_default_unknown_attr(self):
- self.conf([])
- self.assertRaises(NoSuchOptError, self.conf.set_default, 'foo', 'bar')
-
- def test_set_default_unknown_group(self):
- self.conf([])
- self.assertRaises(NoSuchGroupError,
- self.conf.set_default, 'foo', 'bar', group='blaa')
-
- def test_set_override_unknown_attr(self):
- self.conf([])
- self.assertRaises(NoSuchOptError, self.conf.set_override, 'foo', 'bar')
-
- def test_set_override_unknown_group(self):
- self.conf([])
- self.assertRaises(NoSuchGroupError,
- self.conf.set_override, 'foo', 'bar', group='blaa')
-
-
-class FindFileTestCase(BaseTestCase):
-
- def test_find_policy_file(self):
- policy_file = '/etc/policy.json'
-
- self.stubs.Set(os.path, 'exists', lambda p: p == policy_file)
-
- self.conf([])
-
- self.assertEquals(self.conf.find_file('foo.json'), None)
- self.assertEquals(self.conf.find_file('policy.json'), policy_file)
-
- def test_find_policy_file_with_config_file(self):
- dir = tempfile.mkdtemp()
- self.tempdirs.append(dir)
-
- paths = self.create_tempfiles([(os.path.join(dir, 'test.conf'),
- '[DEFAULT]'),
- (os.path.join(dir, 'policy.json'),
- '{}')],
- ext='')
-
- self.conf(['--config-file', paths[0]])
-
- self.assertEquals(self.conf.find_file('policy.json'), paths[1])
-
- def test_find_policy_file_with_config_dir(self):
- dir = tempfile.mkdtemp()
- self.tempdirs.append(dir)
-
- path = self.create_tempfiles([(os.path.join(dir, 'policy.json'),
- '{}')],
- ext='')[0]
-
- self.conf(['--config-dir', dir])
-
- self.assertEquals(self.conf.find_file('policy.json'), path)
-
-
-class OptDumpingTestCase(BaseTestCase):
-
- class FakeLogger:
-
- def __init__(self, test_case, expected_lvl):
- self.test_case = test_case
- self.expected_lvl = expected_lvl
- self.logged = []
-
- def log(self, lvl, fmt, *args):
- self.test_case.assertEquals(lvl, self.expected_lvl)
- self.logged.append(fmt % args)
-
- def test_log_opt_values(self):
- self.conf.register_cli_opt(StrOpt('foo'))
- self.conf.register_cli_opt(StrOpt('passwd', secret=True))
- self.conf.register_group(OptGroup('blaa'))
- self.conf.register_cli_opt(StrOpt('bar'), 'blaa')
- self.conf.register_cli_opt(StrOpt('key', secret=True), 'blaa')
-
- self.conf(['--foo', 'this', '--blaa-bar', 'that',
- '--blaa-key', 'admin', '--passwd', 'hush'])
-
- logger = self.FakeLogger(self, 666)
-
- self.conf.log_opt_values(logger, 666)
-
- self.assertEquals(logger.logged, [
- "*" * 80,
- "Configuration options gathered from:",
- "command line args: ['--foo', 'this', '--blaa-bar', "
- "'that', '--blaa-key', 'admin', '--passwd', 'hush']",
- "config files: []",
- "=" * 80,
- "config_dir = None",
- "config_file = []",
- "foo = this",
- "passwd = ****",
- "blaa.bar = that",
- "blaa.key = *****",
- "*" * 80,
- ])
-
-
-class ConfigParserTestCase(utils.BaseTestCase):
- def test_no_section(self):
- with tempfile.NamedTemporaryFile() as tmpfile:
- tmpfile.write('foo = bar')
- tmpfile.flush()
-
- parser = ConfigParser(tmpfile.name, {})
- self.assertRaises(ParseError, parser.parse)
-
-
-class TildeExpansionTestCase(BaseTestCase):
-
- def test_config_file_tilde(self):
- homedir = os.path.expanduser('~')
- tmpfile = tempfile.mktemp(dir=homedir, prefix='cfg-', suffix='.conf')
- tmpbase = os.path.basename(tmpfile)
-
- try:
- self.conf(['--config-file', os.path.join('~', tmpbase)])
- except ConfigFilesNotFoundError, cfnfe:
- print cfnfe
- self.assertTrue(homedir in str(cfnfe))
-
- self.stubs.Set(os.path, 'exists', lambda p: p == tmpfile)
-
- self.assertEquals(self.conf.find_file(tmpbase), tmpfile)
-
- def test_config_dir_tilde(self):
- homedir = os.path.expanduser('~')
- tmpdir = tempfile.mktemp(dir=homedir,
- prefix='cfg-',
- suffix='.d')
- tmpfile = os.path.join(tmpdir, 'foo.conf')
- tmpbase = os.path.basename(tmpfile)
-
- self.stubs.Set(glob, 'glob', lambda p: [tmpfile])
-
- try:
- print ['--config-dir', os.path.join('~', os.path.basename(tmpdir))]
- self.conf(['--config-dir',
- os.path.join('~', os.path.basename(tmpdir))])
- except ConfigFilesNotFoundError, cfnfe:
- print cfnfe
- self.assertTrue(os.path.expanduser('~') in str(cfnfe))
-
- self.stubs.Set(os.path, 'exists', lambda p: p == tmpfile)
-
- self.assertEquals(self.conf.find_file(tmpbase), tmpfile)
-
-
-class SubCommandTestCase(BaseTestCase):
-
- def test_sub_command(self):
- def add_parsers(subparsers):
- sub = subparsers.add_parser('a')
- sub.add_argument('bar', type=int)
-
- self.conf.register_cli_opt(SubCommandOpt('cmd', handler=add_parsers))
- self.assertTrue(hasattr(self.conf, 'cmd'))
- self.conf(['a', '10'])
- self.assertTrue(hasattr(self.conf.cmd, 'name'))
- self.assertTrue(hasattr(self.conf.cmd, 'bar'))
- self.assertEquals(self.conf.cmd.name, 'a')
- self.assertEquals(self.conf.cmd.bar, 10)
-
- def test_sub_command_with_dest(self):
- def add_parsers(subparsers):
- sub = subparsers.add_parser('a')
-
- self.conf.register_cli_opt(SubCommandOpt('cmd', dest='command',
- handler=add_parsers))
- self.assertTrue(hasattr(self.conf, 'command'))
- self.conf(['a'])
- self.assertEquals(self.conf.command.name, 'a')
-
- def test_sub_command_with_group(self):
- def add_parsers(subparsers):
- sub = subparsers.add_parser('a')
- sub.add_argument('--bar', choices='XYZ')
-
- self.conf.register_cli_opt(SubCommandOpt('cmd', handler=add_parsers),
- group='blaa')
- self.assertTrue(hasattr(self.conf, 'blaa'))
- self.assertTrue(hasattr(self.conf.blaa, 'cmd'))
- self.conf(['a', '--bar', 'Z'])
- self.assertTrue(hasattr(self.conf.blaa.cmd, 'name'))
- self.assertTrue(hasattr(self.conf.blaa.cmd, 'bar'))
- self.assertEquals(self.conf.blaa.cmd.name, 'a')
- self.assertEquals(self.conf.blaa.cmd.bar, 'Z')
-
- def test_sub_command_not_cli(self):
- self.conf.register_opt(SubCommandOpt('cmd'))
- self.conf([])
-
- def test_sub_command_resparse(self):
- def add_parsers(subparsers):
- sub = subparsers.add_parser('a')
-
- self.conf.register_cli_opt(SubCommandOpt('cmd',
- handler=add_parsers))
-
- foo_opt = StrOpt('foo')
- self.conf.register_cli_opt(foo_opt)
-
- self.conf(['--foo=bar', 'a'])
-
- self.assertTrue(hasattr(self.conf.cmd, 'name'))
- self.assertEquals(self.conf.cmd.name, 'a')
- self.assertTrue(hasattr(self.conf, 'foo'))
- self.assertEquals(self.conf.foo, 'bar')
-
- self.conf.clear()
- self.conf.unregister_opt(foo_opt)
- self.conf(['a'])
-
- self.assertTrue(hasattr(self.conf.cmd, 'name'))
- self.assertEquals(self.conf.cmd.name, 'a')
- self.assertFalse(hasattr(self.conf, 'foo'))
-
- def test_sub_command_no_handler(self):
- self.conf.register_cli_opt(SubCommandOpt('cmd'))
- self.stubs.Set(sys, 'stderr', StringIO.StringIO())
- self.assertRaises(SystemExit, self.conf, [])
- self.assertTrue('error' in sys.stderr.getvalue())
-
- def test_sub_command_with_help(self):
- def add_parsers(subparsers):
- sub = subparsers.add_parser('a')
-
- self.conf.register_cli_opt(SubCommandOpt('cmd',
- title='foo foo',
- description='bar bar',
- help='blaa blaa',
- handler=add_parsers))
- self.stubs.Set(sys, 'stdout', StringIO.StringIO())
- self.assertRaises(SystemExit, self.conf, ['--help'])
- self.assertTrue('foo foo' in sys.stdout.getvalue())
- self.assertTrue('bar bar' in sys.stdout.getvalue())
- self.assertTrue('blaa blaa' in sys.stdout.getvalue())
-
- def test_sub_command_errors(self):
- def add_parsers(subparsers):
- sub = subparsers.add_parser('a')
- sub.add_argument('--bar')
-
- self.conf.register_cli_opt(BoolOpt('bar'))
- self.conf.register_cli_opt(SubCommandOpt('cmd', handler=add_parsers))
- self.conf(['a'])
- self.assertRaises(DuplicateOptError, getattr, self.conf.cmd, 'bar')
- self.assertRaises(NoSuchOptError, getattr, self.conf.cmd, 'foo')
-
- def test_sub_command_multiple(self):
- self.conf.register_cli_opt(SubCommandOpt('cmd1'))
- self.conf.register_cli_opt(SubCommandOpt('cmd2'))
- self.stubs.Set(sys, 'stderr', StringIO.StringIO())
- self.assertRaises(SystemExit, self.conf, [])
- self.assertTrue('multiple' in sys.stderr.getvalue())
-
-
-class SetDefaultsTestCase(BaseTestCase):
-
- def test_default_to_none(self):
- opts = [StrOpt('foo', default='foo')]
- self.conf.register_opts(opts)
- set_defaults(opts, foo=None)
- self.conf([])
- self.assertEquals(self.conf.foo, None)
-
- def test_default_from_none(self):
- opts = [StrOpt('foo')]
- self.conf.register_opts(opts)
- set_defaults(opts, foo='bar')
- self.conf([])
- self.assertEquals(self.conf.foo, 'bar')
-
- def test_change_default(self):
- opts = [StrOpt('foo', default='foo')]
- self.conf.register_opts(opts)
- set_defaults(opts, foo='bar')
- self.conf([])
- self.assertEquals(self.conf.foo, 'bar')
-
- def test_group_default_to_none(self):
- opts = [StrOpt('foo', default='foo')]
- self.conf.register_opts(opts, group='blaa')
- set_defaults(opts, foo=None)
- self.conf([])
- self.assertEquals(self.conf.blaa.foo, None)
-
- def test_group_default_from_none(self):
- opts = [StrOpt('foo')]
- self.conf.register_opts(opts, group='blaa')
- set_defaults(opts, foo='bar')
- self.conf([])
- self.assertEquals(self.conf.blaa.foo, 'bar')
-
- def test_group_change_default(self):
- opts = [StrOpt('foo', default='foo')]
- self.conf.register_opts(opts, group='blaa')
- set_defaults(opts, foo='bar')
- self.conf([])
- self.assertEquals(self.conf.blaa.foo, 'bar')
diff --git a/tests/unit/test_deprecated.py b/tests/unit/test_deprecated.py
index 5c85fd9..5b17ac0 100644
--- a/tests/unit/test_deprecated.py
+++ b/tests/unit/test_deprecated.py
@@ -14,7 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstack.common import cfg
+from oslo.config import cfg
+
from openstack.common import log as logging
from tests import utils as test_utils
diff --git a/tests/unit/test_iniparser.py b/tests/unit/test_iniparser.py
deleted file mode 100644
index 1dcb9a0..0000000
--- a/tests/unit/test_iniparser.py
+++ /dev/null
@@ -1,127 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack LLC.
-#
-# 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
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-from openstack.common import iniparser
-from tests import utils
-
-
-class TestParser(iniparser.BaseParser):
- comment_called = False
- values = None
- section = ''
-
- def __init__(self):
- self.values = {}
-
- def assignment(self, key, value):
- self.values.setdefault(self.section, {})
- self.values[self.section][key] = value
-
- def new_section(self, section):
- self.section = section
-
- def comment(self, section):
- self.comment_called = True
-
-
-class BaseParserTestCase(utils.BaseTestCase):
- def setUp(self):
- super(BaseParserTestCase, self).setUp()
- self.parser = iniparser.BaseParser()
-
- def _assertParseError(self, *lines):
- self.assertRaises(iniparser.ParseError, self.parser.parse, lines)
-
- def test_invalid_assignment(self):
- self._assertParseError("foo - bar")
-
- def test_empty_key(self):
- self._assertParseError(": bar")
-
- def test_unexpected_continuation(self):
- self._assertParseError(" baz")
-
- def test_invalid_section(self):
- self._assertParseError("[section")
-
- def test_no_section_name(self):
- self._assertParseError("[]")
-
-
-class ParserTestCase(utils.BaseTestCase):
- def setUp(self):
- super(ParserTestCase, self).setUp()
- self.parser = TestParser()
-
- def test_blank_line(self):
- lines = [""]
- self.parser.parse(lines)
- self.assertEquals(self.parser.values, {})
-
- def test_assignment_equal(self):
- lines = ["foo = bar"]
- self.parser.parse(lines)
- self.assertEquals(self.parser.values, {'': {'foo': ['bar']}})
-
- def test_assignment_colon(self):
- lines = ["foo: bar"]
- self.parser.parse(lines)
- self.assertEquals(self.parser.values, {'': {'foo': ['bar']}})
-
- def test_assignment_multiline(self):
- lines = ["foo = bar0", " bar1"]
- self.parser.parse(lines)
- self.assertEquals(self.parser.values, {'': {'foo': ['bar0', 'bar1']}})
-
- def test_assignment_multline_empty(self):
- lines = ["foo = bar0", "", " bar1"]
- self.assertRaises(iniparser.ParseError, self.parser.parse, lines)
-
- def test_section_assignment(self):
- lines = ["[test]", "foo = bar"]
- self.parser.parse(lines)
- self.assertEquals(self.parser.values, {'test': {'foo': ['bar']}})
-
- def test_new_section(self):
- lines = ["[foo]"]
- self.parser.parse(lines)
- self.assertEquals(self.parser.section, 'foo')
-
- def test_comment(self):
- lines = ["# foobar"]
- self.parser.parse(lines)
- self.assertTrue(self.parser.comment_called)
-
- def test_empty_assignment(self):
- lines = ["foo = "]
- self.parser.parse(lines)
- self.assertEquals(self.parser.values, {'': {'foo': ['']}})
-
- def test_assignment_space_single_quote(self):
- lines = ["foo = ' bar '"]
- self.parser.parse(lines)
- self.assertEquals(self.parser.values, {'': {'foo': [' bar ']}})
-
- def test_assignment_space_double_quote(self):
- lines = ["foo = \" bar \""]
- self.parser.parse(lines)
- self.assertEquals(self.parser.values, {'': {'foo': [' bar ']}})
-
-
-class ExceptionTestCase(utils.BaseTestCase):
- def test_parseerror(self):
- exc = iniparser.ParseError('test', 42, 'example')
- self.assertEquals(str(exc), "at line 42, test: 'example'")
diff --git a/tests/unit/test_log.py b/tests/unit/test_log.py
index a0788f1..6a1eeb2 100644
--- a/tests/unit/test_log.py
+++ b/tests/unit/test_log.py
@@ -3,7 +3,8 @@ import logging
import StringIO
import sys
-from openstack.common import cfg
+from oslo.config import cfg
+
from openstack.common import context
from openstack.common import jsonutils
from openstack.common import log
diff --git a/tests/unit/test_notifier.py b/tests/unit/test_notifier.py
index a777fe8..70746b3 100644
--- a/tests/unit/test_notifier.py
+++ b/tests/unit/test_notifier.py
@@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
-from openstack.common import cfg
+from oslo.config import cfg
+
from openstack.common import context
from openstack.common import log
from openstack.common.notifier import api as notifier_api
diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py
index 510e915..42857a5 100644
--- a/tests/unit/test_plugin.py
+++ b/tests/unit/test_plugin.py
@@ -15,7 +15,8 @@
import pkg_resources
-from openstack.common import cfg
+from oslo.config import cfg
+
from openstack.common.notifier import api as notifier_api
from openstack.common.plugin import plugin
from openstack.common.plugin import pluginmanager
diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py
index 824e553..6738d8e 100644
--- a/tests/unit/test_service.py
+++ b/tests/unit/test_service.py
@@ -25,8 +25,8 @@ import time
import traceback
from eventlet import greenthread
+from oslo.config import cfg
-from openstack.common import cfg
from openstack.common.gettextutils import _
from openstack.common import log as logging
from openstack.common.notifier import api as notifier_api
diff --git a/tests/unit/test_version.py b/tests/unit/test_version.py
index b648fc4..312f328 100644
--- a/tests/unit/test_version.py
+++ b/tests/unit/test_version.py
@@ -21,7 +21,8 @@ import StringIO
import sys
import tempfile
-from openstack.common.cfg import *
+from oslo.config.cfg import *
+
from openstack.common import version
from tests import utils
diff --git a/tests/unit/test_wsgi.py b/tests/unit/test_wsgi.py
index 2dd1035..41a1f97 100644
--- a/tests/unit/test_wsgi.py
+++ b/tests/unit/test_wsgi.py
@@ -15,17 +15,18 @@
# License for the specific language governing permissions and limitations
# under the License.
-import mock
import os
-import routes
import socket
import ssl
import urllib2
+
+import mock
+from oslo.config import cfg
+import routes
import webob
from openstack.common import exception
from openstack.common import wsgi
-from openstack.common import cfg
from tests import utils
TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
diff --git a/tests/utils.py b/tests/utils.py
index 2d681ae..f9c1936 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -20,9 +20,9 @@
import subprocess
import fixtures
+from oslo.config import cfg
import testtools
-from openstack.common import cfg
from openstack.common.fixture import moxstubout
from openstack.common import exception