
    `fb                     X   d Z ddlZddlmZ ddlmZmZmZmZm	Z	 ddl
Z
erddlmZ ddlmZ nexZZej                            d          Zd	 Ze	 	 	 dd            Z e
j        d          d             Z e
j        d          d             Z e
j        d          d             Z e
j        d          d             Z e
j        d          d             Z e
j        d          d             Z e
j        d          d             Z e
j        d          d             Z e
j        d          d             Z e
j                    d             Z e
j        d          d             Z  e
j                    d             Z! e
j                    d             Z"dS )z;Fixtures and testing utilities for :pypi:`pytest <pytest>`.    N)contextmanager)TYPE_CHECKINGAnyMappingSequenceUnion)Celery   )WorkController	NO_WORKERc                 2    |                      dd           dS )z)Register additional pytest configuration.markerszBcelery(**overrides): override celery configuration for a test caseN)addinivalue_line)configs    G/var/www/html/env/lib/python3.11/site-packages/celery/contrib/pytest.pypytest_configurer      s,    
 W        Fc              +      K   ddl m}m} |si n|} |dd| |d|} |||          5  |V  ddd           dS # 1 swxY w Y   dS )z=Utility context used to setup Celery app for pytest fixtures.   )TestAppsetup_default_appF)set_as_currentenable_loggingr   )use_trapN )testing.appr   r   )r   r   
parametersr   r   r   test_apps          r   _create_appr       s       87777777%5:Jw %  	 H 
	8h	7	7	7                   s   <A A session)scopec                      dS )zYou 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   use_celery_app_trapr#   5   s	     5r   c              #     K   | j                             d          }t          |fi |r|j        ni }t	          d|||d|5 }|s(|                                 |                                 |V  ddd           dS # 1 swxY w 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   apps           r   celery_session_appr4   @   s       <**844D-??$#>4;;B??F	 
$91 1
 
 
 
  #&" 	OOOO			                 s   /A??BBc              #      K   ddl m} t          sh|D ]}|j                            |           |D ]}|                    |            |j        |fd|i|5 }	|	V  ddd           dS # 1 swxY w Y   dS dS )z?Session Fixture: Start worker that lives throughout test suite.r   workerpoolN)testingr7   r   loaderimport_task_moduleregister_taskstart_worker)
r.   r4   celery_includescelery_class_taskscelery_worker_poolcelery_worker_parametersr7   module
class_taskws
             r   celery_session_workerrE   T   s        % 	A 	AF%88@@@@, 	9 	9J,,Z8888 V !3 = =&8=#;= = 	@AGGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   A++A/2A/c                      dS )z0You can override this fixture to enable logging.Fr   r   r   r   r1   r1   l   s	     5r   c                      dS )zYou 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>   r>   s   s	     2r   c                      dS )zYou 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@   r@   ~   s	     6r   c                      i S )zRedefine 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/      	     Ir   c                      i S )zRedefine 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   r0   r0      rK   r   c                      i S )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   rA   rA      s	     Ir   c              #      K   | j                             d          }t          |fi |r|j        ni }t	          d|||d|5 }|V  ddd           dS # 1 swxY w Y   dS )z/Fixture creating a Celery application instance.r%   r&   Nr   )r'   r(   r)   r*   r   r-   s           r   
celery_apprO      s       <**844D-??$#>4;;B??F	 
$91 1
 
 
 
  #&				                 s   AAAc                      g S )zARedefine this fixture to register tasks with the test Celery app.r   r   r   r   r?   r?      s	     Ir   c              #      K   ddl m} t          sN|D ]}|j                            |            |j        |fd|i|5 }|V  ddd           dS # 1 swxY w Y   dS dS )zAFixture: Start worker in a thread, stop it when the test returns.r   r6   r8   N)r9   r7   r   r:   r;   r=   )r.   rO   r>   r@   rA   r7   rB   rD   s           r   celery_workerrR      s         % 	9 	9F008888 V  = =&8=#;= = 	@AGGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   AAAc                 .    |                                   dS )z!Fixture that sets app as current.N)r,   )rO   s    r   depends_on_current_apprT      s     r   )FFN)#__doc__os
contextlibr   typingr   r   r   r   r   pytestr%   r	   r7   r   objectenvirongetr   r   r   fixturer#   r4   rE   r1   r>   r@   r/   r0   rA   rO   r?   rR   rT   r   r   r   <module>r^      s	   A A 				 % % % % % % ? ? ? ? ? ? ? ? ? ? ? ? ? ?  %'''''''$$F^ JNN;''	   $   ( i     !  i     ! & i     ! . i     !  i     !  i     !  i     !  i     !  i   	 	 ! 	    i     ! 
   $     r   