
    \e\                         d Z ddlZddlZddlmZ ddlmZ  G d dej                        Z G d de      Z	 e	       Z
 e	d	
      Zy)z'
Test fixtures.

.. versionadded:: 1.3
    N)	timeutils)	uuidutilsc                   :     e Zd ZdZd fd	Z fdZd Zd Z xZS )TimeFixturezA fixture for overriding the time returned by timeutils.utcnow().

    :param override_time: datetime instance or list thereof. If not given,
                          defaults to the current UTC time.

    c                 8    t         t        |           || _        y N)superr   __init___override_time)selfoverride_time	__class__s     4/usr/lib/python3/dist-packages/oslo_utils/fixture.pyr
   zTimeFixture.__init__'   s    k4)++    c                     t         t        |           t        j                  | j
                         | j                  t        j                         y r   )r	   r   setUpr   set_time_overrider   
addCleanupclear_time_override)r   r   s    r   r   zTimeFixture.setUp+   s6    k4&(##D$7$78	556r   c                 .    t        j                  |       y)z3Advance overridden time using a datetime.timedelta.N)r   advance_time_delta)r   	timedeltas     r   r   zTimeFixture.advance_time_delta0   s    $$Y/r   c                 .    t        j                  |       y)z#Advance overridden time by seconds.N)r   advance_time_seconds)r   secondss     r   r   z TimeFixture.advance_time_seconds4   s    &&w/r   r   )	__name__
__module____qualname____doc__r
   r   r   r   __classcell__)r   s   @r   r   r      s    ,7
00r   r   c                       e Zd ZdZddZd Zy)_UUIDSentinelsa  Registry of dynamically created, named, random UUID strings in regular
    (with hyphens) and similar to some keystone IDs (without hyphens) formats.

    An instance of this class will dynamically generate attributes as they are
    referenced, associating a random UUID string with each. Thereafter,
    referring to the same attribute will give the same UUID for the life of the
    instance. Plan accordingly.

    Usage::

        from oslo_utils.fixture import uuidsentinel as uuids
        from oslo_utils.fixture import keystoneidsentinel as keystids
        ...
        foo = uuids.foo
        do_a_thing(foo)
        # Referencing the same sentinel again gives the same value
        assert foo == uuids.foo
        # But a different one will be different
        assert foo != uuids.bar
        # Same approach is valid for keystoneidsentinel:
        data = create_some_data_structure(keystids.bar, var1, var2, var3)
        assert extract_bar(data) == keystids.bar
    c                 R    i | _         t        j                         | _        || _        y r   )
_sentinels	threadingLock_lock	is_dashed)r   r(   s     r   r
   z_UUIDSentinels.__init__Q   s    ^^%
"r   c                    |j                  d      rt        d      | j                  5  || j                  vr-t	        j
                  | j                        | j                  |<   d d d        | j                  |   S # 1 sw Y   xY w)N_zSentinels must not start with _)dashed)
startswithAttributeErrorr'   r$   r   generate_uuidr(   )r   names     r   __getattr__z_UUIDSentinels.__getattr__V   ss    ??3 !BCCZZ 	+4??*(1(?(?>>)+%	+ t$$		+ 	+s   <A<<BN)T)r   r   r   r   r
   r0    r   r   r"   r"   9   s    .#
%r   r"   F)r(   )r   r%   fixtures
oslo_utilsr   r   Fixturer   objectr"   uuidsentinelkeystoneidsentinelr1   r   r   <module>r8      sL   "      0("" 04$%V $%T #e4 r   