o
    Rh                     @   sF   d dl Z d dlmZ d dlmZmZmZmZmZ G dd de j	Z
dS )    N)patch)
clear_tagsget_tagsnew_contextscopedtagc                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zeddd Z	eddd Z
eddd ZdS )
TestScopesc                 C   s
   t   d S )N)r   self r   Z/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/posthog/test/test_scopes.pysetUp   s   
zTestScopes.setUpc                 C   s>   t dd t dd t }|d dksJ |d dksJ d S )Nkey1value1key2   )r   r   )r
   tagsr   r   r   test_tag_and_get_tags   s
   

z TestScopes.test_tag_and_get_tagsc                 C   s4   t dd t d dksJ t  t i ksJ d S )Nr   r   )r   r   r   r	   r   r   r   test_clear_tags   s   
zTestScopes.test_clear_tagsc                 C   s   t dd tdd$ t i ksJ t dd t d dks J | dt  W d    n1 s1w   Y  tdd t ddiksEJ W d    n1 sOw   Y  | dt  t d dksdJ d S )NoutervalueTfreshinnerF)r   r   r   assertNotInr	   r   r   r   test_new_context_isolation   s   

z%TestScopes.test_new_context_isolationc              	   C   s   t dd tdd9 t dd tdd t dd t ddiks$J W d    n1 s.w   Y  t ddiks<J W d    n1 sFw   Y  t ddiksTJ d S )	Nlevel1r   Tr   level2value2level3value3)r   r   r   r	   r   r   r   test_nested_contexts4   s   


zTestScopes.test_nested_contextszposthog.capture_exceptionc                 C   s>   t  dd }|dd}|dksJ |  t i ksJ d S )Nc                 S   s   t d|  t d| | | S )Nxyr   )r"   r#   r   r   r   successful_functionF   s   

zETestScopes.test_scoped_decorator_success.<locals>.successful_function   r      )r   assert_not_calledr   )r
   mock_capturer%   resultr   r   r   test_scoped_decorator_successD   s   

z(TestScopes.test_scoped_decorator_successc                    st   t d dd }||_t  fdd}| t  |  W d    n1 s'w   Y  |  t i ks8J d S )NzTest exceptionc                 [      t  }|ddksJ d S Nimportant_contextr   r   get	exceptionkwargscurrent_tagsr   r   r   check_context_on_capture[      zLTestScopes.test_scoped_decorator_exception.<locals>.check_context_on_capturec                      s   t dd  r-   r$   r   test_exceptionr   r   failing_functionb   s   
zDTestScopes.test_scoped_decorator_exception.<locals>.failing_function)
ValueErrorside_effectr   assertRaisesassert_called_once_withr   )r
   r)   r5   r9   r   r7   r   test_scoped_decorator_exceptionW   s   
z*TestScopes.test_scoped_decorator_exceptionc                 C   s~   t d}dd }||_tdd zt  tdd |1 sw   Y  W n	 t y.   Y nw || t d dks=J d S )NzContext exceptionc                 [   r,   )Ninner_contextinner_valuer/   r1   r   r   r   r5   u   r6   zPTestScopes.test_new_context_exception_handling.<locals>.check_context_on_captureouter_contextouter_valuer?   r@   )RuntimeErrorr;   r   r   r=   r   )r
   r)   r8   r5   r   r   r   #test_new_context_exception_handlingq   s   


z.TestScopes.test_new_context_exception_handlingN)__name__
__module____qualname__r   r   r   r   r!   r   r+   r>   rD   r   r   r   r   r      s    

r   )unittestunittest.mockr   posthog.scopesr   r   r   r   r   TestCaser   r   r   r   r   <module>   s    