This file is indexed.

/usr/lib/python3/dist-packages/oslo_config/tests/test_fixture.py is in python3-oslo.config 1:3.9.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#
# 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

    def test_overridden_value(self):
        f = self._make_fixture()
        self.assertEqual(f.conf.get('testing_option'), 'initial_value')
        f.config(testing_option='changed_value')
        self.assertEqual('changed_value',
                         f.conf.get('testing_option'))

    def test_cleanup(self):
        f = self._make_fixture()
        f.config(testing_option='changed_value')
        self.assertEqual(f.conf.get('testing_option'),
                         'changed_value')
        f.conf.reset()
        self.assertEqual(f.conf.get('testing_option'), 'initial_value')

    def test_register_option(self):
        f = self._make_fixture()
        opt = cfg.StrOpt('new_test_opt', default='initial_value')
        f.register_opt(opt)
        self.assertEqual(f.conf.get('new_test_opt'),
                         opt.default)

    def test_register_options(self):
        f = 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(f.conf.get('first_test_opt'), opt1.default)
        self.assertEqual(f.conf.get('second_test_opt'), opt2.default)

    def test_cleanup_unregister_option(self):
        f = self._make_fixture()
        opt = cfg.StrOpt('new_test_opt', default='initial_value')
        f.register_opt(opt)
        self.assertEqual(f.conf.get('new_test_opt'),
                         opt.default)
        f.cleanUp()
        self.assertRaises(cfg.NoSuchOptError, f.conf.get, 'new_test_opt')

    def test_register_cli_option(self):
        f = self._make_fixture()
        opt = cfg.StrOpt('new_test_opt', default='initial_value')
        f.register_cli_opt(opt)
        self.assertEqual(f.conf.get('new_test_opt'),
                         opt.default)

    def test_register_cli_options(self):
        f = 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(f.conf.get('first_test_opt'), opt1.default)
        self.assertEqual(f.conf.get('second_test_opt'), opt2.default)

    def test_cleanup_unregister_cli_option(self):
        f = self._make_fixture()
        opt = cfg.StrOpt('new_test_opt', default='initial_value')
        f.register_cli_opt(opt)
        self.assertEqual(f.conf.get('new_test_opt'),
                         opt.default)
        f.cleanUp()
        self.assertRaises(cfg.NoSuchOptError, f.conf.get, 'new_test_opt')

    def test_load_raw_values(self):
        f = 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, f.conf.get, 'first_test_opt')
        self.assertRaises(cfg.NoSuchOptError, f.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(f.conf.first_test_opt, 'loaded_value_1')
        self.assertEqual(f.conf.second_test_opt, 'loaded_value_2')

        # Cleanup.
        f.cleanUp()

        # Must no longer be registered.
        self.assertRaises(cfg.NoSuchOptError, f.conf.get, 'first_test_opt')
        self.assertRaises(cfg.NoSuchOptError, f.conf.get, 'second_test_opt')

        # Even when registered, must be default.
        f.register_opt(opt1)
        f.register_opt(opt2)
        self.assertEqual(f.conf.first_test_opt, 'initial_value_1')
        self.assertEqual(f.conf.second_test_opt, 'initial_value_2')

    def test_assert_default_files_cleanup(self):
        """Assert that using the fixture forces a clean list."""
        f = self._make_fixture()
        self.assertNotIn('default_config_files', f.conf)

        config_files = ['./test_fixture.conf']
        f.set_config_files(config_files)

        self.assertEqual(f.conf.default_config_files, config_files)
        f.cleanUp()

        self.assertNotIn('default_config_files', f.conf)

    def test_load_custom_files(self):
        f = self._make_fixture()
        self.assertNotIn('default_config_files', f.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', f.conf.get('first_test_opt'))
        self.assertEqual('loaded_value_2', f.conf.get('second_test_opt'))

    def test_set_default(self):
        f = self._make_fixture()
        opt = cfg.StrOpt('new_test_opt', default='initial_value')
        # Register the option directly so it is not cleaned up by the
        # fixture.
        f.conf.register_opt(opt)
        f.set_default(
            name='new_test_opt',
            default='alternate_value',
        )
        self.assertEqual('alternate_value', f.conf.new_test_opt)
        f.cleanUp()
        self.assertEqual('initial_value', f.conf.new_test_opt)

    def test_set_default_group(self):
        f = self._make_fixture()
        opt = cfg.StrOpt('new_test_opt', default='initial_value')
        # Register the option directly so it is not cleaned up by the
        # fixture.
        f.conf.register_opt(opt, group='foo')
        f.set_default(
            name='new_test_opt',
            default='alternate_value',
            group='foo',
        )
        self.assertEqual('alternate_value', f.conf.foo.new_test_opt)
        f.cleanUp()
        self.assertEqual('initial_value', f.conf.foo.new_test_opt)