Remove oslo namespace package

Blueprint remove-namespace-packages

Depends-on: I77e50f2f14345321d1b5319343c5872a92977936
for openstack/murano-agent
Depends-on: If51059c31c82d5235e2ae21143911b5561783ca6
for openstack/os-collect-config
Depends-on: I324ca86a21c27ce43cebf255b3c075b8fe110820
for openstack/sahara-dashboard
Depends-on: Icfc882db41883410f7b40fc5a22bfaae1a65dedc
for openstack/tempest
Depends-on: I396a64aa7610b5fcc0bab05bff442ae6b43c6164
for openstack/congress
Depends-on: I749f43bd6dc15717154475cc1a776ffd6164b7fa
for openstack/octavia
Depends-on: I892c0b64ff6bab666f1f23f5e7aeb2da088ea087
for stackforge/python-solumclient
Depends-on: I09b3bec4c68c7fe9379b3d5fefbceaa86ffe994e
for openstack/congress

Related fixes for projects that can't build for other reasons:
I7d35c85926c8f098e2e47051ff44b714478df1b7 for stackforge/magnetodb

needed for the gate:
Depends-On: I0f07858e96ea3baf46f8a453e253b9ed29c7f7e2
Depends-On: I33bd2d9dff9cb7dc1a50177db7286b7317966784

Change-Id: Ibe16f8d7f73234845cab94c8e351f41954eecb0a
This commit is contained in:
Doug Hellmann 2015-04-27 20:27:21 +00:00
parent cbf6b30a7b
commit 59fd48b3f0
26 changed files with 18 additions and 5268 deletions

View File

@ -1,15 +0,0 @@
# 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__('pkg_resources').declare_namespace(__name__)

View File

@ -1,28 +0,0 @@
# 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 warnings
from oslo_config import * # noqa
def deprecated():
new_name = __name__.replace('.', '_')
warnings.warn(
('The oslo namespace package is deprecated. Please use %s instead.' %
new_name),
DeprecationWarning,
stacklevel=3,
)
deprecated()

View File

@ -1,13 +0,0 @@
# 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 oslo_config.cfg import * # noqa

View File

@ -1,13 +0,0 @@
# 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 oslo_config.cfgfilter import * # noqa

View File

@ -1,13 +0,0 @@
# 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 oslo_config.fixture import * # noqa

View File

@ -1,13 +0,0 @@
# 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 oslo_config.generator import * # noqa

View File

@ -1,13 +0,0 @@
# 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 oslo_config.iniparser import * # noqa

View File

@ -1,13 +0,0 @@
# 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 oslo_config.types import * # noqa

View File

@ -2599,43 +2599,45 @@ class ImportOptTestCase(BaseTestCase):
def test_import_opt(self):
self.assertFalse(hasattr(cfg.CONF, 'blaa'))
cfg.CONF.import_opt('blaa', 'tests.testmods.blaa_opt')
cfg.CONF.import_opt('blaa', 'oslo_config.tests.testmods.blaa_opt')
self.assertTrue(hasattr(cfg.CONF, 'blaa'))
def test_import_opt_in_group(self):
self.assertFalse(hasattr(cfg.CONF, 'bar'))
cfg.CONF.import_opt('foo', 'tests.testmods.bar_foo_opt', group='bar')
cfg.CONF.import_opt('foo', 'oslo_config.tests.testmods.bar_foo_opt',
group='bar')
self.assertTrue(hasattr(cfg.CONF, 'bar'))
self.assertTrue(hasattr(cfg.CONF.bar, 'foo'))
def test_import_opt_import_errror(self):
self.assertRaises(ImportError, cfg.CONF.import_opt,
'blaa', 'tests.testmods.blaablaa_opt')
'blaa', 'oslo_config.tests.testmods.blaablaa_opt')
def test_import_opt_no_such_opt(self):
self.assertRaises(cfg.NoSuchOptError, cfg.CONF.import_opt,
'blaablaa', 'tests.testmods.blaa_opt')
'blaablaa', 'oslo_config.tests.testmods.blaa_opt')
def test_import_opt_no_such_group(self):
self.assertRaises(cfg.NoSuchGroupError, cfg.CONF.import_opt,
'blaa', 'tests.testmods.blaa_opt', group='blaa')
'blaa', 'oslo_config.tests.testmods.blaa_opt',
group='blaa')
class ImportGroupTestCase(BaseTestCase):
def test_import_group(self):
self.assertFalse(hasattr(cfg.CONF, 'qux'))
cfg.CONF.import_group('qux', 'tests.testmods.baz_qux_opt')
cfg.CONF.import_group('qux', 'oslo_config.tests.testmods.baz_qux_opt')
self.assertTrue(hasattr(cfg.CONF, 'qux'))
self.assertTrue(hasattr(cfg.CONF.qux, 'baz'))
def test_import_group_import_error(self):
self.assertRaises(ImportError, cfg.CONF.import_group,
'qux', 'tests.testmods.bazzz_quxxx_opt')
'qux', 'oslo_config.tests.testmods.bazzz_quxxx_opt')
def test_import_group_no_such_group(self):
self.assertRaises(cfg.NoSuchGroupError, cfg.CONF.import_group,
'quxxx', 'tests.testmods.baz_qux_opt')
'quxxx', 'oslo_config.tests.testmods.baz_qux_opt')
class RequiredOptsTestCase(BaseTestCase):

View File

@ -281,31 +281,33 @@ class ImportTestCase(BaseTestCase):
def test_import_opt(self):
self.assertFalse(hasattr(self.conf, 'fblaa'))
self.conf.import_opt('fblaa', 'tests.testmods.fblaa_opt')
self.conf.import_opt('fblaa', 'oslo_config.tests.testmods.fblaa_opt')
self.assertTrue(hasattr(self.conf, 'fblaa'))
self.assertFalse(hasattr(self.fconf, 'fblaa'))
self.fconf.import_opt('fblaa', 'tests.testmods.fblaa_opt')
self.fconf.import_opt('fblaa', 'oslo_config.tests.testmods.fblaa_opt')
self.assertTrue(hasattr(self.fconf, 'fblaa'))
def test_import_opt_in_group(self):
self.assertFalse(hasattr(self.conf, 'fbar'))
self.conf.import_opt('foo', 'tests.testmods.fbar_foo_opt',
self.conf.import_opt('foo', 'oslo_config.tests.testmods.fbar_foo_opt',
group='fbar')
self.assertTrue(hasattr(self.conf, 'fbar'))
self.assertTrue(hasattr(self.conf.fbar, 'foo'))
self.assertFalse(hasattr(self.fconf, 'fbar'))
self.fconf.import_opt('foo', 'tests.testmods.fbar_foo_opt',
self.fconf.import_opt('foo', 'oslo_config.tests.testmods.fbar_foo_opt',
group='fbar')
self.assertTrue(hasattr(self.fconf, 'fbar'))
self.assertTrue(hasattr(self.fconf.fbar, 'foo'))
def test_import_group(self):
self.assertFalse(hasattr(self.conf, 'fbaar'))
self.conf.import_group('fbaar', 'tests.testmods.fbaar_baa_opt')
self.conf.import_group('fbaar',
'oslo_config.tests.testmods.fbaar_baa_opt')
self.assertTrue(hasattr(self.conf, 'fbaar'))
self.assertTrue(hasattr(self.conf.fbaar, 'baa'))
self.assertFalse(hasattr(self.fconf, 'fbaar'))
self.fconf.import_group('fbaar', 'tests.testmods.fbaar_baa_opt')
self.fconf.import_group('fbaar',
'oslo_config.tests.testmods.fbaar_baa_opt')
self.assertTrue(hasattr(self.fconf, 'fbaar'))
self.assertTrue(hasattr(self.fconf.fbaar, 'baa'))

View File

@ -22,11 +22,7 @@ classifier =
[files]
packages =
oslo
oslo.config
oslo_config
namespace_packages =
oslo
[global]
setup-hooks =

File diff suppressed because it is too large Load Diff

View File

@ -1,249 +0,0 @@
# 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
# 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 oslotest import base as test_base
from oslo.config import cfg
from oslo.config import cfgfilter
class BaseTestCase(test_base.BaseTestCase):
def setUp(self, conf=None):
super(BaseTestCase, self).setUp()
if conf is None:
self.conf = cfg.ConfigOpts()
else:
self.conf = conf
self.fconf = cfgfilter.ConfigFilter(self.conf)
class RegisterTestCase(BaseTestCase):
def test_register_opt_default(self):
self.fconf.register_opt(cfg.StrOpt('foo', default='bar'))
self.assertEqual('bar', self.fconf.foo)
self.assertEqual('bar', self.fconf['foo'])
self.assertIn('foo', self.fconf)
self.assertEqual(['foo'], list(self.fconf))
self.assertEqual(1, len(self.fconf))
self.assertNotIn('foo', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'foo')
def test_register_opt_none_default(self):
self.fconf.register_opt(cfg.StrOpt('foo'))
self.assertIsNone(self.fconf.foo)
self.assertIsNone(self.fconf['foo'])
self.assertIn('foo', self.fconf)
self.assertEqual(['foo'], list(self.fconf))
self.assertEqual(1, len(self.fconf))
self.assertNotIn('foo', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'foo')
def test_register_grouped_opt_default(self):
self.fconf.register_opt(cfg.StrOpt('foo', default='bar'),
group='blaa')
self.assertEqual('bar', self.fconf.blaa.foo)
self.assertEqual('bar', self.fconf['blaa']['foo'])
self.assertIn('blaa', self.fconf)
self.assertIn('foo', self.fconf.blaa)
self.assertEqual(['blaa'], list(self.fconf))
self.assertEqual(['foo'], list(self.fconf.blaa))
self.assertEqual(1, len(self.fconf))
self.assertEqual(1, len(self.fconf.blaa))
self.assertNotIn('blaa', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'blaa')
def test_register_grouped_opt_none_default(self):
self.fconf.register_opt(cfg.StrOpt('foo'), group='blaa')
self.assertIsNone(self.fconf.blaa.foo)
self.assertIsNone(self.fconf['blaa']['foo'])
self.assertIn('blaa', self.fconf)
self.assertIn('foo', self.fconf.blaa)
self.assertEqual(['blaa'], list(self.fconf))
self.assertEqual(['foo'], list(self.fconf.blaa))
self.assertEqual(1, len(self.fconf))
self.assertEqual(1, len(self.fconf.blaa))
self.assertNotIn('blaa', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'blaa')
def test_register_group(self):
group = cfg.OptGroup('blaa')
self.fconf.register_group(group)
self.fconf.register_opt(cfg.StrOpt('foo'), group=group)
self.assertIsNone(self.fconf.blaa.foo)
self.assertIsNone(self.fconf['blaa']['foo'])
self.assertIn('blaa', self.fconf)
self.assertIn('foo', self.fconf.blaa)
self.assertEqual(['blaa'], list(self.fconf))
self.assertEqual(['foo'], list(self.fconf.blaa))
self.assertEqual(1, len(self.fconf))
self.assertEqual(1, len(self.fconf.blaa))
self.assertNotIn('blaa', self.conf)
self.assertEqual(0, len(self.conf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.conf, 'blaa')
def test_register_opts(self):
self.fconf.register_opts([cfg.StrOpt('foo'),
cfg.StrOpt('bar')])
self.assertIn('foo', self.fconf)
self.assertIn('bar', self.fconf)
self.assertNotIn('foo', self.conf)
self.assertNotIn('bar', self.conf)
def test_register_known_cli_opt(self):
self.conf.register_opt(cfg.StrOpt('foo'))
self.fconf.register_cli_opt(cfg.StrOpt('foo'))
self.assertIn('foo', self.fconf)
self.assertIn('foo', self.conf)
def test_register_known_cli_opts(self):
self.conf.register_cli_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')])
self.fconf.register_cli_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')])
self.assertIn('foo', self.fconf)
self.assertIn('bar', self.fconf)
self.assertIn('foo', self.conf)
self.assertIn('bar', self.conf)
def test_register_opts_grouped(self):
self.fconf.register_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')],
group='blaa')
self.assertIn('foo', self.fconf.blaa)
self.assertIn('bar', self.fconf.blaa)
self.assertNotIn('blaa', self.conf)
def test_register_known_cli_opt_grouped(self):
self.conf.register_cli_opt(cfg.StrOpt('foo'), group='blaa')
self.fconf.register_cli_opt(cfg.StrOpt('foo'), group='blaa')
self.assertIn('foo', self.fconf.blaa)
self.assertIn('blaa', self.fconf)
self.assertIn('blaa', self.conf)
def test_register_known_cli_opts_grouped(self):
self.conf.register_cli_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')],
group='blaa')
self.fconf.register_cli_opts([cfg.StrOpt('foo'), cfg.StrOpt('bar')],
group='blaa')
self.assertIn('foo', self.fconf.blaa)
self.assertIn('bar', self.fconf.blaa)
self.assertIn('blaa', self.fconf)
self.assertIn('blaa', self.conf)
def test_unknown_opt(self):
self.assertNotIn('foo', self.fconf)
self.assertEqual(0, len(self.fconf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.fconf, 'foo')
self.assertNotIn('blaa', self.conf)
def test_blocked_opt(self):
self.conf.register_opt(cfg.StrOpt('foo'))
self.assertIn('foo', self.conf)
self.assertEqual(1, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertNotIn('foo', self.fconf)
self.assertEqual(0, len(self.fconf))
self.assertRaises(cfg.NoSuchOptError, getattr, self.fconf, 'foo')
def test_already_registered_opt(self):
self.conf.register_opt(cfg.StrOpt('foo'))
self.fconf.register_opt(cfg.StrOpt('foo'))
self.assertIn('foo', self.conf)
self.assertEqual(1, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertIn('foo', self.fconf)
self.assertEqual(1, len(self.fconf))
self.assertIsNone(self.fconf.foo)
self.conf.set_override('foo', 'bar')
self.assertEqual('bar', self.conf.foo)
self.assertEqual('bar', self.fconf.foo)
def test_already_registered_opts(self):
self.conf.register_opts([cfg.StrOpt('foo'),
cfg.StrOpt('fu')])
self.fconf.register_opts([cfg.StrOpt('foo'),
cfg.StrOpt('bu')])
self.assertIn('foo', self.conf)
self.assertIn('fu', self.conf)
self.assertNotIn('bu', self.conf)
self.assertEqual(2, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertIsNone(self.conf.fu)
self.assertIn('foo', self.fconf)
self.assertIn('bu', self.fconf)
self.assertNotIn('fu', self.fconf)
self.assertEqual(2, len(self.fconf))
self.assertIsNone(self.fconf.foo)
self.assertIsNone(self.fconf.bu)
self.conf.set_override('foo', 'bar')
self.assertEqual('bar', self.conf.foo)
self.assertEqual('bar', self.fconf.foo)
def test_already_registered_cli_opt(self):
self.conf.register_cli_opt(cfg.StrOpt('foo'))
self.fconf.register_cli_opt(cfg.StrOpt('foo'))
self.assertIn('foo', self.conf)
self.assertEqual(1, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertIn('foo', self.fconf)
self.assertEqual(1, len(self.fconf))
self.assertIsNone(self.fconf.foo)
self.conf.set_override('foo', 'bar')
self.assertEqual('bar', self.conf.foo)
self.assertEqual('bar', self.fconf.foo)
def test_already_registered_cli_opts(self):
self.conf.register_cli_opts([cfg.StrOpt('foo'),
cfg.StrOpt('fu')])
self.fconf.register_cli_opts([cfg.StrOpt('foo'),
cfg.StrOpt('fu')])
self.assertIn('foo', self.conf)
self.assertIn('fu', self.conf)
self.assertEqual(2, len(self.conf))
self.assertIsNone(self.conf.foo)
self.assertIsNone(self.conf.fu)
self.assertIn('foo', self.fconf)
self.assertIn('fu', self.fconf)
self.assertEqual(2, len(self.fconf))
self.assertIsNone(self.fconf.foo)
self.assertIsNone(self.fconf.fu)
self.conf.set_override('foo', 'bar')
self.assertEqual('bar', self.conf.foo)
self.assertEqual('bar', self.fconf.foo)

View File

@ -1,154 +0,0 @@
#
# Copyright 2013 Mirantis, Inc.
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
# 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 oslotest import base
from oslo.config import cfg
from oslo.config import fixture as config
class ConfigTestCase(base.BaseTestCase):
def _make_fixture(self):
conf = cfg.ConfigOpts()
config_fixture = config.Config(conf)
config_fixture.setUp()
config_fixture.register_opt(cfg.StrOpt(
'testing_option', default='initial_value'))
return (config_fixture, conf)
def test_overridden_value(self):
f, conf = self._make_fixture()
self.assertEqual(conf.get('testing_option'), 'initial_value')
f.config(testing_option='changed_value')
self.assertEqual(conf.get('testing_option'),
f.conf.get('testing_option'))
def test_cleanup(self):
f, conf = self._make_fixture()
f.config(testing_option='changed_value')
self.assertEqual(f.conf.get('testing_option'),
'changed_value')
f.conf.reset()
self.assertEqual(conf.get('testing_option'), 'initial_value')
def test_register_option(self):
f, conf = self._make_fixture()
opt = cfg.StrOpt('new_test_opt', default='initial_value')
f.register_opt(opt)
self.assertEqual(conf.get('new_test_opt'),
opt.default)
def test_register_options(self):
f, conf = self._make_fixture()
opt1 = cfg.StrOpt('first_test_opt', default='initial_value_1')
opt2 = cfg.StrOpt('second_test_opt', default='initial_value_2')
f.register_opts([opt1, opt2])
self.assertEqual(conf.get('first_test_opt'), opt1.default)
self.assertEqual(conf.get('second_test_opt'), opt2.default)
def test_cleanup_unregister_option(self):
f, conf = self._make_fixture()
opt = cfg.StrOpt('new_test_opt', default='initial_value')
f.register_opt(opt)
self.assertEqual(conf.get('new_test_opt'),
opt.default)
f.cleanUp()
self.assertRaises(cfg.NoSuchOptError, conf.get, 'new_test_opt')
def test_register_cli_option(self):
f, conf = self._make_fixture()
opt = cfg.StrOpt('new_test_opt', default='initial_value')
f.register_cli_opt(opt)
self.assertEqual(conf.get('new_test_opt'),
opt.default)
def test_register_cli_options(self):
f, conf = self._make_fixture()
opt1 = cfg.StrOpt('first_test_opt', default='initial_value_1')
opt2 = cfg.StrOpt('second_test_opt', default='initial_value_2')
f.register_cli_opts([opt1, opt2])
self.assertEqual(conf.get('first_test_opt'), opt1.default)
self.assertEqual(conf.get('second_test_opt'), opt2.default)
def test_cleanup_unregister_cli_option(self):
f, conf = self._make_fixture()
opt = cfg.StrOpt('new_test_opt', default='initial_value')
f.register_cli_opt(opt)
self.assertEqual(conf.get('new_test_opt'),
opt.default)
f.cleanUp()
self.assertRaises(cfg.NoSuchOptError, conf.get, 'new_test_opt')
def test_load_raw_values(self):
f, conf = self._make_fixture()
f.load_raw_values(first_test_opt='loaded_value_1',
second_test_opt='loaded_value_2')
# Must not be registered.
self.assertRaises(cfg.NoSuchOptError, conf.get, 'first_test_opt')
self.assertRaises(cfg.NoSuchOptError, conf.get, 'second_test_opt')
opt1 = cfg.StrOpt('first_test_opt', default='initial_value_1')
opt2 = cfg.StrOpt('second_test_opt', default='initial_value_2')
f.register_opt(opt1)
f.register_opt(opt2)
self.assertEqual(conf.first_test_opt, 'loaded_value_1')
self.assertEqual(conf.second_test_opt, 'loaded_value_2')
# Cleanup.
f.cleanUp()
# Must no longer be registered.
self.assertRaises(cfg.NoSuchOptError, conf.get, 'first_test_opt')
self.assertRaises(cfg.NoSuchOptError, conf.get, 'second_test_opt')
# Even when registered, must be default.
f.register_opt(opt1)
f.register_opt(opt2)
self.assertEqual(conf.first_test_opt, 'initial_value_1')
self.assertEqual(conf.second_test_opt, 'initial_value_2')
def test_assert_default_files_cleanup(self):
"""Assert that using the fixture forces a clean list."""
f, conf = self._make_fixture()
self.assertNotIn('default_config_files', conf)
config_files = ['./test_fixture.conf']
f.set_config_files(config_files)
self.assertEqual(conf.default_config_files, config_files)
f.cleanUp()
self.assertNotIn('default_config_files', conf)
def test_load_custom_files(self):
f, conf = self._make_fixture()
self.assertNotIn('default_config_files', conf)
config_files = ['./oslo_config/tests/test_fixture.conf']
f.set_config_files(config_files)
opt1 = cfg.StrOpt('first_test_opt', default='initial_value_1')
opt2 = cfg.StrOpt('second_test_opt', default='initial_value_2')
f.register_opt(opt1)
f.register_opt(opt2)
self.assertEqual('loaded_value_1', conf.get('first_test_opt'))
self.assertEqual('loaded_value_2', conf.get('second_test_opt'))

View File

@ -1,592 +0,0 @@
# 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
# 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 sys
import fixtures
import mock
from oslotest import base
from six import moves
import testscenarios
from oslo.config import cfg
from oslo.config import fixture as config_fixture
from oslo.config import generator
from oslo_i18n import fixture as i18n_fixture
load_tests = testscenarios.load_tests_apply_scenarios
class GeneratorTestCase(base.BaseTestCase):
opts = {
'foo': cfg.StrOpt('foo', help='foo option'),
'foo_i18n_help': cfg.StrOpt('foo_i18n_help',
help=i18n_fixture.Translation().lazy(
'this is a lazy message')),
'bar': cfg.StrOpt('bar', help='bar option'),
'foo-bar': cfg.StrOpt('foo-bar', help='foobar'),
'no_help': cfg.StrOpt('no_help'),
'long_help': cfg.StrOpt('long_help',
help='Lorem ipsum dolor sit amet, consectetur '
'adipisicing elit, sed do eiusmod tempor '
'incididunt ut labore et dolore magna '
'aliqua. Ut enim ad minim veniam, quis '
'nostrud exercitation ullamco laboris '
'nisi ut aliquip ex ea commodo '
'consequat. Duis aute irure dolor in '
'reprehenderit in voluptate velit esse '
'cillum dolore eu fugiat nulla '
'pariatur. Excepteur sint occaecat '
'cupidatat non proident, sunt in culpa '
'qui officia deserunt mollit anim id est '
'laborum.'),
'choices_opt': cfg.StrOpt('choices_opt',
default='a',
choices=(None, '', 'a', 'b', 'c'),
help='a string with choices'),
'deprecated_opt': cfg.StrOpt('bar',
deprecated_name='foobar',
help='deprecated'),
'deprecated_group': cfg.StrOpt('bar',
deprecated_group='group1',
deprecated_name='foobar',
help='deprecated'),
# Unknown Opt default must be a string
'unknown_type': cfg.Opt('unknown_opt',
default='123',
help='unknown'),
'str_opt': cfg.StrOpt('str_opt',
default='foo bar',
help='a string'),
'str_opt_sample_default': cfg.StrOpt('str_opt',
default='fooishbar',
help='a string'),
'str_opt_with_space': cfg.StrOpt('str_opt',
default=' foo bar ',
help='a string with spaces'),
'bool_opt': cfg.BoolOpt('bool_opt',
default=False,
help='a boolean'),
'int_opt': cfg.IntOpt('int_opt',
default=10,
min=1,
max=20,
help='an integer'),
'float_opt': cfg.FloatOpt('float_opt',
default=0.1,
help='a float'),
'list_opt': cfg.ListOpt('list_opt',
default=['1', '2', '3'],
help='a list'),
'dict_opt': cfg.DictOpt('dict_opt',
default={'1': 'yes', '2': 'no'},
help='a dict'),
'multi_opt': cfg.MultiStrOpt('multi_opt',
default=['1', '2', '3'],
help='multiple strings'),
'multi_opt_none': cfg.MultiStrOpt('multi_opt_none',
help='multiple strings'),
'multi_opt_empty': cfg.MultiStrOpt('multi_opt_empty',
default=[],
help='multiple strings'),
'multi_opt_sample_default': cfg.MultiStrOpt('multi_opt',
default=['1', '2', '3'],
sample_default=['5', '6'],
help='multiple strings'),
'group_opt': cfg.OptGroup('group_opt', title='a group'),
}
content_scenarios = [
('empty',
dict(opts=[], expected='''[DEFAULT]
''')),
('single_namespace',
dict(opts=[('test', [(None, [opts['foo']])])],
expected='''[DEFAULT]
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('multiple_namespaces',
dict(opts=[('test', [(None, [opts['foo']])]),
('other', [(None, [opts['bar']])])],
expected='''[DEFAULT]
#
# From other
#
# bar option (string value)
#bar = <None>
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('group',
dict(opts=[('test', [('group1', [opts['foo']])])],
expected='''[DEFAULT]
[group1]
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('group_opt',
dict(opts=[('test', [(opts['group_opt'], [opts['foo']])])],
expected='''[DEFAULT]
[group_opt]
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('empty_group',
dict(opts=[('test', [('group1', [])])],
expected='''[DEFAULT]
''')),
('multiple_groups',
dict(opts=[('test', [('group1', [opts['foo']]),
('group2', [opts['bar']])])],
expected='''[DEFAULT]
[group1]
#
# From test
#
# foo option (string value)
#foo = <None>
[group2]
#
# From test
#
# bar option (string value)
#bar = <None>
''')),
('group_in_multiple_namespaces',
dict(opts=[('test', [('group1', [opts['foo']])]),
('other', [('group1', [opts['bar']])])],
expected='''[DEFAULT]
[group1]
#
# From other
#
# bar option (string value)
#bar = <None>
#
# From test
#
# foo option (string value)
#foo = <None>
''')),
('hyphenated_name',
dict(opts=[('test', [(None, [opts['foo-bar']])])],
expected='''[DEFAULT]
#
# From test
#
# foobar (string value)
#foo_bar = <None>
''')),
('i18n_help',
dict(opts=[('test', [(None, [opts['foo_i18n_help']])])],
expected='''[DEFAULT]
#
# From test
#
# this is a lazy message (string value)
#foo_i18n_help = <None>
''')),
('no_help',
dict(opts=[('test', [(None, [opts['no_help']])])],
log_warning=('"%s" is missing a help string', 'no_help'),
expected='''[DEFAULT]
#
# From test
#
# (string value)
#no_help = <None>
''')),
('long_help',
dict(opts=[('test', [(None, [opts['long_help']])])],
expected='''[DEFAULT]
#
# From test
#
# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
# eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
# ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
# aliquip ex ea commodo consequat. Duis aute irure dolor in
# reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
# pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
# culpa qui officia deserunt mollit anim id est laborum. (string
# value)
#long_help = <None>
''')),
('long_help_wrap_at_40',
dict(opts=[('test', [(None, [opts['long_help']])])],
wrap_width=40,
expected='''[DEFAULT]
#
# From test
#
# Lorem ipsum dolor sit amet,
# consectetur adipisicing elit, sed do
# eiusmod tempor incididunt ut labore et
# dolore magna aliqua. Ut enim ad minim
# veniam, quis nostrud exercitation
# ullamco laboris nisi ut aliquip ex ea
# commodo consequat. Duis aute irure
# dolor in reprehenderit in voluptate
# velit esse cillum dolore eu fugiat
# nulla pariatur. Excepteur sint
# occaecat cupidatat non proident, sunt
# in culpa qui officia deserunt mollit
# anim id est laborum. (string value)
#long_help = <None>
''')),
('long_help_no_wrapping',
dict(opts=[('test', [(None, [opts['long_help']])])],
wrap_width=0,
expected='''[DEFAULT]
#
# From test
#
''' # noqa
'# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod '
'tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, '
'quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo '
'consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse '
'cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat '
'non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. '
'(string value)'
'''
#long_help = <None>
''')),
('choices_opt',
dict(opts=[('test', [(None, [opts['choices_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a string with choices (string value)
# Allowed values: <None>, '', a, b, c
#choices_opt = a
''')),
('deprecated',
dict(opts=[('test', [('foo', [opts['deprecated_opt']])])],
expected='''[DEFAULT]
[foo]
#
# From test
#
# deprecated (string value)
# Deprecated group/name - [DEFAULT]/foobar
#bar = <None>
''')),
('deprecated_group',
dict(opts=[('test', [('foo', [opts['deprecated_group']])])],
expected='''[DEFAULT]
[foo]
#
# From test
#
# deprecated (string value)
# Deprecated group/name - [group1]/foobar
#bar = <None>
''')),
('unknown_type',
dict(opts=[('test', [(None, [opts['unknown_type']])])],
log_warning=('Unknown option type: %s',
repr(opts['unknown_type'])),
expected='''[DEFAULT]
#
# From test
#
# unknown (unknown type)
#unknown_opt = 123
''')),
('str_opt',
dict(opts=[('test', [(None, [opts['str_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a string (string value)
#str_opt = foo bar
''')),
('str_opt_with_space',
dict(opts=[('test', [(None, [opts['str_opt_with_space']])])],
expected='''[DEFAULT]
#
# From test
#
# a string with spaces (string value)
#str_opt = " foo bar "
''')),
('bool_opt',
dict(opts=[('test', [(None, [opts['bool_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a boolean (boolean value)
#bool_opt = false
''')),
('int_opt',
dict(opts=[('test', [(None, [opts['int_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# an integer (integer value)
# Minimum value: 1
# Maximum value: 20
#int_opt = 10
''')),
('float_opt',
dict(opts=[('test', [(None, [opts['float_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a float (floating point value)
#float_opt = 0.1
''')),
('list_opt',
dict(opts=[('test', [(None, [opts['list_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a list (list value)
#list_opt = 1,2,3
''')),
('dict_opt',
dict(opts=[('test', [(None, [opts['dict_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# a dict (dict value)
#dict_opt = 1:yes,2:no
''')),
('multi_opt',
dict(opts=[('test', [(None, [opts['multi_opt']])])],
expected='''[DEFAULT]
#
# From test
#
# multiple strings (multi valued)
#multi_opt = 1
#multi_opt = 2
#multi_opt = 3
''')),
('multi_opt_none',
dict(opts=[('test', [(None, [opts['multi_opt_none']])])],
expected='''[DEFAULT]
#
# From test
#
# multiple strings (multi valued)
#multi_opt_none =
''')),
('multi_opt_empty',
dict(opts=[('test', [(None, [opts['multi_opt_empty']])])],
expected='''[DEFAULT]
#
# From test
#
# multiple strings (multi valued)
#multi_opt_empty =
''')),
('str_opt_sample_default',
dict(opts=[('test', [(None, [opts['str_opt_sample_default']])])],
expected='''[DEFAULT]
#
# From test
#
# a string (string value)
#str_opt = fooishbar
''')),
('multi_opt_sample_default',
dict(opts=[('test', [(None, [opts['multi_opt_sample_default']])])],
expected='''[DEFAULT]
#
# From test
#
# multiple strings (multi valued)
#multi_opt = 5
#multi_opt = 6
''')),
]
output_file_scenarios = [
('stdout',
dict(stdout=True, output_file=None)),
('output_file',
dict(output_file='sample.conf', stdout=False)),
]
@classmethod
def generate_scenarios(cls):
cls.scenarios = testscenarios.multiply_scenarios(
cls.content_scenarios,
cls.output_file_scenarios)
def setUp(self):
super(GeneratorTestCase, self).setUp()
self.conf = cfg.ConfigOpts()
self.config_fixture = config_fixture.Config(self.conf)
self.config = self.config_fixture.config
self.useFixture(self.config_fixture)
self.tempdir = self.useFixture(fixtures.TempDir())
def _capture_stream(self, stream_name):
self.useFixture(fixtures.MonkeyPatch("sys.%s" % stream_name,
moves.StringIO()))
return getattr(sys, stream_name)
def _capture_stdout(self):
return self._capture_stream('stdout')
@mock.patch('stevedore.named.NamedExtensionManager')
@mock.patch('oslo_config.generator.LOG')
def test_generate(self, mock_log, named_mgr):
generator.register_cli_opts(self.conf)
namespaces = [i[0] for i in self.opts]
self.config(namespace=namespaces)
wrap_width = getattr(self, 'wrap_width', None)
if wrap_width is not None:
self.config(wrap_width=wrap_width)
if self.stdout:
stdout = self._capture_stdout()
else:
output_file = self.tempdir.join(self.output_file)
self.config(output_file=output_file)
mock_eps = []
for name, opts in self.opts:
mock_ep = mock.Mock()
mock_ep.configure_mock(name=name, obj=opts)
mock_eps.append(mock_ep)
named_mgr.return_value = mock_eps
generator.generate(self.conf)
if self.stdout:
self.assertEqual(self.expected, stdout.getvalue())
else:
content = open(output_file).read()
self.assertEqual(self.expected, content)
named_mgr.assert_called_once_with(
'oslo.config.opts',
names=namespaces,
on_load_failure_callback=generator.on_load_failure_callback,
invoke_on_load=True)
log_warning = getattr(self, 'log_warning', None)
if log_warning is not None:
mock_log.warning.assert_called_once_with(*log_warning)
else:
self.assertFalse(mock_log.warning.called)
GeneratorTestCase.generate_scenarios()

View File

@ -1,124 +0,0 @@
# Copyright 2012 OpenStack Foundation
#
# 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 unittest
from oslo.config import iniparser
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(unittest.TestCase):
def setUp(self):
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(unittest.TestCase):
def setUp(self):
self.parser = TestParser()
def test_blank_line(self):
lines = [""]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {})
def test_assignment_equal(self):
lines = ["foo = bar"]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {'': {'foo': ['bar']}})
def test_assignment_colon(self):
lines = ["foo: bar"]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {'': {'foo': ['bar']}})
def test_assignment_multiline(self):
lines = ["foo = bar0", " bar1"]
self.parser.parse(lines)
self.assertEqual(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.assertEqual(self.parser.values, {'test': {'foo': ['bar']}})
def test_new_section(self):
lines = ["[foo]"]
self.parser.parse(lines)
self.assertEqual(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.assertEqual(self.parser.values, {'': {'foo': ['']}})
def test_assignment_space_single_quote(self):
lines = ["foo = ' bar '"]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {'': {'foo': [' bar ']}})
def test_assignment_space_double_quote(self):
lines = ["foo = \" bar \""]
self.parser.parse(lines)
self.assertEqual(self.parser.values, {'': {'foo': [' bar ']}})
class ExceptionTestCase(unittest.TestCase):
def test_parseerror(self):
exc = iniparser.ParseError('test', 42, 'example')
self.assertEqual(str(exc), "at line 42, test: 'example'")

View File

@ -1,411 +0,0 @@
# Copyright 2013 Mirantis, 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 unittest
from oslo.config import types
class TypeTestHelper(object):
def setUp(self):
super(TypeTestHelper, self).setUp()
self.type_instance = self.type
def assertConvertedValue(self, s, expected):
self.assertEqual(expected, self.type_instance(s))
def assertInvalid(self, value):
self.assertRaises(ValueError, self.type_instance, value)
class StringTypeTests(TypeTestHelper, unittest.TestCase):
type = types.String()
def test_empty_string_passes(self):
self.assertConvertedValue('', '')
def test_should_return_same_string_if_valid(self):
self.assertConvertedValue('foo bar', 'foo bar')
def test_listed_value(self):
self.type_instance = types.String(choices=['foo', 'bar'])
self.assertConvertedValue('foo', 'foo')
def test_unlisted_value(self):
self.type_instance = types.String(choices=['foo', 'bar'])
self.assertInvalid('baz')
def test_with_no_values_returns_error(self):
self.type_instance = types.String(choices=[])
self.assertInvalid('foo')
def test_string_with_non_closed_quote_is_invalid(self):
self.type_instance = types.String(quotes=True)
self.assertInvalid('"foo bar')
self.assertInvalid("'bar baz")
def test_quotes_are_stripped(self):
self.type_instance = types.String(quotes=True)
self.assertConvertedValue('"foo bar"', 'foo bar')
def test_trailing_quote_is_ok(self):
self.type_instance = types.String(quotes=True)
self.assertConvertedValue('foo bar"', 'foo bar"')
def test_repr(self):
t = types.String()
self.assertEqual('String', repr(t))
def test_repr_with_choices(self):
t = types.String(choices=['foo', 'bar'])
self.assertEqual('String(choices=[\'foo\', \'bar\'])', repr(t))
def test_equal(self):
self.assertTrue(types.String() == types.String())
def test_equal_with_same_choices(self):
t1 = types.String(choices=['foo', 'bar'])
t2 = types.String(choices=['foo', 'bar'])
self.assertTrue(t1 == t2)
def test_not_equal_with_different_choices(self):
t1 = types.String(choices=['foo', 'bar'])
t2 = types.String(choices=['foo', 'baz'])
self.assertFalse(t1 == t2)
def test_equal_with_equal_quote_falgs(self):
t1 = types.String(quotes=True)
t2 = types.String(quotes=True)
self.assertTrue(t1 == t2)
def test_not_equal_with_different_quote_falgs(self):
t1 = types.String(quotes=False)
t2 = types.String(quotes=True)
self.assertFalse(t1 == t2)
def test_not_equal_to_other_class(self):
self.assertFalse(types.String() == types.Integer())
class BooleanTypeTests(TypeTestHelper, unittest.TestCase):
type = types.Boolean()
def test_True(self):
self.assertConvertedValue('True', True)
def test_yes(self):
self.assertConvertedValue('yes', True)
def test_on(self):
self.assertConvertedValue('on', True)
def test_1(self):
self.assertConvertedValue('1', True)
def test_False(self):
self.assertConvertedValue('False', False)
def test_no(self):
self.assertConvertedValue('no', False)
def test_off(self):
self.assertConvertedValue('off', False)
def test_0(self):
self.assertConvertedValue('0', False)
def test_other_values_produce_error(self):
self.assertInvalid('foo')
def test_repr(self):
self.assertEqual('Boolean', repr(types.Boolean()))
def test_equal(self):
self.assertEqual(types.Boolean(), types.Boolean())
def test_not_equal_to_other_class(self):
self.assertFalse(types.Boolean() == types.String())
class IntegerTypeTests(TypeTestHelper, unittest.TestCase):
type = types.Integer()
def test_empty_string(self):
self.assertConvertedValue('', None)
def test_whitespace_string(self):
self.assertConvertedValue(" \t\t\t\t", None)
def test_positive_values_are_valid(self):
self.assertConvertedValue('123', 123)
def test_zero_is_valid(self):
self.assertConvertedValue('0', 0)
def test_negative_values_are_valid(self):
self.assertConvertedValue('-123', -123)
def test_leading_whitespace_is_ignored(self):
self.assertConvertedValue(' 5', 5)
def test_trailing_whitespace_is_ignored(self):
self.assertConvertedValue('7 ', 7)
def test_non_digits_are_invalid(self):
self.assertInvalid('12a45')
def test_repr(self):
t = types.Integer()
self.assertEqual('Integer', repr(t))
def test_repr_with_min(self):
t = types.Integer(min=123)
self.assertEqual('Integer(min=123)', repr(t))
def test_repr_with_max(self):
t = types.Integer(max=456)
self.assertEqual('Integer(max=456)', repr(t))
def test_repr_with_min_and_max(self):
t = types.Integer(min=123, max=456)
self.assertEqual('Integer(min=123, max=456)', repr(t))
def test_equal(self):
self.assertTrue(types.Integer() == types.Integer())
def test_equal_with_same_min_and_no_max(self):
self.assertTrue(types.Integer(min=123) == types.Integer(min=123))
def test_equal_with_same_max_and_no_min(self):
self.assertTrue(types.Integer(max=123) == types.Integer(max=123))
def test_equal_with_same_min_and_max(self):
t1 = types.Integer(min=1, max=123)
t2 = types.Integer(min=1, max=123)
self.assertTrue(t1 == t2)
def test_not_equal(self):
self.assertFalse(types.Integer(min=123) == types.Integer(min=456))
def test_not_equal_to_other_class(self):
self.assertFalse(types.Integer() == types.String())
def test_with_max_and_min(self):
t = types.Integer(min=123, max=456)
self.assertRaises(ValueError, t, 122)
t(123)
t(300)
t(456)
self.assertRaises(ValueError, t, 457)
class FloatTypeTests(TypeTestHelper, unittest.TestCase):
type = types.Float()
def test_decimal_format(self):
v = self.type_instance('123.456')
self.assertAlmostEqual(v, 123.456)
def test_decimal_format_negative_float(self):
v = self.type_instance('-123.456')
self.assertAlmostEqual(v, -123.456)
def test_exponential_format(self):
v = self.type_instance('123e-2')
self.assertAlmostEqual(v, 1.23)
def test_non_float_is_invalid(self):
self.assertInvalid('123,345')
self.assertInvalid('foo')
def test_repr(self):
self.assertEqual('Float', repr(types.Float()))
def test_equal(self):
self.assertTrue(types.Float() == types.Float())
def test_not_equal_to_other_class(self):
self.assertFalse(types.Float() == types.Integer())
class ListTypeTests(TypeTestHelper, unittest.TestCase):
type = types.List()
def test_empty_value(self):
self.assertConvertedValue('', [])
def test_single_value(self):
self.assertConvertedValue(' foo bar ',
['foo bar'])
def test_list_of_values(self):
self.assertConvertedValue(' foo bar, baz ',
['foo bar',
'baz'])
def test_list_of_values_containing_commas(self):
self.type_instance = types.List(types.String(quotes=True))
self.assertConvertedValue('foo,"bar, baz",bam',
['foo',
'bar, baz',
'bam'])
def test_list_of_lists(self):
self.type_instance = types.List(
types.List(types.String(), bounds=True)
)
self.assertConvertedValue('[foo],[bar, baz],[bam]',
[['foo'], ['bar', 'baz'], ['bam']])
def test_list_of_custom_type(self):
self.type_instance = types.List(types.Integer())
self.assertConvertedValue('1,2,3,5',
[1, 2, 3, 5])
def test_bounds_parsing(self):
self.type_instance = types.List(types.Integer(), bounds=True)
self.assertConvertedValue('[1,2,3]', [1, 2, 3])
def test_bounds_required(self):
self.type_instance = types.List(types.Integer(), bounds=True)
self.assertInvalid('1,2,3')
self.assertInvalid('[1,2,3')
self.assertInvalid('1,2,3]')
def test_repr(self):
t = types.List(types.Integer())
self.assertEqual('List of Integer', repr(t))
def test_equal(self):
self.assertTrue(types.List() == types.List())
def test_equal_with_equal_custom_item_types(self):
it1 = types.Integer()
it2 = types.Integer()
self.assertTrue(types.List(it1) == types.List(it2))
def test_not_equal_with_non_equal_custom_item_types(self):
it1 = types.Integer()
it2 = types.String()
self.assertFalse(it1 == it2)
self.assertFalse(types.List(it1) == types.List(it2))
def test_not_equal_to_other_class(self):
self.assertFalse(types.List() == types.Integer())
class DictTypeTests(TypeTestHelper, unittest.TestCase):
type = types.Dict()
def test_empty_value(self):
self.assertConvertedValue('', {})
def test_single_value(self):
self.assertConvertedValue(' foo: bar ',
{'foo': 'bar'})
def test_dict_of_values(self):
self.assertConvertedValue(' foo: bar, baz: 123 ',
{'foo': 'bar',
'baz': '123'})
def test_custom_value_type(self):
self.type_instance = types.Dict(types.Integer())
self.assertConvertedValue('foo:123, bar: 456',
{'foo': 123,
'bar': 456})
def test_dict_of_values_containing_commas(self):
self.type_instance = types.Dict(types.String(quotes=True))
self.assertConvertedValue('foo:"bar, baz",bam:quux',
{'foo': 'bar, baz',
'bam': 'quux'})
def test_dict_of_dicts(self):
self.type_instance = types.Dict(
types.Dict(types.String(), bounds=True)
)
self.assertConvertedValue('k1:{k1:v1,k2:v2},k2:{k3:v3}',
{'k1': {'k1': 'v1', 'k2': 'v2'},
'k2': {'k3': 'v3'}})
def test_bounds_parsing(self):
self.type_instance = types.Dict(types.String(), bounds=True)
self.assertConvertedValue('{foo:bar,baz:123}',
{'foo': 'bar',
'baz': '123'})
def test_bounds_required(self):
self.type_instance = types.Dict(types.String(), bounds=True)
self.assertInvalid('foo:bar,baz:123')
self.assertInvalid('{foo:bar,baz:123')
self.assertInvalid('foo:bar,baz:123}')
def test_no_mapping_produces_error(self):
self.assertInvalid('foo,bar')
def test_repr(self):
t = types.Dict(types.Integer())
self.assertEqual('Dict of Integer', repr(t))
def test_equal(self):
self.assertTrue(types.Dict() == types.Dict())
def test_equal_with_equal_custom_item_types(self):
it1 = types.Integer()
it2 = types.Integer()
self.assertTrue(types.Dict(it1) == types.Dict(it2))
def test_not_equal_with_non_equal_custom_item_types(self):
it1 = types.Integer()
it2 = types.String()
self.assertFalse(it1 == it2)
self.assertFalse(types.Dict(it1) == types.Dict(it2))
def test_not_equal_to_other_class(self):
self.assertFalse(types.Dict() == types.Integer())
class IPAddressTypeTests(TypeTestHelper, unittest.TestCase):
type = types.IPAddress()
def test_ipv4_address(self):
self.assertConvertedValue('192.168.0.1', '192.168.0.1')
def test_ipv6_address(self):
self.assertConvertedValue('abcd:ef::1', 'abcd:ef::1')
def test_strings(self):
self.assertInvalid('')
self.assertInvalid('foo')
def test_numbers(self):
self.assertInvalid(1)
self.assertInvalid(-1)
self.assertInvalid(3.14)
class IPv4AddressTypeTests(IPAddressTypeTests):
type = types.IPAddress(4)
def test_ipv6_address(self):
self.assertInvalid('abcd:ef::1')
class IPv6AddressTypeTests(IPAddressTypeTests):
type = types.IPAddress(6)
def test_ipv4_address(self):
self.assertInvalid('192.168.0.1')

View File

@ -1,61 +0,0 @@
# 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 imp
import os
import warnings
import mock
from oslotest import base as test_base
import six
class DeprecationWarningTest(test_base.BaseTestCase):
@mock.patch('warnings.warn')
def test_warning(self, mock_warn):
import oslo.config
imp.reload(oslo.config)
self.assertTrue(mock_warn.called)
args = mock_warn.call_args
self.assertIn('oslo_config', args[0][0])
self.assertIn('deprecated', args[0][0])
self.assertTrue(issubclass(args[0][1], DeprecationWarning))
def test_real_warning(self):
with warnings.catch_warnings(record=True) as warning_msgs:
warnings.resetwarnings()
warnings.simplefilter('always', DeprecationWarning)
import oslo.config
# Use a separate function to get the stack level correct
# so we know the message points back to this file. This
# corresponds to an import or reload, which isn't working
# inside the test under Python 3.3. That may be due to a
# difference in the import implementation not triggering
# warnings properly when the module is reloaded, or
# because the warnings module is mostly implemented in C
# and something isn't cleanly resetting the global state
# used to track whether a warning needs to be
# emitted. Whatever the cause, we definitely see the
# warnings.warn() being invoked on a reload (see the test
# above) and warnings are reported on the console when we
# run the tests. A simpler test script run outside of
# testr does correctly report the warnings.
def foo():
oslo.config.deprecated()
foo()
self.assertEqual(1, len(warning_msgs))
msg = warning_msgs[0]
self.assertIn('oslo_config', six.text_type(msg.message))
self.assertEqual('test_warning.py', os.path.basename(msg.filename))