o
    wvXj˜  ã                   @   s\  d Z ddlmZmZ ddlZddlmZ ddlZddlm	Z	 ddl
mZmZ ej d¡Zd	d
„ Ze			d(dd„ƒZejdd�dd„ ƒZejdd�dd„ ƒZejdd�dd„ ƒZejdd�dd„ ƒZejdd�dd„ ƒZejdd�dd„ ƒZejdd�dd„ ƒZejdd�dd„ ƒZejdd�d d!„ ƒZe ¡ d"d#„ ƒZe ¡ d$d%„ ƒZe ¡ d&d'„ ƒZdS ))z<Fixtures and testing utilities for :pypi:`py.test <pytest>`.é    )Úabsolute_importÚunicode_literalsN)Úcontextmanageré   )Úworker©ÚTestAppÚsetup_default_appÚ	NO_WORKERc                 C   s   |   dd¡ dS )z)Register additional pytest configuration.ÚmarkerszBcelery(**overrides): override celery configuration for a test caseN)Úaddinivalue_line)Úconfig© r   úR/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/contrib/pytest.pyÚpytest_configure   s   ÿr   Fc                 k   s\   � |si n|}t dd| |dœ|¤Ž}t||d�� |V  W d  ƒ dS 1 s'w   Y  dS )z=Utility context used to setup Celery app for pytest fixtures.F)Úset_as_currentÚenable_loggingr   )Úuse_trapNr   r   )r   r   Ú
parametersr   Útest_appr   r   r   Ú_create_app   s   €ýü"ÿr   Úsession)Úscopec                   C   ó   dS )z¤You can override this fixture to enable the app trap.

    The app trap raises an exception whenever something attempts
    to use the current or default apps.
    Fr   r   r   r   r   Úuse_celery_app_trap.   ó   r   c                 c   s~   � | j  d¡}t|fi |r|jni ¤Ž}td|||dœ|¤Ž�}|s*| ¡  | ¡  |V  W d  ƒ dS 1 s8w   Y  dS )z1Session Fixture: Return app for session fixtures.Úcelery©r   r   r   Nr   )ÚnodeÚget_closest_markerÚdictÚkwargsr   Úset_defaultÚset_current©ÚrequestÚcelery_configÚcelery_parametersÚcelery_enable_loggingr   Úmarkr   Úappr   r   r   Úcelery_session_app9   s   €þý"ùr+   c                 c   ób   � t s/|D ]}|j |¡ qtj|fd|i|¤Ž�}|V  W d  ƒ dS 1 s(w   Y  dS dS )z?Session Fixture: Start worker that lives throughout test suite.ÚpoolN©r
   ÚloaderÚimport_task_moduler   Ústart_worker)r%   r+   Úcelery_includesÚcelery_worker_poolÚcelery_worker_parametersÚmoduleÚwr   r   r   Úcelery_session_workerM   ó   €
ÿþ"ýýr7   c                   C   r   )z0You can override this fixture to enable logging.Fr   r   r   r   r   r(   ^   s   r(   c                   C   r   )zÆYou can override this include modules when a worker start.

    You can have this return a list of module names to import,
    these can be task modules, modules registering signals, and so on.
    r   r   r   r   r   r   r2   e   r   r2   c                   C   r   )z–You can override this fixture to set the worker pool.

    The "solo" pool is used by default, but you can set this to
    return e.g. "prefork".
    Úsolor   r   r   r   r   r3   p   r   r3   c                   C   ó   i S )z¨Redefine this fixture to configure the test Celery app.

    The config returned by your fixture will then be used
    to configure the :func:`celery_app` fixture.
    r   r   r   r   r   r&   {   r   r&   c                   C   r:   )zÃRedefine this fixture to change the init parameters of test Celery app.

    The dict returned by your fixture will then be used
    as parameters when instantiating :class:`~celery.Celery`.
    r   r   r   r   r   r'   †   r   r'   c                   C   r:   )a"  Redefine this fixture to change the init parameters of Celery workers.

    This can be used e. g. to define queues the worker will consume tasks from.

    The dict returned by your fixture will then be used
    as parameters when instantiating :class:`~celery.worker.WorkController`.
    r   r   r   r   r   r4   ‘   s   
r4   c                 c   sj   � | j  d¡}t|fi |r|jni ¤Ž}td|||dœ|¤Ž�}|V  W d  ƒ dS 1 s.w   Y  dS )z/Fixture creating a Celery application instance.r   r   Nr   )r   r   r    r!   r   r$   r   r   r   Ú
celery_appž   s   €þý"ür;   c                 c   r,   )zAFixture: Start worker in a thread, stop it when the test returns.r-   Nr.   )r%   r;   r2   r3   r4   r5   r6   r   r   r   Úcelery_worker®   r8   r<   c                 C   s   |   ¡  dS )z!Fixture that sets app as current.N)r#   )r;   r   r   r   Údepends_on_current_app¿   s   r=   )FFN)Ú__doc__Ú
__future__r   r   ÚosÚ
contextlibr   ÚpytestÚtestingr   Útesting.appr   r	   ÚenvironÚgetr
   r   r   Úfixturer   r+   r7   r(   r2   r3   r&   r'   r4   r;   r<   r=   r   r   r   r   Ú<module>   sL    
þ
























