o
    ҷh                     @  s  d dl mZ d dlZd dlZd dlmZ d dlmZ d dlZd dl	Z	d dl
mZmZ d dlmZ ejdk r=d dlmZmZ erEd d	lmZ dJddZ	dKdLddZdMddZdMddZdMddZdMddZdMdd ZdMd!d"ZdMd#d$ZdMd%d&ZdMd'd(ZdMd)d*Z dMd+d,Z!dMd-d.Z"dMd/d0Z#ej$j%d1ej&v d2d3dMd4d5Z'dMd6d7Z(dMd8d9Z)dMd:d;Z*dMd<d=Z+dMd>d?Z,dMd@dAZ-dMdBdCZ.dMdDdEZ/dNdHdIZ0dS )O    )annotationsN)TracebackType)TYPE_CHECKING)MatcherRaisesGroup)repr_callable)      )BaseExceptionGroupExceptionGroup)RaisesContextsstrreturnc                 C  s   dt |  d S )N^$)reescape)r    r   W/var/www/html/venv/lib/python3.10/site-packages/trio/_tests/test_testing_raisesgroup.pywrap_escape   s   r   Tmsg
add_prefixboolRaisesContext[AssertionError]c                 C  s6   | d dks
J d|rdnd}t jtt||  dS )N
z<developer error, expected string should not end with newlinez&Raised exception group did not match:  match)pytestraisesAssertionErrorr   )r   r   prefixr   r   r   fails_raises_group   s
   r$   Nonec                	   C  s  t jttdt dd tt  W d    n1 sw   Y  tt tdt f1 s2w   Y  td tt tdt f1 sKw   Y  W d    n1 sZw   Y  ttt
 tdt t f1 sqw   Y  ttt
 tdt t f1 sw   Y  ttt tdtdt ff1 sw   Y  tttttt	 tdt tdt ftdt	 ff1 sw   Y  d S )NzInvalid argument "z2" must be exception type, Matcher, or RaisesGroup.r   fooz)'SyntaxError' is not of type 'ValueError'barr   )
r    r!   
ValueErrorr   	TypeErrorr   r   r$   SyntaxErrorRuntimeErrorr   r   r   r   test_raises_group#   sN   
.r,   c                	   C  s  t d tt
 tdt t f1 sw   Y  W d    n1 s%w   Y  t d ttt tdt f1 s?w   Y  W d    n1 sNw   Y  t d ttt tdt f1 shw   Y  W d    n1 sww   Y  t d tt
 tdt t f1 sw   Y  W d    n1 sw   Y  t d  ttt
 tdt t g1 sw   Y  W d    d S 1 sw   Y  d S )Nz>1 matched exception. Unexpected exception(s): [RuntimeError()]r   zS1 matched exception. Too few exceptions raised, found no match for: ['SyntaxError']z
1 matched exception. 
Too few exceptions raised!
The following expected exceptions did not find a match:
  'ValueError'
    It matches ValueError() which was paired with 'ValueError'z
1 matched exception. 
Unexpected exception(s)!
The following raised exceptions did not find a match
  ValueError():
    It matches 'ValueError' which was paired with ValueError()a  
1 matched exception. 
The following expected exceptions did not find a match:
  'ValueError'
    It matches ValueError() which was paired with 'ValueError'
The following raised exceptions did not find a match
  SyntaxError():
    'SyntaxError' is not of type 'ValueError')r$   r   r(   r   r+   r*   r   r   r   r    test_incorrect_number_exceptionsO   sP   .
.		.	.4r-   c                	   C  sZ  t tdd tdtdt ff1 sw   Y  t ttdd tdtdt t ff1 s2w   Y  t ttdd tdtdt gt g1 sOw   Y  t t tdd tdtdt ff1 skw   Y  t t tdd tdtdtdt fff1 sw   Y  tjtdd t t tdd W d    n1 sw   Y  td t tdd t1 sw   Y  W d    n1 sw   Y  td  t t tdd tdt f1 sw   Y  W d    n1 sw   Y  tdd	d
$ t tt tdtdt t gg1 sw   Y  W d    n	1 s.w   Y  tdd	d
( t ttdd d tdtdt t gg1 sUw   Y  W d    n	1 sew   Y  tdd	d
! t t tdtdt gg1 sw   Y  W d    n	1 sw   Y  td! t t tdtdt gg1 sw   Y  W d    n	1 sw   Y  td' t t t tdtdtdt ggg1 sw   Y  W d    n	1 sw   Y  td" t t tdtdt gg1 sw   Y  W d    d S 1 s&w   Y  d S )NT)flatten_subgroupsr   z@^You cannot specify a nested structure inside a RaisesGroup withr   S'ValueError' is not an exception group, but would match with `allow_unwrapped=True`zRaisesGroup(ValueError, flatten_subgroups=True): 'ValueError' is not an exception group, but would match with `allow_unwrapped=True`a  Raised exception group did not match: 
The following expected exceptions did not find a match:
  'ValueError'
  'TypeError'
The following raised exceptions did not find a match
  ExceptionGroup('', [ValueError(), TypeError()]):
    Unexpected nested 'ExceptionGroup', expected 'ValueError'
    Unexpected nested 'ExceptionGroup', expected 'TypeError'
Did you mean to use `flatten_subgroups=True`?Fr   c                 S  s   t | jdkS )N   )len
exceptions)egr   r   r   <lambda>       z(test_flatten_subgroups.<locals>.<lambda>checkzRaised exception group did not match: Unexpected nested 'ExceptionGroup', expected 'ValueError'
  Did you mean to use `flatten_subgroups=True`?z9Unexpected nested 'ExceptionGroup', expected 'ValueError'zRaisesGroup(ValueError): Unexpected nested 'ExceptionGroup', expected 'ValueError'
  Did you mean to use `flatten_subgroups=True`?z4'BaseExceptionGroup' is not of type 'ExceptionGroup')	r   r(   r   r)   r    r!   r$   r
   KeyboardInterruptr   r   r   r   test_flatten_subgroups   s   
..
	2	222

28r:   c                	   C  s  t tdd t1 sw   Y  tjtdd t ttdd W d    n1 s*w   Y  t tdd ddd t1 s@w   Y  tjtdd t t tdd W d    n1 s_w   Y  t t tdd td	td	t gg1 s{w   Y  t t tdd td	t g1 sw   Y  td
 t t td1 sw   Y  W d    n1 sw   Y  td" t tdd tdtdt gg1 sw   Y  W d    n1 sw   Y  t tddd td	td	t gg1 sw   Y  tddd t tdd td1 sw   Y  W d    n	1 s-w   Y  tddd t ttdd t1 sHw   Y  W d    n	1 sXw   Y  td t t t t1 sow   Y  W d    d S 1 sw   Y  d S )NTallow_unwrappedz,^You cannot specify multiple exceptions withr   c                 S  s   t | ttfS N)
isinstancer*   r(   er   r   r   r5     r6   z1test_catch_unwrapped_exceptions.<locals>.<lambda>r7   zhas no effect when expectingr   r/   zvalue error textziUnexpected nested 'ExceptionGroup', expected 'ValueError'
  Did you mean to use `flatten_subgroups=True`?r&   r'   )r<   r.   zORaised exception (group) did not match: 'TypeError' is not of type 'ValueError'Fr0   z.this text doesn't show up in the error messagezdRaised exception (group) did not match: Matcher(ValueError): 'TypeError' is not of type 'ValueError'z&'ValueError' is not an exception group)	r   r(   r    r!   r*   r   r   r$   r)   r   r   r   r   test_catch_unwrapped_exceptions  s   .

.

2	2
8rA   c               	   C  s|  t tdd tdt f1 sw   Y  t tdd tdt f1 s'w   Y  t tdd tdt f} | d | 1 sDw   Y  t tdd tdt f} | d | 1 saw   Y  td t tdd tdt f1 s|w   Y  W d    n1 sw   Y  td  t tdd	 tdtdg1 sw   Y  W d    d S 1 sw   Y  d S )	Nr'   r   ^bar$zmy notez^bar
my note$z;Regex pattern 'foo' did not match 'bar' of 'ExceptionGroup'r&   zRegex pattern 'foo' did not match 'bar' of 'ExceptionGroup', but matched the expected 'ValueError'. You might want RaisesGroup(Matcher(ValueError, match='foo')))r   r(   r   add_noter$   r?   r   r   r   
test_matchX  s@   


.
4rD   c               	     s   t dt f d fdd} t| }tt| d  1 sw   Y  td	| d
 tt| d t dt f1 s=w   Y  W d    d S 1 sMw   Y  d S )Nr   r@   ExceptionGroup[ValueError]r   r   c                   s   |  u S r=   r   r?   excr   r   is_exc  s   ztest_check.<locals>.is_excr7   zcheck z did not return True)r@   rE   r   r   )r   r(   r   r   r$   )rH   is_exc_reprr   rF   r   
test_check  s   
4rJ   c                  C  sD  ddd} d}t jtt|d ttd	d
d W d    n1 s#w   Y  t jtt|d ttd	| d W d    n1 sDw   Y  tttddd	d}| td
1 s]w   Y  |	 tdtd
g1 spw   Y  ttd	d	}tdtd
g1 sw   Y  t|j	trttdd
|j	sJ d S d S )Nr@   objectr   r   c                 S     dS )NTr   r?   r   r   r   my_check  s   z,test_unwrapped_match_check.<locals>.my_checkav  `allow_unwrapped=True` bypasses the `match` and `check` parameters if the exception is unwrapped. If you intended to match/check the exception you should use a `Matcher` object. If you want to match/check the exceptiongroup when the exception *is* wrapped you need to do e.g. `if isinstance(exc.value, ExceptionGroup): assert RaisesGroup(...).matches(exc.value)` afterwards.r   Tr&   )r<   r   )r<   r8   z^foo$r;   r   r'   )r@   rK   r   r   )r    r!   r(   r   r   r   r   r   r>   valuematches)rM   r   rgrG   r   r   r   test_unwrapped_match_check  s.   
rQ   c                  C  sB   t t} | d rJ | t rJ | tdt fsJ d S )Nr   )r   r(   rO   r   )rP   r   r   r   test_RaisesGroup_matches  s   rR   c                  C  s   ddd} | d	t t | d
t tt | dt t t | dt ttd | dt tdd | dt t | dt tt | dt t t | dt t tt t d S )Nmessager   bodyRaisesGroup[BaseException]r   r%   c              	   S  sv   t jtdt|  dd# | W d    n1 sw   Y  W d    d S W d    d S 1 s4w   Y  d S )Nz'^DID NOT RAISE any exception, expected r   r   )r    r!   r"   r   r   )rS   rT   r   r   r   check_message  s   Pz#test_message.<locals>.check_messagezExceptionGroup(ValueError)z&ExceptionGroup(ValueError, ValueError)z*ExceptionGroup(ExceptionGroup(ValueError))z3ExceptionGroup(Matcher(ValueError, match='my_str'))my_strz'ExceptionGroup(Matcher(match='my_str'))r   z%BaseExceptionGroup(KeyboardInterrupt)z.BaseExceptionGroup(Matcher(KeyboardInterrupt))z9BaseExceptionGroup(BaseExceptionGroup(KeyboardInterrupt))zUBaseExceptionGroup(BaseExceptionGroup(KeyboardInterrupt), ExceptionGroup(ValueError)))rS   r   rT   rU   r   r%   )r   r(   r   r9   )rV   r   r   r   test_message  sD   



rX   c                	   C  s  t d tt tdt g1 sw   Y  W d    n1 s#w   Y  t ddd) tttttdd tdtdt gt g1 sKw   Y  W d    n1 sZw   Y  t ddd- tttttttt tdt t td	td
g1 sw   Y  W d    n1 sw   Y  t d ttt
 tdt t g1 sw   Y  W d    n1 sw   Y  t d ttt tdt g1 sw   Y  W d    n1 sw   Y  t ddd ttdd tdt g1 sw   Y  W d    n	1 sw   Y  t d! ttdd	 tdtdg1 s6w   Y  W d    n	1 sFw   Y  t ddd' ttttt tdtdt t gg1 skw   Y  W d    d S 1 s|w   Y  d S )Nz''TypeError' is not of type 'ValueError'aaJ  Raised exception group did not match: 
The following expected exceptions did not find a match:
  RaisesGroup(ValueError)
  RaisesGroup(ValueError, match='a')
The following raised exceptions did not find a match
  ExceptionGroup('', [RuntimeError()]):
    RaisesGroup(ValueError): 'RuntimeError' is not of type 'ValueError'
    RaisesGroup(ValueError, match='a'): Regex pattern 'a' did not match '' of 'ExceptionGroup'
  RuntimeError():
    RaisesGroup(ValueError): 'RuntimeError' is not an exception group
    RaisesGroup(ValueError, match='a'): 'RuntimeError' is not an exception groupFr0   r   r   a  Raised exception group did not match: 
2 matched exceptions. 
The following expected exceptions did not find a match:
  RaisesGroup(RuntimeError)
  RaisesGroup(ValueError)
The following raised exceptions did not find a match
  RuntimeError():
    RaisesGroup(RuntimeError): 'RuntimeError' is not an exception group, but would match with `allow_unwrapped=True`
    RaisesGroup(ValueError): 'RuntimeError' is not an exception group
  ValueError('bar'):
    It matches 'ValueError' which was paired with ValueError('foo')
    RaisesGroup(RuntimeError): 'ValueError' is not an exception group
    RaisesGroup(ValueError): 'ValueError' is not an exception group, but would match with `allow_unwrapped=True`r&   r'   z@1 matched exception. 'AssertionError' is not of type 'TypeError'z<Matcher(ValueError): 'TypeError' is not of type 'ValueError'zRaised exception group did not match: Regex pattern 'h(ell)o' did not match 'h(ell)o' of 'ExceptionGroup'
  Did you mean to `re.escape()` the regex?zh(ell)oztMatcher(match='h(ell)o'): Regex pattern 'h(ell)o' did not match 'h(ell)o'
  Did you mean to `re.escape()` the regex?a  Raised exception group did not match: 
The following expected exceptions did not find a match:
  'ValueError'
  'ValueError'
  'ValueError'
  'ValueError'
The following raised exceptions did not find a match
  ExceptionGroup('', [ValueError(), TypeError()]):
    Unexpected nested 'ExceptionGroup', expected 'ValueError'
    Unexpected nested 'ExceptionGroup', expected 'ValueError'
    Unexpected nested 'ExceptionGroup', expected 'ValueError'
    Unexpected nested 'ExceptionGroup', expected 'ValueError')r$   r   r(   r   r)   r+   r   r"   r   r   r   r   test_assert_message  s   ... .	
.

2
2
8rZ   c                	   C  s   t ddd( ttttt tdtdt t gt g1 s"w   Y  W d    n1 s1w   Y  t ddd& tttt tdtdt t gg1 sUw   Y  W d    d S 1 sew   Y  d S )Na  Raised exception group did not match: 
The following expected exceptions did not find a match:
  RaisesGroup(ValueError, ValueError)
  'ValueError'
The following raised exceptions did not find a match
  ExceptionGroup('', [TypeError(), RuntimeError()]):
    RaisesGroup(ValueError, ValueError): 
      The following expected exceptions did not find a match:
        'ValueError'
        'ValueError'
      The following raised exceptions did not find a match
        TypeError():
          'TypeError' is not of type 'ValueError'
          'TypeError' is not of type 'ValueError'
        RuntimeError():
          'RuntimeError' is not of type 'ValueError'
          'RuntimeError' is not of type 'ValueError'
    Unexpected nested 'ExceptionGroup', expected 'ValueError'
  TypeError():
    RaisesGroup(ValueError, ValueError): 'TypeError' is not an exception group
    'TypeError' is not of type 'ValueError'Fr0   r   a  Raised exception group did not match: 
RaisesGroup(ValueError, ValueError): 
  The following expected exceptions did not find a match:
    'ValueError'
    'ValueError'
  The following raised exceptions did not find a match
    TypeError():
      'TypeError' is not of type 'ValueError'
      'TypeError' is not of type 'ValueError'
    RuntimeError():
      'RuntimeError' is not of type 'ValueError'
      'RuntimeError' is not of type 'ValueError')r$   r   r(   r   r)   r+   r   r   r   r   test_message_indentk  s@    .(4r[   c                
   C  s:  t d' tttt tdtdtdt ggg1 sw   Y  W d    n1 s.w   Y  t d* ttttt tdtdt tdt ggg1 sUw   Y  W d    n1 sdw   Y  t d& tttddt tdtdt gg1 sw   Y  W d    d S 1 sw   Y  d S )Na  
The following expected exceptions did not find a match:
  RaisesGroup(ValueError)
  'ValueError'
The following raised exceptions did not find a match
  ExceptionGroup('', [ExceptionGroup('', [ValueError()])]):
    RaisesGroup(ValueError): Unexpected nested 'ExceptionGroup', expected 'ValueError'
      Did you mean to use `flatten_subgroups=True`?
    Unexpected nested 'ExceptionGroup', expected 'ValueError'r   a  
The following expected exceptions did not find a match:
  RaisesGroup(ValueError, ValueError)
  'ValueError'
The following raised exceptions did not find a match
  ExceptionGroup('', [ValueError(), ExceptionGroup('', [ValueError()])]):
    RaisesGroup(ValueError, ValueError): 
      1 matched exception. 
      The following expected exceptions did not find a match:
        'ValueError'
          It matches ValueError() which was paired with 'ValueError'
      The following raised exceptions did not find a match
        ExceptionGroup('', [ValueError()]):
          Unexpected nested 'ExceptionGroup', expected 'ValueError'
      Did you mean to use `flatten_subgroups=True`?
    Unexpected nested 'ExceptionGroup', expected 'ValueError'a  
The following expected exceptions did not find a match:
  RaisesGroup(Exception, match='^hello')
  'ValueError'
The following raised exceptions did not find a match
  ExceptionGroup('^hello', [Exception()]):
    RaisesGroup(Exception, match='^hello'): Regex pattern '^hello' did not match '^hello' of 'ExceptionGroup'
      Did you mean to `re.escape()` the regex?
    Unexpected nested 'ExceptionGroup', expected 'ValueError'z^hellor   )r$   r   r(   r   	Exceptionr   r   r   r   )test_suggestion_on_nested_and_brief_error  s<   ..4r]   c                   C  s   t dddA tttttttttddttt tdtdtdtd	gtdtd
tdgg1 s:w   Y  W d    d S 1 sJw   Y  d S )Na  Raised exception group did not match: 
The following expected exceptions did not find a match:
  RaisesGroup(ValueError)
  RaisesGroup(RaisesGroup(ValueError))
  RaisesGroup(Matcher(TypeError, match='foo'))
  RaisesGroup(TypeError, ValueError)
The following raised exceptions did not find a match
  TypeError('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'):
    RaisesGroup(ValueError): 'TypeError' is not an exception group
    RaisesGroup(RaisesGroup(ValueError)): 'TypeError' is not an exception group
    RaisesGroup(Matcher(TypeError, match='foo')): 'TypeError' is not an exception group
    RaisesGroup(TypeError, ValueError): 'TypeError' is not an exception group
  ExceptionGroup('Exceptions from Trio nursery', [TypeError('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')]):
    RaisesGroup(ValueError): 'TypeError' is not of type 'ValueError'
    RaisesGroup(RaisesGroup(ValueError)): RaisesGroup(ValueError): 'TypeError' is not an exception group
    RaisesGroup(Matcher(TypeError, match='foo')): Matcher(TypeError, match='foo'): Regex pattern 'foo' did not match 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
    RaisesGroup(TypeError, ValueError): 1 matched exception. Too few exceptions raised, found no match for: ['ValueError']
  ExceptionGroup('Exceptions from Trio nursery', [TypeError('cccccccccccccccccccccccccccccccccccccccc'), TypeError('dddddddddddddddddddddddddddddddddddddddd')]):
    RaisesGroup(ValueError): 
      The following expected exceptions did not find a match:
        'ValueError'
      The following raised exceptions did not find a match
        TypeError('cccccccccccccccccccccccccccccccccccccccc'):
          'TypeError' is not of type 'ValueError'
        TypeError('dddddddddddddddddddddddddddddddddddddddd'):
          'TypeError' is not of type 'ValueError'
    RaisesGroup(RaisesGroup(ValueError)): 
      The following expected exceptions did not find a match:
        RaisesGroup(ValueError)
      The following raised exceptions did not find a match
        TypeError('cccccccccccccccccccccccccccccccccccccccc'):
          RaisesGroup(ValueError): 'TypeError' is not an exception group
        TypeError('dddddddddddddddddddddddddddddddddddddddd'):
          RaisesGroup(ValueError): 'TypeError' is not an exception group
    RaisesGroup(Matcher(TypeError, match='foo')): 
      The following expected exceptions did not find a match:
        Matcher(TypeError, match='foo')
      The following raised exceptions did not find a match
        TypeError('cccccccccccccccccccccccccccccccccccccccc'):
          Matcher(TypeError, match='foo'): Regex pattern 'foo' did not match 'cccccccccccccccccccccccccccccccccccccccc'
        TypeError('dddddddddddddddddddddddddddddddddddddddd'):
          Matcher(TypeError, match='foo'): Regex pattern 'foo' did not match 'dddddddddddddddddddddddddddddddddddddddd'
    RaisesGroup(TypeError, ValueError): 
      1 matched exception. 
      The following expected exceptions did not find a match:
        'ValueError'
      The following raised exceptions did not find a match
        TypeError('dddddddddddddddddddddddddddddddddddddddd'):
          It matches 'TypeError' which was paired with TypeError('cccccccccccccccccccccccccccccccccccccccc')
          'TypeError' is not of type 'ValueError'Fr0   r&   r   r   (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazExceptions from Trio nursery(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(cccccccccccccccccccccccccccccccccccccccc(dddddddddddddddddddddddddddddddddddddddd)r$   r   r(   r   r)   r   r   r   r   r   test_assert_message_nested  s8   26
=4rb   
hypothesisz-hypothesis may have monkeypatched _check_repr)reasonc                	   C  sp   t jtdd' ttdd dt tdtdtdg1 s!w   Y  W d    d S 1 s1w   Y  d S )	Na`  ^Raised exception group did not match: \nThe following expected exceptions did not find a match:\n  Matcher\(check=<function test_check_no_patched_repr.<locals>.<lambda> at .*>\)\n  'TypeError'\nThe following raised exceptions did not find a match\n  ValueError\('foo'\):\n    Matcher\(check=<function test_check_no_patched_repr.<locals>.<lambda> at .*>\): check did not return True\n    'ValueError' is not of type 'TypeError'\n  ValueError\('bar'\):\n    Matcher\(check=<function test_check_no_patched_repr.<locals>.<lambda> at .*>\): check did not return True\n    'ValueError' is not of type 'TypeError'$r   c                 S  rL   )NFr   )xr   r   r   r5   ]  s    z,test_check_no_patched_repr.<locals>.<lambda>r7   r   r&   r'   )r    r!   r"   r   r   r)   r   r(   r   r   r   r   test_check_no_patched_reprC  s   
4rf   c                	   C  sx   t d. ttttttdd tdtdtdtdtdg1 s%w   Y  W d    d S 1 s5w   Y  d S )Naz  
3 matched exceptions. 
The following expected exceptions did not find a match:
  Matcher(ValueError, match='foo')
    It matches ValueError('foo') which was paired with 'ValueError'
    It matches ValueError('foo') which was paired with 'ValueError'
    It matches ValueError('foo') which was paired with 'ValueError'
The following raised exceptions did not find a match
  ValueError('bar'):
    It matches 'ValueError' which was paired with ValueError('foo')
    It matches 'ValueError' which was paired with ValueError('foo')
    It matches 'ValueError' which was paired with ValueError('foo')
    Matcher(ValueError, match='foo'): Regex pattern 'foo' did not match 'bar'
There exist a possible match when attempting an exhaustive check, but RaisesGroup uses a greedy algorithm. Please make your expected exceptions more stringent with `Matcher` etc so the greedy algorithm can function.r&   r   r   r'   )r$   r   r(   r   r   r   r   r   r   test_misordering_exampleb  s"   4rg   c                	   C  s  t d ttt
 tdt t g1 sw   Y  W d   n1 s&w   Y  t d ttt
 tdt t g1 sBw   Y  W d   n1 sQw   Y  t d  ttt
 tdt t g1 smw   Y  W d   dS 1 s}w   Y  dS )zif only one raised and one expected fail to match up, we print a full table iff
    the raised exception would match one of the expected that previously got matchedz>1 matched exception. 'TypeError' is not of type 'RuntimeError'r   Na  
1 matched exception. 
The following expected exceptions did not find a match:
  'RuntimeError'
The following raised exceptions did not find a match
  TypeError():
    It matches 'Exception' which was paired with ValueError()
    'TypeError' is not of type 'RuntimeError'a  
1 matched exception. 
The following expected exceptions did not find a match:
  'ValueError'
    It matches ValueError() which was paired with 'ValueError'
The following raised exceptions did not find a match
  TypeError():
    'TypeError' is not of type 'ValueError')r$   r   r(   r+   r   r)   r\   r   r   r   r   test_brief_error_on_one_fail  s0   .
.4rh   c               	   C  s   t d% ttttt tdt t t t g1 sw   Y  W d    n1 s,w   Y  td} tdd}t d  t|||	 td| | | g1 sQw   Y  W d    d S 1 saw   Y  d S )Nz?3 matched exceptions. 'RuntimeError' is not of type 'TypeError'r   r&   r'   r   aC  
The following expected exceptions did not find a match:
  Matcher(match='bar')
  Matcher(match='bar')
  Matcher(match='bar')
The following raised exceptions did not find a match
  ValueError('foo'):
    Matcher(match='bar'): Regex pattern 'bar' did not match 'foo'
    Matcher(match='bar'): Regex pattern 'bar' did not match 'foo'
    Matcher(match='bar'): Regex pattern 'bar' did not match 'foo'
  ValueError('foo'):
    Matcher(match='bar'): Regex pattern 'bar' did not match 'foo'
    Matcher(match='bar'): Regex pattern 'bar' did not match 'foo'
    Matcher(match='bar'): Regex pattern 'bar' did not match 'foo'
  ValueError('foo'):
    Matcher(match='bar'): Regex pattern 'bar' did not match 'foo'
    Matcher(match='bar'): Regex pattern 'bar' did not match 'foo'
    Matcher(match='bar'): Regex pattern 'bar' did not match 'foo')r$   r   r(   r)   r   r+   r   )r@   mr   r   r   test_identity_oopsies  s(   .


4rj   c                	   C  s  t jtdd t  W d    n1 sw   Y  t jtdttt dd tt W d    n1 s9w   Y  ttt t	dt f1 sOw   Y  t
d ttt t	dt f1 sjw   Y  W d    d S 1 szw   Y  d S )Nz6^You must specify at least one parameter to match on.$r   z^exception_type z% must be a subclass of BaseException$r   z;Matcher(TypeError): 'ValueError' is not of type 'TypeError')r    r!   r(   r   r   r   reprrK   r   r   r$   r)   r   r   r   r   test_matcher  s.   

4rl   c                	   C  s  t ttd	 tdtdf1 sw   Y  td  t ttd	 tdtdf1 s0w   Y  W d    n1 s?w   Y  t tdd	 tdtdf1 sWw   Y  td  t tdd	 tdtdf1 stw   Y  W d    n1 sw   Y  t ttdd	 tdtdg1 sw   Y  td" t ttdd	 tdtd	g1 sw   Y  W d    d S 1 sw   Y  d S )
Nr&   r   zIMatcher(ValueError, match='foo'): Regex pattern 'foo' did not match 'bar'r'   r   z=Matcher(match='foo'): Regex pattern 'foo' did not match 'bar'rB   zNMatcher(ValueError, match='^bar$'): Regex pattern '^bar$' did not match 'barr'barr)r   r   r(   r   r$   r   r   r   r   test_matcher_match  sB   .	.	4rn   c               	   C  sZ  ddd} t t| d
 tdtd	df1 sw   Y  ddd}t tt|d
 tdtd	df1 s8w   Y  td|d" t tt|d
 tdtddf1 s[w   Y  W d    n1 sjw   Y  td|d|d) t t tt|d tdtdtddgg1 sw   Y  W d    d S 1 sw   Y  d S )Nr@   BaseExceptionr   r   c                 S  s   t | to	| jdkS N   )r>   OSErrorerrnor?   r   r   r   check_oserror_and_errno_is_5  s   z8test_Matcher_check.<locals>.check_oserror_and_errno_is_5r7   r   rq   rr   c                 S  s
   | j dkS rp   )rs   r?   r   r   r   check_errno_is_5  s   
z,test_Matcher_check.<locals>.check_errno_is_5zMatcher(OSError, check=z): check did not return True   z#RaisesGroup(Matcher(OSError, check=z)): Matcher(OSError, check=)r@   ro   r   r   )r@   rr   r   r   )r   r   r   rr   r$   )rt   ru   r   r   r   test_Matcher_check  s0   


.4rw   c                  C  s   t ttdks
J t tdddksJ tdd} t t| ddks&J tdtj}t t|dd|d	ks<J t ttd
tddtd	ksMJ d S )NzMatcher(ValueError)[a-z]r   zMatcher(match='[a-z]')noflagr   zMatcher(match='noflag')zMatcher(match=)r   r   r8   z&Matcher(ValueError, match='re', check=)r   r   r(   r   compile
IGNORECASEr   )pattern_no_flagspattern_flagsr   r   r   test_matcher_tostring6  s   
r   c                  C  sX   ddd} | d | d | d	 | d
 | d t ttdtddtdks*J d S )Nr   r   r   r%   c                 S  s0   t | }| t|  krt|ksJ  J d S r=   )evalr   rk   )r   evaledr   r   r   check_str_and_reprD  s   (z5test_raisesgroup_tostring.<locals>.check_str_and_reprzRaisesGroup(ValueError)z$RaisesGroup(RaisesGroup(ValueError))z RaisesGroup(Matcher(ValueError))z-RaisesGroup(ValueError, allow_unwrapped=True)z%RaisesGroup(ValueError, match='aoeu')rx   r{   z-RaisesGroup(ValueError, match='[a-z]', check=rz   )r   r   r   r%   )r   r   r(   r   )r   r   r   r   test_raisesgroup_tostringC  s   

r   monkeypatchpytest.MonkeyPatchc                 C  s~   |  tjjdtjjj tjt	}tdtdf1 sw   Y  |jtu s*J |j	j
d jdks5J t|jts=J d S )NExceptionInfor   hellor   )r   )setattrtriotesting_raises_group_ExceptionInfor   r(   r   typerN   r3   argsr>   tbr   )r   excinfor   r   r   test__ExceptionInfoT  s   r   )r   r   r   r   )T)r   r   r   r   r   r   )r   r%   )r   r   r   r%   )1
__future__r   r   systypesr   typingr   r    r   trio.testingr   r   trio.testing._raises_groupr   version_infoexceptiongroupr
   r   _pytest.python_apir   r   r$   r,   r-   r:   rA   rD   rJ   rQ   rR   rX   rZ   r[   r]   rb   markskipifmodulesrf   rg   rh   rj   rl   rn   rw   r   r   r   r   r   r   r   <module>   sV    




,
>
{
P
+



;
v
D
AS

!
-
+

"
"
