
    DIe                       d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ dZ	 	 	 d5d6dZ	 d7d8d"Zd9d(Zd:d)Z G d* d+          Z	 	 d;d<d.Z G d/ d0          Z d=d4Z!dS )>z;Collection of helper functions used in conda.notices tests.    )annotationsN)chain)Path)Sequence)mock)Context)get_channel_objs)get_notices_cache_file)get_channel_name_and_urls)ChannelNoticeResponsez:Here is an example message that will be displayed to usersinfomessagesSequence[str]level
str | None
created_atdatetime.datetime | None
expired_atreturndictc                    p-t           j                             t           j        j                  pt          j        d          z   dfd| D             iS )N   )daysnoticesc                    g | ]L}t          t          j                              |                                                                d MS ))idmessager   r   r   )struuiduuid4	isoformat).0r   r   r   r   s     =lib/python3.11/site-packages/conda/testing/notices/helpers.py
<listcomp>z$get_test_notices.<locals>.<listcomp>"   sg     	
 	
 	
  $*,,''"(2244(2244 	
 	
 	
    )datetimenowtimezoneutc	timedelta)r   r   r   r   s    ```r#   get_test_noticesr+      s     Kx044X5F5JKKJFzH,>A,F,F,FFJ 	 	
 	
 	
 	
 	
 	
 $	
 	
 	
 r%   Fmock_sessionmock.MagicMockstatus_codeintmessages_json	raise_excboolNonec                    d }fd}t           |             |                      t          fdt          d          D                        |             j        _        dS )zCAdds any number of MockResponse to MagicMock object as side_effectsc               3  .   K   	 t          di           V  )NTi  MockResponse r%   r#   forever_404z%add_resp_to_mock.<locals>.forever_4047   s&      	(sB'''''	(r%   c               3  4   K   t                     V  d S )N)r1   r6   )r0   r1   r.   s   r#   one_200z!add_resp_to_mock.<locals>.one_200;   s(      ;KKKKKKKKr%   c              3  6   K   | ]}t                    V  d S N)next)r"   _chns     r#   	<genexpr>z#add_resp_to_mock.<locals>.<genexpr>?   s)      *I*I499*I*I*I*I*I*Ir%   d   N)r   tuplerangegetside_effect)r,   r.   r0   r1   r9   r;   r@   s    ```  @r#   add_resp_to_mockrG   /   s    ( ( (L L L L L L L 		;;==
)
)C%**I*I*I*IeCjj*I*I*I%I%ILLNN"""r%   	cache_dirr   cache_filesmessages_json_seqSequence[dict]c                    t          ||          D ]Z\  }}|                     |                              d          5 }t          j        ||           ddd           n# 1 swxY w Y   [dS )z,Creates the cache files that we use in testswN)zipjoinpathopenjsondump)rH   rI   rJ   message_jsonfilefps         r#   create_notice_cache_filesrV   B   s     ""3[AA ( (d%%**3// 	(2IlB'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(( (s   A  A$	'A$	c                    t                      }t          j        ||                                j        |                                j        | z
  f           dS )z
    Allows for offsetting the mtime of the notices cache file. This is often
    used to mock an older creation time the cache file.
    )timesN)r
   osutimestatst_atimest_mtime)mtime_offset
cache_files     r#   offset_cache_file_mtimer`   M   s\    
 ())JH  ):??+<+<+E+TU     r%   c                      e Zd ZdZd ZdS )	DummyArgsz7Dummy object that sets all kwargs as object properties.c                j    d| _         |                                D ]\  }}t          | ||           d S )NT)no_ansi_colorsitemssetattr)selfkwargskeyvals       r#   __init__zDummyArgs.__init__\   sD    " 	$ 	$HCD#s####	$ 	$r%   N)__name__
__module____qualname____doc__rk   r8   r%   r#   rb   rb   Y   s)        AA$ $ $ $ $r%   rb   
dummy_mesgnot_inc                r    | j         dk    sJ || j        v sJ |D ]}|r|| j        vsJ || j        v sJ dS )zc
    Tests a run of notices decorator where we expect to see the messages
    print to stdout.
     N)errout)capturedr   rp   rq   mesgs        r#   *notices_decorator_assert_message_in_stdoutrx   c   sw     <2%%%% ( ( 	(x|+++++8<'''''	( (r%   c                      e Zd ZddZd ZdS )r7   Fc                0    || _         || _        || _        d S r=   )r.   	json_datar1   )rg   r.   r{   r1   s       r#   rk   zMockResponse.__init__x   s    &""r%   c                <    | j         rt          d          | j        S )NError)r1   
ValueErrorr{   )rg   s    r#   rQ   zMockResponse.json}   s"    > 	&W%%%~r%   NF)rl   rm   rn   rk   rQ   r8   r%   r#   r7   r7   w   s7        # # # #
    r%   r7   ctxr   
tuple[str]c                l    t          t          |                     }t          d |D                       S )zBReturns the filenames of the cache files that will be searched forc              3  j   K   | ].\  }}t          j        |t          d                     j        V  /dS )rs   N)r   get_cache_keyr   name)r"   urlr   s      r#   rA   z-get_notice_cache_filenames.<locals>.<genexpr>   sP        C 	+Cb::?     r%   )r   r	   rC   )r   channel_urls_and_namess     r#   get_notice_cache_filenamesr      sG    67G7L7LMM  /     r%   )r   NN)
r   r   r   r   r   r   r   r   r   r   r   )
r,   r-   r.   r/   r0   r   r1   r2   r   r3   )rH   r   rI   r   rJ   rK   r   r3   )r   r3   )NF)r   r   rp   r   rq   r2   )r   r   r   r   )"ro   
__future__r   r&   rQ   rY   r   	itertoolsr   pathlibr   typingr   unittestr   conda.base.contextr   conda.models.channelr	   conda.notices.cacher
   conda.notices.corer   conda.notices.typesr   DEFAULT_NOTICE_MESGr+   rG   rV   r`   rb   rx   r7   r   r8   r%   r#   <module>r      s   B A " " " " " "   				                          & & & & & & 1 1 1 1 1 1 6 6 6 6 6 6 8 8 8 8 8 8 5 5 5 5 5 5R 
 +/+/	    6 	J J J J J&( ( ( (	 	 	 	$ $ $ $ $ $ $ $ "	( ( ( ( ((	 	 	 	 	 	 	 	     r%   