
    ce#                     B    d dl Z d dlmZ  G d de j                        Zy)    N)cfgc                        e Zd ZdZej
                  fdZ fdZd Zd Z	d Z
d ZddZdd	Zdd
ZddZddZd Zd ZddZ xZS )ConfigzbAllows overriding configuration settings for the test.

    `conf` will be reset on cleanup.

    c                     || _         y N)conf)selfr   s     5/usr/lib/python3/dist-packages/oslo_config/fixture.py__init__zConfig.__init__   s	    	    c                    t         t        |           | j                  | j                         | j                  | j
                         | j                  | j                         | j                  | j                  j                         i | _	        t        | j                  d      r| j                  j                  | _        nd | _        t        | j                  d      r| j                  j                  | _        y d | _        y )Ndefault_config_filesdefault_config_dirs)superr   setUp
addCleanup_reset_default_config_files_reset_default_config_dirs_unregister_config_optsr   reset_registered_config_optshasattrr   _default_config_filesr   _default_config_dirs)r	   	__class__s    r
   r   zConfig.setUp!   s    fd!# 	889778445		(')$ 49945)-)G)GD&)-D&49934(,		(E(ED%(,D%r   c                     |j                  dd      }|j                         D ]"  \  }}| j                  j                  |||       $ y)aU  Override configuration values.

        The keyword arguments are the names of configuration options to
        override and their values.

        If a `group` argument is supplied, the overrides are applied to
        the specified configuration option group, otherwise the overrides
        are applied to the ``default`` group.

        groupN)popitemsr   set_override)r	   kwr   kvs        r
   configzConfig.config8   sC     w%HHJ 	0DAqII""1a/	0r   c                 z    | j                   D ],  }| j                  j                  | j                   |   |       . y )Nr   )r   r   unregister_opts)r	   r   s     r
   r   zConfig._unregister_config_optsH   s>    11 	3EII%%d&B&B5&I,1 & 3	3r   c                     t        | j                  d      sy | j                  r| j                  | j                  _        y d | j                  _        y )Nr   )r   r   r   r   r	   s    r
   r   z"Config._reset_default_config_filesM   s=    tyy"89%%-1-G-GDII* .2DII*r   c                     t        | j                  d      sy | j                  r| j                  | j                  _        y d | j                  _        y )Nr   )r   r   r   r   r)   s    r
   r   z!Config._reset_default_config_dirsX   s=    tyy"78$$,0,E,EDII) -1DII)r   c                     | j                   j                  ||       | j                  j                  |t	                     j                  |       y)aA  Register a single option for the test run.

        Options registered in this manner will automatically be unregistered
        during cleanup.

        If a `group` argument is supplied, it will register the new option
        to that group, otherwise the option is registered to the ``default``
        group.
        r&   N)r   register_optr   
setdefaultsetaddr	   optr   s      r
   r,   zConfig.register_optc   s>     			s%0$$//su=AA#Fr   c                 8    |D ]  }| j                  ||        y)aU  Register multiple options for the test run.

        This works in the same manner as register_opt() but takes a list of
        options as the first argument. All arguments will be registered to the
        same group if the ``group`` argument is supplied, otherwise all options
        will be registered to the ``default`` group.
        r&   N)r,   r	   optsr   r1   s       r
   register_optszConfig.register_optsp   s&      	0Cc/	0r   c                     | j                   j                  ||       | j                  j                  |t	                     j                  |       y)a  Register a single CLI option for the test run.

        Options registered in this manner will automatically be unregistered
        during cleanup.

        If a `group` argument is supplied, it will register the new option
        to that group, otherwise the option is registered to the ``default``
        group.

        CLI options must be registered before the command line and config files
        are parsed. This is to ensure that all CLI options are shown in --help
        and option validation works as expected.
        r&   N)r   register_cli_optr   r-   r.   r/   r0   s      r
   r7   zConfig.register_cli_opt{   s>     			""3e"4$$//su=AA#Fr   c                 8    |D ]  }| j                  ||        y)a*  Register multiple CLI options for the test run.

        This works in the same manner as register_opt() but takes a list of
        options as the first argument. All arguments will be registered to the
        same group if the ``group`` argument is supplied, otherwise all options
        will be registered to the ``default`` group.

        CLI options must be registered before the command line and config files
        are parsed. This is to ensure that all CLI options are shown in --help
        and option validation works as expected.
        r&   N)r7   r3   s       r
   register_cli_optszConfig.register_cli_opts   s&      	4C!!#U!3	4r   c                 D   | j                   j                  s| j                   j                  g        |sdn|}t               }t               ||<   |j	                         D ]  \  }}t        |      g||   |<    | j                   j                  j                  d||       y)aq  Load raw values into the configuration without registering them.

        This method adds a series of parameters into the current config
        instance, as if they had been loaded by a ConfigParser. This method
        does not require that you register the configuration options first,
        however the values loaded will not be accessible until you do.
        argsDEFAULTz<memory>N)r   
_namespace__call__dictr   str_add_parsed_config_file)r	   r   kwargs
raw_configkeyvalues         r
   load_raw_valueszConfig.load_raw_values   s     yy##IIB' "'	EV
 F
5 ,,. 	2JC&)%j\Juc"	2 			44
J	0r   c                     t        |t              st        d      | j                  j                  s| j                  j                  g        || j                  _        | j                  j                          y)a9  Specify a list of config files to read.

        This method allows you to predefine the list of configuration files
        that are loaded by oslo_config. It will ensure that your tests do not
        attempt to autodetect, and accidentally pick up config files from
        locally installed services.
        z*Please pass a list() to set_config_files()r;   N)
isinstancelistAttributeErrorr   r>   r?   r   reload_config_files)r	   config_filess     r
   set_config_fileszConfig.set_config_files   sZ     ,- !MNN yy##IIB')5		&		%%'r   c                     t        |t              st        d      | j                  j                  s| j                  g        || j                  _        | j                  j                          y)a7  Specify a list of config dirs to read.

        This method allows you to predefine the list of configuration dirs
        that are loaded by oslo_config. It will ensure that your tests do not
        attempt to autodetect, and accidentally pick up config files from
        locally installed services.
        z)Please pass a list() to set_config_dirs()N)rI   rJ   rK   r   r>   r   rL   )r	   config_dirss     r
   set_config_dirszConfig.set_config_dirs   sP     +t, !LMM yy##IIbM(3		%		%%'r   c                     | j                   j                  |||       | j                  | j                   j                  ||       y)a  Set a default value for an option.

        This method is not necessarily meant to be invoked
        directly. It is here to allow the set_defaults() functions in
        various Oslo libraries to work with a Config fixture instead
        of a ConfigOpts instance.

        Use it like::

            class MyTest(testtools.TestCase):

                def setUp(self):
                    super(MyTest, self).setUp()
                    self.conf = self.useFixture(fixture.Config())

                def test_something(self):
                    some_library.set_defaults(self.conf, name='value')
                    some_library.do_something_exciting()

        N)r   set_defaultr   clear_default)r	   namedefaultr   s       r
   rS   zConfig.set_default   s4    * 			dGU3		//u=r   r   )__name__
__module____qualname____doc__r   CONFr   r   r$   r   r   r   r,   r5   r7   r9   rG   rN   rQ   rS   __classcell__)r   s   @r
   r   r      sY      HH -.0 3
	2	1G	0G"402($($>r   r   )fixturesoslo_configr   Fixturer    r   r
   <module>ra      s!   $  W>X W>r   