Coverage for manila/tests/test_conf.py: 100%
41 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2010 United States Government as represented by the
2# Administrator of the National Aeronautics and Space Administration.
3# All Rights Reserved.
4# Copyright 2011 Red Hat, Inc.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
18from oslo_config import cfg
21from manila import test
23CONF = cfg.CONF
24CONF.register_opt(cfg.StrOpt('conf_unittest',
25 default='foo',
26 help='for testing purposes only'))
29class ConfigTestCase(test.TestCase):
31 def test_declare(self):
32 self.assertNotIn('answer', CONF)
33 CONF.import_opt('answer', 'manila.tests.declare_conf')
34 self.assertIn('answer', CONF)
35 self.assertEqual(42, CONF.answer)
37 # Make sure we don't overwrite anything
38 CONF.set_override('answer', 256)
39 self.assertEqual(256, CONF.answer)
40 CONF.import_opt('answer', 'manila.tests.declare_conf')
41 self.assertEqual(256, CONF.answer)
43 def test_runtime_and_unknown_flags(self):
44 self.assertNotIn('runtime_answer', CONF)
45 import manila.tests.runtime_conf # noqa
46 self.assertIn('runtime_answer', CONF)
47 self.assertEqual(54, CONF.runtime_answer)
49 def test_long_vs_short_flags(self):
50 CONF.clear()
51 CONF.register_cli_opt(cfg.StrOpt('duplicate_answer_long',
52 default='val',
53 help='desc'))
54 CONF.register_cli_opt(cfg.IntOpt('duplicate_answer',
55 default=50,
56 help='desc'))
58 argv = ['--duplicate_answer=60']
59 CONF(argv, default_config_files=[])
60 self.assertEqual(60, CONF.duplicate_answer)
61 self.assertEqual('val', CONF.duplicate_answer_long)
63 def test_flag_leak_left(self):
64 self.assertEqual('foo', CONF.conf_unittest)
65 self.flags(conf_unittest='bar')
66 self.assertEqual('bar', CONF.conf_unittest)
68 def test_flag_leak_right(self):
69 self.assertEqual('foo', CONF.conf_unittest)
70 self.flags(conf_unittest='bar')
71 self.assertEqual('bar', CONF.conf_unittest)
73 def test_flag_overrides(self):
74 self.assertEqual('foo', CONF.conf_unittest)
75 self.flags(conf_unittest='bar')
76 self.assertEqual('bar', CONF.conf_unittest)
77 CONF.reset()
78 self.assertEqual('foo', CONF.conf_unittest)