o
    gY                    @   s\  d dl Z d dlZd dlZd dl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mZmZmZmZmZmZ d dlmZ d dlmZmZ d dlmZ d dlmZ G dd	 d	eZG d
d deZG dd deZG dd dejZ dZ!G dd dejZ"G dd dejZ#G dd dejZ$G dd dejZ%G dd dejZ&e'dkre(  dS dS )    N)dedent)captured_stderrcheck_impl_detailcpython_only
gc_collect
no_tracingscript_helperSuppressCrashReport)import_module)TESTFNunlink)check_warnings)supportc                   @      e Zd Zdd ZdS )NaiveExceptionc                 C   
   || _ d S Nxselfr    r   J/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/test_exceptions.py__init__      
zNaiveException.__init__N__name__
__module____qualname__r   r   r   r   r   r          r   c                   @      e Zd ZdZdd ZdS )SlottedNaiveExceptionr   c                 C   r   r   r   r   r   r   r   r      r   zSlottedNaiveException.__init__N)r   r   r   	__slots__r   r   r   r   r   r!          r!   c                   @   r   )BrokenStrExceptionc                 C      t d)Nzstr() is broken	Exceptionr   r   r   r   __str__!      zBrokenStrException.__str__N)r   r   r   r)   r   r   r   r   r$       r   r$   c                   @   sF  e Zd Zdd Zdd Zdd Zdd Zdd
dZdd Ze	dd Z
dd Zeejdkddd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zed&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Z d4d5 Z!d6d7 Z"d8d9 Z#d:d; Z$d<d= Z%d>d? Z&d@dA Z'dBdC Z(dDdE Z)dFdG Z*dHdI Z+dJdK Z,dLdM Z-e.dNdOdP Z/dQdR Z0dSdT Z1dUdV Z2edWdX Z3e	dYdZ Z4e	d[d\ Z5e	d]d^ Z6d_d` Z7e	dadb Z8e	dcdd Z9e	dedf Z:e	dgdh Z;edidj Z<dkdl Z=dmdn Z>dodp Z?e	dqdr Z@dsdt ZAdudv ZBdwdx ZCedydzd{d| ZDd}d~ ZEdS )ExceptionTestsc                 C   s   | j ||dL z|d |y" } z
t|}W Y d }~nd }~ww z|d |y= } z
t|}W Y d }~nd }~ww | || | |j| W d    d S 1 sVw   Y  d S )N)excexcnameZspam)subTeststrassertEqualr   )r   r,   r-   errZbuf1Zbuf2r   r   r   raise_catch(   s    "zExceptionTests.raise_catchc              
   C   s  |  td | tttd |  td ttddd}|  ttddd}tj	}z"zdd l
}|d	 W n	 ty>   Y nw W |t_	|  tt n|t_	|  tt w |  td
 | ttdd |  td | ttd |  td g }| t|jd |  td i }| t|jd |  td |  td |  td zt}W n	 ty   Y nw |  td d}tdD ]}||7 }q|  td |  td |  td ztd W n	 ty   Y nw |  td |  td ztddd  W n
 ty   Y nw |  d! |  t!d" |  t"d# | t"tj#d |  t$d$ zg d%  W n
 t$y6   Y nw |  t%d& | t%t&d' |  t'd( zdd }W n
 t'yZ   Y nw |  t(d) zdd }W n t(yz } zW Y d }~nd }~ww |  t)d* d S )+NAttributeErrorZundefined_attributeEOFErrorwutf-8encodingrr       OSErrorzthis file does not existImportErrorZundefined_module
IndexError
   KeyErrorkeyKeyboardInterruptMemoryError	NameErrorOverflowError      RuntimeErrorRecursionErrorSyntaxErrorz/
IndentationErrorTabErrorz"try:
	1/0
    	1/0
finally:
 pass
z<string>execzTabError not raisedSystemError
SystemExit	TypeErrorr   
ValueErrori   ZeroDivisionErrorr'   StopAsyncIteration)*r2   r3   assertRaisesgetattrsysr4   openr   closestdinmarshalloadsr   r;   r<   
__import__r=   __getitem__r?   rA   rB   rC   Zundefined_variablerD   rangerG   rH   rI   rL   rJ   rK   compilefailrM   rN   exitrO   rP   chrrQ   r'   rR   )r   fpZ	savestdinrY   r   Zdummyer   r   r   testRaising5   s   




 zExceptionTests.testRaisingc                    s(    fdd}d}||d |dd d S )Nc                    s    j | |d@ zt| dd W n! ty1 } z|j|kr' d||jf  W Y d }~nd }~ww  d W d    d S W d    d S 1 sJw   Y  d S )N)srcmsg
<fragment>rL   expected %s, got %s"failed to get expected SyntaxError)r.   r^   rI   rf   r_   )re   rf   rc   r(   r   r   ckmsg   s   
" z4ExceptionTests.testSyntaxErrorMessage.<locals>.ckmsgzHif 1:
        try:
            continue
        except:
            passz'continue' not properly in loopz	continue
r   r   rj   sr   r(   r   testSyntaxErrorMessage   s   

z%ExceptionTests.testSyntaxErrorMessagec                    s   t f fdd	}d}||d d}||d d}||d d}||d d	}||d d
}||d d}||d d}||dt d}||dt d S )Nc              
      sr   zt | dd W n) |y1 } z|j|kr& d||jf  W Y d }~d S W Y d }~d S d }~ww  d d S )Nrg   rL   rh   ri   )r^   rf   r_   )re   rf   	exceptionrc   r(   r   r   rj      s   
"z:ExceptionTests.testSyntaxErrorMissingParens.<locals>.ckmsgzprint "old style"z@Missing parentheses in call to 'print'. Did you mean print(...)?zprint "old style",zprint f(a+b,c)zexec "old style"z>Missing parentheses in call to 'exec'. Did you mean exec(...)?zexec f(a+b,c)zprint (a+b,c) $ 42zinvalid syntaxzexec (a+b,c) $ 42zif True:
print "No indent"z9expected an indented block after 'if' statement on line 1z6if True:
        print()
	exec "mixed tabs and spaces"z2inconsistent use of tabs and spaces in indentation)rI   rJ   rK   rk   r   r(   r   testSyntaxErrorMissingParens   s&   	






z+ExceptionTests.testSyntaxErrorMissingParensr6   c              	   C   s   | j |||d^ | t}t|dd W d    n1 sw   Y  | |jj| | |jj| |jjd ur^t	|t
sE||d}|d|d  }| ||jj W d    d S W d    d S 1 siw   Y  d S )N)sourcelinenooffsetrg   rL   replace
rE   )r.   rS   rI   r^   r0   rn   rq   rr   text
isinstancer/   decodesplitassertIn)r   re   rq   rr   r8   cmliner   r   r   check   s   
"zExceptionTests.checkc                 C   sj  | j }|ddd |ddd |ddd |d	dd
 |ddd
 |ddddd |ddd |ddd |ddd |ddd |ddd |ddd |ddd |ddd |ddd |ddd |ddd |ddd |d dd |d!dd |d"dd |d#dd$ |d%dd |d&dd' |d(dd) |d*dd$ |d+dd$ |d,dd$d-d |d.d/d0 |d1dd |d2dd |d3dd |d4d5d6 |d7dd |d8dd |d9dd |d:dd |d;dd |d<dd |d=dd |d>dd |d?dd |d@dd |dAdd |dBdd |dCdd |dDdd |dEdd |dFdd |dGdd) d S )HNzdef fact(x):
	return x!
   r>   z1 +
rE      z def spam():
  print(1)
 print(2)   zPython = "Python" +   u   Python = "Ṕýţĥòñ" +s+   # -*- coding: cp1251 -*-
Python = "ϳ" +   cp1251r7   s   Python = "ϳ" +   zx = "a   zlambda x: x = 2zf{a + b + c}z[file for str(file) in []
])u   a = « hello » « world »z[
file
for str(file)
in
[]
]z[file for
 str(file) in []]zages = {'Alice'=22, 'Bob'=23}   z7match ...:
    case {**rest, "key": value}:
        ...zclass foo:return 1   zdef f():
  continuezdef f():
  breakz4try:
  pass
except:
  pass
except ValueError:
  passz(0x+1)zx = 0xI   z0010 + 2z
x = 32e-+4   zx = 0o9   u   α = 0xIs   α = 0xIs#   # -*- coding: iso8859-7 -*-
 = 0xIz	iso8859-7s   if 1:
            def foo():
                '''

            def bar():
                pass

            def baz():
                '''quux'''
            	      z"pass
pass
pass
(1+)
pass
pass
passz(1+)z[interesting
foo()
s   ﻿#coding: utf8
print('我')
r   z!x = [(yield i) for i in range(3)]zdef f():
  from _ import *zdef f(x, x):
  passzdef f(x):
  nonlocal xzdef f(x):
  x = 1
  global xz
nonlocal xz def f():
  global x
  nonlocal xz#from __future__ import doesnt_existzfrom __future__ import bracesz#x=1
from __future__ import divisionzfoo(1=2)zdef f():
  x, y: intz[*x for x in xs]zfoo(x for x in range(10), 100)zfor 1 in []: passz(yield i) = 2zdef f(*):
  pass)r|   )r   r|   r   r   r   testSyntaxErrorOffset   sr   	
z$ExceptionTests.testSyntaxErrorOffsetc                    sn   G dd dt  G dd d fdd} fdd}fd	d
}tjds5|  |  |  d S d S )Nc                   @   r   )z9ExceptionTests.testSettingException.<locals>.BadExceptionc                 S   r%   )Nzcan't instantiate BadException)rG   )Zself_r   r   r   r   #  r*   zBExceptionTests.testSettingException.<locals>.BadException.__init__Nr   r   r   r   r   BadException"  r   r   c                   @      e Zd ZdS )z=ExceptionTests.testSettingException.<locals>.InvalidExceptionNr   r   r   r   r   r   r   InvalidException&      r   c               
      s   dd l } z|  d W n. ty: } z"t \}}}|jj}|jd 	|j
d W Y d }~d S d }~ww d d S )Nr   rE   
test_capi1test_exceptions.pyExpected exception)	_testcapiraise_exceptionrO   rU   exc_infotb_framef_coder0   co_name
assertTrueco_filenameendswithr_   )r   r1   r,   tbcor   r   r   r   r   )  s    z7ExceptionTests.testSettingException.<locals>.test_capi1c               
      s   dd l } z|  d W n: tyF } z.t \}}}|jj}|jd 	|j
d |jjj}|jd W Y d }~d S d }~ww d d S )Nr   r   r   
test_capi2r   )r   r   rG   rU   r   r   r   r0   r   r   r   r   f_backr_   )r   r1   r,   r   r   Zco2r   r   r   r   5  s   
z7ExceptionTests.testSettingException.<locals>.test_capi2c                     s   dd l } t| j d d S )Nr   rE   )r   rS   rM   r   )r   )r   r   r   r   
test_capi3C  s   
z7ExceptionTests.testSettingException.<locals>.test_capi3java)r'   rU   platform
startswith)r   r   r   r   r   )r   r   r   r   testSettingException  s   
z#ExceptionTests.testSettingExceptionc                 C   s  zt  W n
 ty   Y d S w | t t | ttdd | ttddd tddd}| |jd | |jd  | t|d td	ddd
}| |jd | |jd
 | |jd | |j	d | |j
d  | t|d td	dd d}| |jd | |jd | |jd | |j	d  | |j
d  | t|d tdd}| |jd | |jd  | |jd | |j	d  | |j
d  d S )Ni  Z1001messagez[Errno 1001] messager   foobarz[Errno 9] foo: 'bar'r   r   r}   z[WinError 3] foo: 'bar'   z[WinError 1001] foo)WindowsErrorrC   assertIsr;   r0   r/   errnowinerrorstrerrorfilename	filename2)r   r5   r   r   r   test_WindowsErrorM  sD   
z ExceptionTests.test_WindowsErrorwin32ztest specific to Windowsc                 C   sN   t d}d}| td|  |j| W d   dS 1 s w   Y  dS )z:Should fill in unknown error code in Windows error messagectypesl   cs@ zWindows Error 0x%xN)r
   assertRaisesRegexr;   Z	pythonapiZPyErr_SetFromWindowsErr)r   r   coder   r   r   test_windows_messaget  s
   "z#ExceptionTests.test_windows_messagec                 C   s  t dddift dddift dddift dddiftddddftddd d d d dftd	d	d d dd
dftdd	dd dd
dftdd	dddftddddddftdddddd dftdd d d d d d d dftddd d dd d d d dftddd dd ddd!d"d#d$	ftd%d d%d dd d d d d d&	ftdddiftd'd'd(d)d*d+d,ftd(td-d*dd+fd(td-d*dd+fd(d-d*d+d,ftd.d.d(d-d*d+d,ftd/d/d0d1d*dd2ft	dddd3ft
dddd3fg}z|tdddd ddd d4f W n	 ty   Y nw |D ]\}}}z|| }W n   td5||f tjd6 Y qt|jd7s$| t|jd8 t|}|D ]}t||}| t|t|| d9||||| f  q*tfD ]7}	t|	jd D ],}
|	||
}|	|}|D ]}tt||}t|| }| ||d:||f  qcqTqKqd S );Nr   args)rE   )r   )r   rE   r   )r   r   )r   r   r   r   r   )r   r   r   )r   r   bazr   )r   r   r   Nquuxr   )r   r   r   )errnoStrstrErrorStrfilenameStr)r   r   r   r   r   )r   r   r   r   )rE   r   r   )rE   r   rE   )r   r   r   r   r   )rf   ru   r   rq   rr   
end_offsetprint_file_and_line)msgStrr   )r   ru   r   rf   r   rq   rr   r   )r   )r   	linenoStr	offsetStrtextStrendLinenoStrendOffsetStrr   r   r   r   r   )	rr   ru   r   r   rf   r   rq   
end_linenor   )r   r   r   r   r   r   r   Zprint_file_and_lineStr)	ru   r   r   rf   r   rq   rr   r   r   )asciiar   rE   ordinal not in ranger   r   r   r   )r   r8   objectstartreason   )r   r   r   rE   r   )   あr   rE   ouchr   r   )r   r   r   r   end)r   r   )r   r   r   r   r   r   z
exc=%r, args=%r)filer   builtinsz%r.%s == %r, expected %rzpickled "%r", attribute "%s)BaseExceptionrN   r;   rI   UnicodeErrorUnicodeEncodeErrorUnicodeDecodeError	bytearrayUnicodeTranslateErrorr   r!   appendr   rC   printrU   stderrtyper   r   r0   r   r/   rT   reprpickler]   HIGHEST_PROTOCOLdumpsrZ   )r   ZexceptionListr,   r   expectedrc   rl   ZcheckArgNamevaluepprotocolnewZgotZwantr   r   r   testAttributes~  s0  
	
U




zExceptionTests.testAttributesc                 C   s   zt d   t d }Y t |}| |t | |j| t d|}| |t  | |j| G dd dt}| |}| || | |j| d S )Nr~   r}   r   c                   @   r   )z5ExceptionTests.testWithTraceback.<locals>.MyExceptionNr   r   r   r   r   MyException  r   r   )	r=   rU   r   r   with_tracebackassertIsInstancer0   __traceback__r'   )r   r   rc   r   r   r   r   testWithTraceback  s   z ExceptionTests.testWithTracebackc              
   C   sR   zdt  _W n ty! } z| dt| W Y d }~d S d }~ww | d d S )Nr   z!__traceback__ must be a tracebackNo exception raised)r'   r   rO   ry   r/   r_   r   rc   r   r   r   testInvalidTraceback  s   z#ExceptionTests.testInvalidTracebackc                 C   sP   |  ttt dd |  ttt d |  ttt dd |  ttt d d S )N	__cause__rE   __context__)rS   rO   setattrr'   delattrr(   r   r   r   testInvalidAttrs  s   zExceptionTests.testInvalidAttrsc                 C   sB   zt d   t d }Y t }||_d |_| |jd  d S )Nr~   r}   )r=   rU   r   r'   r   r0   )r   r   rc   r   r   r   testNoneClearsTracebackAttr%  s   z*ExceptionTests.testNoneClearsTracebackAttrc                 C   sn   t  }| |j | |j t }| |j | |j G dd dt}| }| |j | |j d S )Nc                   @   r   )z5ExceptionTests.testChainingAttrs.<locals>.MyExceptionNr   r   r   r   r   r   9  r   r   )r'   assertIsNoner   r   rO   r;   )r   rc   r   r   r   r   testChainingAttrs0  s   z ExceptionTests.testChainingAttrsc              
   C   s   zt   t y } z|}W Y d }~nd }~ww | |j | |j | |j t |_d |_| |jt | |j | |j d|_| |j d S )NF)	r'   r   r   r   ZassertFalse__suppress_context__rC   r   r   )r   r,   rc   r   r   r   testChainingDescriptors@  s    z&ExceptionTests.testChainingDescriptorsc                 C   s<   | j ttdd G dd dt}|dd}| |jd d S )NrE   )r   c                   @   r   )z8ExceptionTests.testKeywordArgs.<locals>.DerivedExceptionc                 S   s   t |  || _d S r   )r   r   	fancy_arg)r   r   r   r   r   r   X  s   

zAExceptionTests.testKeywordArgs.<locals>.DerivedException.__init__Nr   r   r   r   r   DerivedExceptionW  r   r   *   )r   )rS   rO   r   r0   r   )r   r   r   r   r   r   testKeywordArgsR  s   
zExceptionTests.testKeywordArgsc                    s4    fdd |  t  fdd|  t d S )Nc                      s     S r   r   r   )fr   r   r   a     z/ExceptionTests.testInfiniteRecursion.<locals>.fc                      s   z  W S  t y   Y dS w )Nr   rP   r   gr   r   r  e  s
   z/ExceptionTests.testInfiniteRecursion.<locals>.g)rS   rH   r(   r   )r   r  r   testInfiniteRecursion_  s   z$ExceptionTests.testInfiniteRecursionc                 C   s8   |  tt |  ttd |  ttdd d S )Nr   b)r   r/   r'   r(   r   r   r   test_strl  s   zExceptionTests.test_strc              
   C   sJ   zt   t y } z| | ~W Y d }~nd }~ww | dt  d S )Nrc   )r'   r   assertNotInlocalsr   r   r   r   testExceptionCleanupNamesr  s   
z(ExceptionTests.testExceptionCleanupNamesc                    s  G dd dt  G dd d} fdd}| t}z|  W n  y5 } zW Y d }~nd }~ww d | |  | t}z|  W n	  yV   Y nw d | |  | t}z|  W n   Y d | |  | t}dD ]}z|  W q   Y  d | |  | t}zz|  W n   tW n' ty } zd |_d | tdd	rt  |  W Y d }~nd }~ww | t}z|  W n  y   zz    y   Y nw Y nw d tdd	r
t  | |  G d
d d}| t}|  |  W d    n	1 s3w   Y  d tdd	rCt  | |  d S )Nc                   @   r   )z=ExceptionTests.testExceptionCleanupState.<locals>.MyExceptionc                 S   r   r   objr   r  r   r   r   r     r   zFExceptionTests.testExceptionCleanupState.<locals>.MyException.__init__Nr   r   r   r   r   r     r   r   c                   @   r   )z7ExceptionTests.testExceptionCleanupState.<locals>.MyObjNr   r   r   r   r   MyObj  r   r  c                     s   }  r   r   )Z	local_refr   r  r   r   inner_raising_func  s   zDExceptionTests.testExceptionCleanupState.<locals>.inner_raising_func)r   F)Zcpythonc                   @      e Zd Zdd Zdd ZdS )z9ExceptionTests.testExceptionCleanupState.<locals>.Contextc                 S      | S r   r   r(   r   r   r   	__enter__     zCExceptionTests.testExceptionCleanupState.<locals>.Context.__enter__c                 S   s   dS )NTr   )r   exc_type	exc_valueexc_tbr   r   r   __exit__  r  zBExceptionTests.testExceptionCleanupState.<locals>.Context.__exit__Nr   r   r   r  r  r   r   r   r   Context      r  )r'   weakrefrefr   r?   r   r   r   )r   r  r  wrrc   ir  r   r  r   testExceptionCleanupState|  s   


















z(ExceptionTests.testExceptionCleanupStatec              
      sD    fdd}zt  W d S  ty!   z
|  W Y d   d S d   ww )Nc                      s     d S r   r   r   rc   r   r   print_error  r*   zIExceptionTests.test_exception_target_in_nested_scope.<locals>.print_error)	somethingr'   )r   r!  r   r   r   %test_exception_target_in_nested_scope  s   
z4ExceptionTests.test_exception_target_in_nested_scopec                 C   s   dd }| }|  t|t |  t d d  |  t|t |  t d d  |  t|d  ztd ty{   | }|  t|t |  t d t |  t|t |  t d t |  t|t ~|  t d t Y d S w )Nc                   s   sL    zt d t y   t d V  t d V  Y nw t d V  d S )NZcaughtr   )r?   rU   r   r   r   r   r   yield_raise  s   z:ExceptionTests.test_generator_leaking.<locals>.yield_raiser   r   )r0   nextr?   rU   r   rO   )r   r$  r  r   r   r   test_generator_leaking  s&   z%ExceptionTests.test_generator_leakingc                 C   sb   dd }zt  t y   | }t| Y nw zt| W n	 ty&   Y nw | t d d S )Nc                   s   s    d V  d S r   r   r   r   r   r   r       
z1ExceptionTests.test_generator_leaking2.<locals>.gNNN)rG   r%  StopIterationr0   rU   r   r   r  itr   r   r   test_generator_leaking2  s   z&ExceptionTests.test_generator_leaking2c              
   C   s   dd }| }t | zdd  W n1 tyB } z%| t d | ||}| t d | | || W Y d }~nd }~ww | t d d S )Nc                   s   s2    zd V  W d S  t y   t d V  Y d S w NrE   rQ   rU   r   r   r   r   r   r  +  s   z1ExceptionTests.test_generator_leaking3.<locals>.grE   r   r(  )r%  rQ   r   rU   r   throwr0   )r   r  r+  rc   Zgen_excr   r   r   test_generator_leaking3(  s   
z&ExceptionTests.test_generator_leaking3c              
   C   s   dd }| }zt  t y   t|}Y nw | |t zt| W n ty? } z| t d | W Y d }~nd }~ww | t d d S )Nc                   s   s0    zdd  W d S  t y   t d V   w NrE   r   r.  r   r   r   r   r  >  s   z1ExceptionTests.test_generator_leaking4.<locals>.grE   r(  )rO   r%  r   rQ   rU   r   r0   )r   r  r+  tprc   r   r   r   test_generator_leaking4;  s    z&ExceptionTests.test_generator_leaking4c                    sD    fdd}| }zt  t y   t| Y nw  tt| d S )Nc                   3   s0      t d t d V   t d d S )NrE   r(  )r   rU   r   rG   r0   r   r(   r   r   r  W  s   z>ExceptionTests.test_generator_doesnt_retain_old_exc.<locals>.g)rG   r%  rS   r)  r*  r   r(   r   $test_generator_doesnt_retain_old_excV  s   z3ExceptionTests.test_generator_doesnt_retain_old_excc                    s4   dd   fdd}|  t   | t d d S )Nc                   s   s    dV  d S r-  r   r   r   r   r   
simple_gend  r'  zIExceptionTests.test_generator_finalizing_and_exc_info.<locals>.simple_genc                     s&     } zt  t y   t|  Y S w r   )rG   r%  )genr5  r   r   run_genf  s   zFExceptionTests.test_generator_finalizing_and_exc_info.<locals>.run_genr(  )r   r0   rU   r   )r   r8  r   r7  r   &test_generator_finalizing_and_exc_infob  s
   z5ExceptionTests.test_generator_finalizing_and_exc_infoc                    sn   G dd dt  G dd d} fdd}| t}| }t| || d  }| |  d S )Nc                   @   r   )zFExceptionTests._check_generator_cleanup_exc_state.<locals>.MyExceptionc                 S   r   r   r
  r  r   r   r   r   t  r   zOExceptionTests._check_generator_cleanup_exc_state.<locals>.MyException.__init__Nr   r   r   r   r   r   s  r   r   c                   @   r   )z@ExceptionTests._check_generator_cleanup_exc_state.<locals>.MyObjNr   r   r   r   r   r  v  r   r  c                   3   s&    z   y   d V  Y d S w r   r   r   r  r   r   raising_geny  s   zFExceptionTests._check_generator_cleanup_exc_state.<locals>.raising_gen)r'   r  r  r%  r   )r   Ztestfuncr  r:  r  r  r   r  r   "_check_generator_cleanup_exc_statep  s   
z1ExceptionTests._check_generator_cleanup_exc_statec                 C      dd }|  | d S )Nc                 S   s(   z	|  t  W d S  ty   Y d S w r   )r/  rG   r  r   r   r   do_throw  s
   zGExceptionTests.test_generator_throw_cleanup_exc_state.<locals>.do_throwr;  )r   r=  r   r   r   &test_generator_throw_cleanup_exc_state  s   z5ExceptionTests.test_generator_throw_cleanup_exc_statec                 C   r<  )Nc                 S   s   |    d S r   )rW   r  r   r   r   do_close     zGExceptionTests.test_generator_close_cleanup_exc_state.<locals>.do_closer>  )r   r@  r   r   r   &test_generator_close_cleanup_exc_state     z5ExceptionTests.test_generator_close_cleanup_exc_statec                 C   r<  )Nc                 S   s   d } d S r   r   r  r   r   r   do_del  r*   zCExceptionTests.test_generator_del_cleanup_exc_state.<locals>.do_delr>  )r   rD  r   r   r   $test_generator_del_cleanup_exc_state  rC  z3ExceptionTests.test_generator_del_cleanup_exc_statec                        fdd}  | d S )Nc                    s0   zt |  W n
 ty   Y d S w  d d S Nz should have raised StopIteration)r%  r)  r_   r  r(   r   r   do_next  s   zEExceptionTests.test_generator_next_cleanup_exc_state.<locals>.do_nextr>  )r   rH  r   r(   r   %test_generator_next_cleanup_exc_state     z4ExceptionTests.test_generator_next_cleanup_exc_statec                    rF  )Nc                    s2   z|  d  W n
 ty   Y d S w  d d S rG  )sendr)  r_   r  r(   r   r   do_send  s   zEExceptionTests.test_generator_send_cleanup_exc_state.<locals>.do_sendr>  )r   rL  r   r(   r   %test_generator_send_cleanup_exc_state  rJ  z4ExceptionTests.test_generator_send_cleanup_exc_statec                    s:   G  fddd}d zt |    Y |  d d S )Nc                       s   e Zd Z fddZdS )z*ExceptionTests.test_3114.<locals>.MyObjectc                    s   t   d S r   )rU   r   r(   r   r   r   __del__  s   z2ExceptionTests.test_3114.<locals>.MyObject.__del__Nr   r   r   rN  r   r   r   r   MyObject  s    rP  r   r(  )r'   r0   )r   rP  r   r   r   	test_3114  s   
zExceptionTests.test_3114c                 C   sH  G dd dt }G dd dt }G dd dt }z[z| |ys } zL|}z| |yn } z;|}z| |yi } z*|}	| || | || | |	| | |j | |j| | |	j| |d }~ww d }~ww d }~ww  |y }
 z|
}W Y d }
~
nd }
~
ww | || | |j|	 | |	j| | |j d S )Nc                   @   r   )zHExceptionTests.test_raise_does_not_create_context_chain_cycle.<locals>.ANr   r   r   r   r   A  r   rR  c                   @   r   )zHExceptionTests.test_raise_does_not_create_context_chain_cycle.<locals>.BNr   r   r   r   r   B  r   rS  c                   @   r   )zHExceptionTests.test_raise_does_not_create_context_chain_cycle.<locals>.CNr   r   r   r   r   C  r   rT  )r'   r   r   r   r   )r   rR  rS  rT  Za_r   Zb_r  Zc_crc   r,   r   r   r   .test_raise_does_not_create_context_chain_cycle  sJ   z=ExceptionTests.test_raise_does_not_create_context_chain_cyclec              
   C   sl   dd }z|  W n t y } z|}W Y d }~nd }~ww | |t | |jt | |jj|j d S )Nc               
   S   s0   zt d t y }  z| | _tdd } ~ ww NrE   r}   )rP   r   rO   exr   r   r   cycle  s   zBExceptionTests.test_no_hang_on_context_chain_cycle1.<locals>.cycle)r'   r   rO   r   rP   r   )r   rZ  rc   r,   r   r   r   $test_no_hang_on_context_chain_cycle1  s   
z3ExceptionTests.test_no_hang_on_context_chain_cycle1zSee issue 44895c                 C   s   G dd dt }G dd dt }G dd dt }| |<}z|  |yX } z+|}z|  |yS } z|}z|  |yN }	 z|	}
|
|_|
d }	~	ww d }~ww d }~ww 1 s\w   Y  | |j|
 | |
j| | |j| | |j|
 d S )Nc                   @   r   )z>ExceptionTests.test_no_hang_on_context_chain_cycle2.<locals>.ANr   r   r   r   r   rR    r   rR  c                   @   r   )z>ExceptionTests.test_no_hang_on_context_chain_cycle2.<locals>.BNr   r   r   r   r   rS    r   rS  c                   @   r   )z>ExceptionTests.test_no_hang_on_context_chain_cycle2.<locals>.CNr   r   r   r   r   rT    r   rT  r'   rS   r   r   rn   )r   rR  rS  rT  rz   _ar   _br  _crU  r   r   r   $test_no_hang_on_context_chain_cycle2  s:   z3ExceptionTests.test_no_hang_on_context_chain_cycle2c                 C   sd  G dd dt }G dd dt }G dd dt }G dd dt }G d	d
 d
t }| |Q}z|  |y} } z@|}z|  |yx }	 z.|	}
z|  |ys } z|}||_z|  |yn } z|}| }|d }~ww d }~ww d }	~	ww d }~ww 1 sw   Y  | |j| | |j| | |j| | |j|
 | |
j| | |j| d S )Nc                   @   r   )z>ExceptionTests.test_no_hang_on_context_chain_cycle3.<locals>.ANr   r   r   r   r   rR    r   rR  c                   @   r   )z>ExceptionTests.test_no_hang_on_context_chain_cycle3.<locals>.BNr   r   r   r   r   rS  !  r   rS  c                   @   r   )z>ExceptionTests.test_no_hang_on_context_chain_cycle3.<locals>.CNr   r   r   r   r   rT  #  r   rT  c                   @   r   )z>ExceptionTests.test_no_hang_on_context_chain_cycle3.<locals>.DNr   r   r   r   r   D%  r   ra  c                   @   r   )z>ExceptionTests.test_no_hang_on_context_chain_cycle3.<locals>.ENr   r   r   r   r   E'  r   rb  r\  )r   rR  rS  rT  ra  rb  rz   r]  r   r^  r  r_  rU  Z_ddrc   r   r   r   $test_no_hang_on_context_chain_cycle3  sP   z3ExceptionTests.test_no_hang_on_context_chain_cycle3c                 C   sf  t ddddd}| t|d d|_| t|d d|_d	|_| t|d
 d|_| t|d d|_| t|d tddddd}| t|d d|_| t|d d|_d	|_| t|d d|_| t|d d|_| t|d tdddd}| t|d d|_| t|d d|_d	|_| t|d d|_| t|d d S )Nr   ZxxxxxrE   r   r   z8'baz' codec can't encode characters in position 1-4: foor}   z<'baz' codec can't encode character '\x78' in position 1: fool   ESh
MQ)EzJ'baz' codec can't encode characters in position 1-4: 965230951443685724997i  zK'4000' codec can't encode characters in position 1-4: 965230951443685724997i  zN'4000' codec can't encode characters in position 1000-4: 965230951443685724997s   xxxxxz3'baz' codec can't decode bytes in position 1-4: fooz5'baz' codec can't decode byte 0x78 in position 1: foozE'baz' codec can't decode bytes in position 1-4: 965230951443685724997zF'4000' codec can't decode bytes in position 1-4: 965230951443685724997zI'4000' codec can't decode bytes in position 1000-4: 965230951443685724997Zxxxxz/can't translate characters in position 1-4: fooz3can't translate character '\x78' in position 1: foozAcan't translate characters in position 1-4: 965230951443685724997zDcan't translate characters in position 1000-4: 965230951443685724997)	r   r0   r/   r   r   r8   r   r   r   )r   ur   r   r   test_unicode_change_attributesK  s>   z-ExceptionTests.test_unicode_change_attributesc                 C   s.   t ttf}|D ]}| t||d qd S )N )r   r   r   r0   r/   __new__)r   Zklassesklassr   r   r   test_unicode_errors_no_objectp  s   
z,ExceptionTests.test_unicode_errors_no_objectc                    s   G dd dt }G dd dt|d}t 3}zt  |y0 } z| d W Y d }~nd }~w ty8   Y n	   | d Y W d    n1 sKw   Y   fdd	   \}}}| |tt | | d
t| d S )Nc                   @   r   )z/ExceptionTests.test_badisinstance.<locals>.Metac                 S      t  r   r  )clssubclassr   r   r   __subclasscheck__{  r   zAExceptionTests.test_badisinstance.<locals>.Meta.__subclasscheck__N)r   r   r   rn  r   r   r   r   Metaz  r   ro  c                   @   r   )z6ExceptionTests.test_badisinstance.<locals>.MyExceptionNr   r   r   r   r   r   }  r   r   )	metaclassz%exception should not be a MyExceptionzShould have raised KeyErrorc                      s$   z  W S  t y   t  Y S w r   )rH   rU   r   r   r  r   r   r    s
   z,ExceptionTests.test_badisinstance.<locals>.gz maximum recursion depth exceeded)	r   r'   r   r?   r_   r   rH   ry   r/   )r   ro  r   r   rc   vr   r   r  r   test_badisinstancev  s$   z!ExceptionTests.test_badisinstancec                 C   s   dd }|  t   d S )Nc                  S   s   t  } tdD ]}| j} qd S )Ni@B )r   r]   __dir__)or   r   r   r   r     s   z3ExceptionTests.test_trashcan_recursion.<locals>.foo)r   r   )r   r   r   r   r   test_trashcan_recursion  s   z&ExceptionTests.test_trashcan_recursionc                 C   sP   dt  }tdd|\}}}| |d | d| | d| | d| d S )Na  if 1:
            import sys
            from _testinternalcapi import get_recursion_depth

            class MyException(Exception): pass

            def setrecursionlimit(depth):
                while 1:
                    try:
                        sys.setrecursionlimit(depth)
                        return depth
                    except RecursionError:
                        # sys.setrecursionlimit() raises a RecursionError if
                        # the new recursion limit is too low (issue #25274).
                        depth += 1

            def recurse(cnt):
                cnt -= 1
                if cnt:
                    recurse(cnt)
                else:
                    generator.throw(MyException)

            def gen():
                f = open(%a, mode='rb', buffering=0)
                yield

            generator = gen()
            next(generator)
            recursionlimit = sys.getrecursionlimit()
            depth = get_recursion_depth()
            try:
                # Upon the last recursive invocation of recurse(),
                # tstate->recursion_depth is equal to (recursion_limit - 1)
                # and is equal to recursion_limit when _gen_throw() calls
                # PyErr_NormalizeException().
                recurse(setrecursionlimit(depth + 2) - depth)
            finally:
                sys.setrecursionlimit(recursionlimit)
                print('Done.')
        -Wd-crE   s   RecursionErrors   ResourceWarning   Done.)__file__r   assert_python_failurer0   ry   r   r   rcoutr1   r   r   r   $test_recursion_normalizing_exception  s   ()z3ExceptionTests.test_recursion_normalizing_exceptionc                 C   s>   d}t d|\}}}| |d | d| | d| d S )Nzif 1:
            import _testcapi
            try:
                raise _testcapi.RecursingInfinitelyError
            finally:
                print('Done.')
        rw  rE   sO   RecursionError: maximum recursion depth exceeded while normalizing an exceptionrx  )r   rz  r0   ry   r{  r   r   r   -test_recursion_normalizing_infinite_exception  s   z<ExceptionTests.test_recursion_normalizing_infinite_exceptionc              
      s   dd }fdd fdd fddt  }z>|d	  fD ],}| j|d
 z|  W n	 ty;   Y nw | d W d    q$1 sKw   Y  q$W t | d S t | w )Nc                 S   sF   d}	 zt | W n ty   |d7 }Y nw qqt ||   d S )NrE   T)rU   setrecursionlimitrH   )nZdepthr   r   r   set_relative_recursion_limit  s   zUExceptionTests.test_recursion_in_except_handler.<locals>.set_relative_recursion_limitc                      s"   zdd  W d S       Y d S r1  r   r   )recurse_in_exceptr   r   r    s   zJExceptionTests.test_recursion_in_except_handler.<locals>.recurse_in_exceptc                      s    zdd  W n   Y    d S r1  r   r   )recurse_after_exceptr   r   r    s
   
zMExceptionTests.test_recursion_in_except_handler.<locals>.recurse_after_exceptc                      s    z   W d S       Y d S r   r   r   )recurse_in_body_and_exceptr   r   r    s   zSExceptionTests.test_recursion_in_except_handler.<locals>.recurse_in_body_and_exceptr>   )funcz#Should have raised a RecursionError)rU   getrecursionlimitr.   rH   r_   r  )r   r  Zrecursionlimitr  r   )r  r  r  r    test_recursion_in_except_handler  s&   

	z/ExceptionTests.test_recursion_in_except_handlerc                 C   sN   d}t   td|\}}}| d| W d    d S 1 s w   Y  d S )Na+  if 1:
            import _testcapi
            class C(): pass
            def recurse(cnt):
                cnt -= 1
                if cnt:
                    recurse(cnt)
                else:
                    _testcapi.set_nomemory(0)
                    C()
            recurse(16)
        rw  sm   Fatal Python error: _PyErr_NormalizeException: Cannot recover from MemoryErrors while normalizing exceptions.)r	   r   rz  ry   r{  r   r   r   )test_recursion_normalizing_with_no_memory!  s   "z8ExceptionTests.test_recursion_normalizing_with_no_memoryc                    s@   dd l ddlm   fdd}| }| }|| d S )Nr   raise_memoryerrorc               
      sJ   z   W n t y }  z	| j}W Y d } ~ n
d } ~ ww d |S )Nz Should have raised a MemoryError)rB   r   r_   	format_tb)rc   r   r  r   	tracebackr   r   raiseMemError?  s   


z6ExceptionTests.test_MemoryError.<locals>.raiseMemError)r  r   r  r0   )r   r  Ztb1Ztb2r   r  r   test_MemoryError9  s   	zExceptionTests.test_MemoryErrorc           
      C   s"  dd l }d}d}| t|jd |d}| t|t | t|t | 	|j
 |d|}| |j
| |jd|d}| t|| G d	d
 d
t}|d|||f}| t|| | t|| | |j
| |dd|ddi}	| t|	| | |	jd | |	j
d d S )Nr   zThis is a test docstring.zThis is another test docstring.error1z_testcapi.error1z_testcapi.error2z_testcapi.error3)basec                   @   r   )z1ExceptionTests.test_exception_with_doc.<locals>.CNr   r   r   r   r   rT  e  r   rT  z_testcapi.error4z_testcapi.error5rg  r   rE   )r   rS   rM   Zmake_exception_with_docr   r   r   
issubclassr'   r   __doc__r0   r   r   )
r   r   Zdoc2Zdoc4r  Zerror2Zerror3rT  Zerror4Zerror5r   r   r   test_exception_with_docL  s:   

z&ExceptionTests.test_exception_with_docc              
      s   ddl m G dd d d  fdd}z|  W n ty5 } z|  d  W Y d }~n
d }~ww | d |  d  d S )Nr   r  c                   @   r   )z3ExceptionTests.test_memory_error_cleanup.<locals>.CNr   r   r   r   r   rT  y  r   rT  c                          } t |   d S r   r  r  rU  rT  r  r  r   r   inner|     

z7ExceptionTests.test_memory_error_cleanup.<locals>.innerzMemoryError not raised)r   r  rB   assertNotEqualr_   r0   )r   r  rc   r   r  r   test_memory_error_cleanupt  s   

z(ExceptionTests.test_memory_error_cleanupc              
      s|   G dd d d  fddz  W n t y/ } z|  d  W Y d }~n
d }~ww | d |  d  d S )Nc                   @   r   )z6ExceptionTests.test_recursion_error_cleanup.<locals>.CNr   r   r   r   r   rT    r   rT  c                     r  r   r  r  rT  r  r  r   r   r    r  z:ExceptionTests.test_recursion_error_cleanup.<locals>.innerzRecursionError not raised)rH   r  r_   r0   r   r   r  r   test_recursion_error_cleanup  s   

z+ExceptionTests.test_recursion_error_cleanupc                 C   sN   |  t}tt W d    n1 sw   Y  | |jjtj|j d S r   )	rS   r;   oslistdirry  r0   rn   r   ENOTDIR)r   rz   r   r   r   test_errno_ENOTDIR  s   z!ExceptionTests.test_errno_ENOTDIRc                 C   sd   G dd d}| }t  }~| |jj|j | |jj W d    d S 1 s+w   Y  d S )Nc                   @   r   )z1ExceptionTests.test_unraisable.<locals>.BrokenDelc                 S   s   t d}|)Nzdel is brokenr  r   r,   r   r   r   rN    s   z9ExceptionTests.test_unraisable.<locals>.BrokenDel.__del__NrO  r   r   r   r   	BrokenDel  r   r  )r   Zcatch_unraisable_exceptionr0   Z
unraisabler   rN  ZassertIsNotNoneexc_traceback)r   r  r  rz   r   r   r   test_unraisable  s   
"zExceptionTests.test_unraisablec                 C   s   t tfD ]q}| |b z|d}| |y5   t }tjt   W d    n1 s.w   Y  Y nw | }| d| | d| | |j	| |tu rX| d| n| d| | 
|d W d    q1 spw   Y  qd S )Nztest messager   z	raise excz<exception str() failed>rt   )rP   r$   r.   r   rU   __excepthook__r   getvaluery   r   r   r   )r   r  r,   r   reportr   r   r   test_unhandled  s*   zExceptionTests.test_unhandledc                 C   sF   d}t ddD ]}td|| \}}}| |d | d| qd S )Nzif 1:
            import _testcapi
            class C(): pass
            _testcapi.set_nomemory(0, %d)
            C()
        rE   r   rw  )rE   x   s   MemoryError)r]   r   rz  ry   )r   r   r  r|  r}  r1   r   r   r   "test_memory_error_in_PyErr_PrintEx  s   
z1ExceptionTests.test_memory_error_in_PyErr_PrintExc                    sz   G dd dt  G dd dt  fdd}| }|d  |   |  W d    d S 1 s6w   Y  d S )Nc                   @   r   )zBExceptionTests.test_yield_in_nested_try_excepts.<locals>.MainErrorNr   r   r   r   r   	MainError  r   r  c                   @   r   )zAExceptionTests.test_yield_in_nested_try_excepts.<locals>.SubErrorNr   r   r   r   r   SubError  r   r  c                   3   s6    z    y   zd V  W   y   Y  w w r   r   r   r  r  r   r   main  s   z=ExceptionTests.test_yield_in_nested_try_excepts.<locals>.main)r'   rK  rS   r/  )r   r  coror   r  r    test_yield_in_nested_try_excepts  s   

"z/ExceptionTests.test_yield_in_nested_try_exceptsc                    sN    fdd}| }zt  t y    t|d Y nw  t|d d S )Nc                   3   s:    zt  t y   dV  Y nw  t d dV  d S )NrE   r(  r}   )rP   r0   rU   r   r   r(   r   r   r    s   

z?ExceptionTests.test_generator_doesnt_retain_old_exc2.<locals>.grE   r}   )r=   r0   r%  )r   r  r6  r   r(   r   %test_generator_doesnt_retain_old_exc2  s   z4ExceptionTests.test_generator_doesnt_retain_old_exc2c                 C   st   dd }|  t' | }zdd  W n   t| t| Y W d    d S W d    d S 1 s3w   Y  d S )Nc                   s   s
    dV   rW  r   r   r   r   r   r    s   z1ExceptionTests.test_raise_in_generator.<locals>.grE   r   )rS   rQ   r%  )r   r  r  r   r   r   test_raise_in_generator  s   "z&ExceptionTests.test_raise_in_generatorTz Won't work if __debug__ is Falsec              
   C   sR   t azJ d ty( } zb| |t | t|d W Y d }~d S d }~ww )NFZhellor   )rO   AssertionErrorr   r   r0   r/   r_   r   r   r   r   test_assert_shadowing  s   z$ExceptionTests.test_assert_shadowingc                 C   s   G dd dt }zt  t y } z|}W Y d }~nd }~ww z| ty*   Y nw tdD ]}zt  t yE } zW Y d }~nd }~ww t  q/d S )Nc                   @   r   )zBExceptionTests.test_memory_error_subclasses.<locals>.TestExceptionNr   r   r   r   r   TestException*  r   r  r>   )rB   r'   r]   r   )r   r  r,   inst_r   r   r   test_memory_error_subclasses!  s*   	z+ExceptionTests.test_memory_error_subclassesN)r6   )Fr   r   r   r2   rd   rm   ro   r|   r   r   r   r   unittestZ
skipUnlessrU   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r#  r&  r,  r0  r3  r4  r9  r;  r?  rB  rE  rI  rM  rQ  rV  r[  skipr`  rd  rf  rj  rr  ru  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r+   &   s    T
)H
/'
 

t

(
$/%


:
/


'




r+   c                   @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )NameErrorTestsc              
   C   s@   zt  W d S  ty } z| d|j W Y d }~d S d }~ww )Nbluch)r  rC   r0   namer  r   r   r   test_name_error_has_nameB  s   
z'NameErrorTests.test_name_error_has_namec                 C   s   dd }dd }dd }dd }d	d
 }dd }|df|df|df|df|df|dffD ]A\}}d }	z|  W n- t yd }
 z!t }	tjt   W d    n1 sUw   Y  W Y d }
~
nd }
~
ww | ||	  q,d S )Nc                  S       d  }  } }}d }t t d S r   r   r  )noise
more_noiser   bcblechr   r   r   SubstitutionI     z@NameErrorTests.test_name_error_suggestions.<locals>.Substitutionc                  S   r  r   r  )r  r  r   r  blchr   r   r   EliminationN  r  z?NameErrorTests.test_name_error_suggestions.<locals>.Eliminationc                  S   r  r   r  )r  r  r   r  bluchinr   r   r   AdditionS  r  z<NameErrorTests.test_name_error_suggestions.<locals>.Additionc                  S      d } d }t t d S r   r  )blachblucr   r   r   SubstitutionOverEliminationX     zONameErrorTests.test_name_error_suggestions.<locals>.SubstitutionOverEliminationc                  S   r  r   r  )r  bluchir   r   r   SubstitutionOverAddition]  r  zLNameErrorTests.test_name_error_suggestions.<locals>.SubstitutionOverAdditionc                  S   r  r   r  )bluchar  r   r   r   EliminationOverAdditionb  r  zKNameErrorTests.test_name_error_suggestions.<locals>.EliminationOverAddition'blech'?'blch'?
'bluchin'?z	'blucha'?'blach'?rC   r   r   rU   r  r   ry   r  )r   r  r  r  r  r  r  r  
suggestionr1   r,   r   r   r   test_name_error_suggestionsH  s0   

z*NameErrorTests.test_name_error_suggestionsc                 C      dd }z|  W n- t y6 } z!t }tjt   W d    n1 s'w   Y  W Y d }~nd }~ww | d|  d S )Nc                   S      t t d S r   )r   Zglobal_for_suggestior   r   r   r   r  v  rA  zENameErrorTests.test_name_error_suggestions_from_globals.<locals>.funcz'global_for_suggestions'?r  r   r  r,   r1   r   r   r   (test_name_error_suggestions_from_globalsu     

z7NameErrorTests.test_name_error_suggestions_from_globalsc                 C   r  )Nc                   S   r  r   )r   ZZeroDivisionErrrrrr   r   r   r   r    rA  zFNameErrorTests.test_name_error_suggestions_from_builtins.<locals>.funcz'ZeroDivisionError'?r  r  r   r   r   )test_name_error_suggestions_from_builtins  r  z8NameErrorTests.test_name_error_suggestions_from_builtinsc                 C   r  )Nc                  S   s   d } t t d S r   )r   Zsomethingverywronghe)Zsomethingverywrongheheheheheher   r   r   r     s   zSNameErrorTests.test_name_error_suggestions_do_not_trigger_for_long_names.<locals>.fZsomethingverywrongheherC   r   r   rU   r  r   r  r  r   r   r,   r1   r   r   r   9test_name_error_suggestions_do_not_trigger_for_long_names  s   

zHNameErrorTests.test_name_error_suggestions_do_not_trigger_for_long_namesc                 C   s  d  } } } }}| j ddj zt W n- tyB } z!t }tjt   W d    n1 s3w   Y  W Y d }~nd }~ww | d|	  | d|	  | d|	  | d|	  | d|	  | d|	  W d    n1 s}w   Y  | j d	dj zt
 W n- ty } z!t }tjt   W d    n1 sw   Y  W Y d }~nd }~ww | d|	  | d|	  | d|	  | d|	  | d|	  | d|	  W d    n1 sw   Y  | j d
dl zt W n/ ty4 } z"t }tjt   W d    n	1 s%w   Y  W Y d }~nd }~ww | d|	  | d|	  | d|	  | d|	  | d|	  | d|	  W d    n	1 spw   Y  | j ddm zt W n/ ty } z"t }tjt   W d    n	1 sw   Y  W Y d }~nd }~ww | d|	  | d|	  | d|	  | d|	  | d|	  | d|	  W d    d S 1 sw   Y  d S )Nr  r  you meanvvvmom'id''w''pytho'rq  mpy)r.   r  rC   r   r   rU   r  r   r  r  rq  r  r  )r   r  r  r5   idpythor,   r1   r   r   r   >test_name_error_bad_suggestions_do_not_trigger_for_small_names  s   



$zMNameErrorTests.test_name_error_bad_suggestions_do_not_trigger_for_small_namesc                 C   r  )Nc                  S   s  d  }  } } } } } } } } }	 }
 } } } } } } } } } } } } } } } } } } } } } }  }! }" }# }$ }% }& }' }( }) }* }+ }, }- }. }/ }0 }1 }2 }3 }4 }5 }6 }7 }8 }9 }: }; }< }= }> }? }@ }A }B }C }D }E }F }G }H }I }J }K }L }M }N }O }P }Q }R }S }T }U }V }W }X }Y }Z }[ }\ }] }^ }_ }` }a }b }c }d }e }f }g }h }i }j }k }l }m }n }o }p }q }r }s }t }u }v }w }x }y }z }{ }| }} }~ } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } }  } } } } } } } } }	 }
 } } } } } } } } } } } } } } } } } } } } } }  }! }" }# }$ }% }& }' }( }) }* }+ }, }- }. }/ }0 }1 }2 }3 }4 }5 }6 }7 }8 }9 }: }; }< }= }> }? }@ }A }B }C }D }E }F }G }H }I }J }K }L }M }N }O }P }Q }R }S }T }U }V }W }X }Y }Z }[ }\ }] }^ }_ }` }a }b }c }d }e }f }g }h }i }j }k }l }m }n }o }p }q }r }s }t }u }v }w }x }y }z }{ }| }} }~ } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } }  } } } } } } } } }	 }
 } } } } } } } } } } } } } } } } } } } } } }  }! }" }# }$ }% }& }' }( }) }* }+ }, }- }. }/ }0 }1 }2 }3 }4 }5 }6 }7 }8 }9 }: }; }< }= }> }? }@ }A }B }C }D }E }F }G }H }I }J }K }L }M }N }O }P }Q }R }S }T }U }V }W }X }Y }Z }[ }\ }] }^ }_ }` }a }b }c }d }e }f }g }h }i }j }k }l }m }n }o }p }q }r }s }t }u }v }w }x }y }z }{ }| }} }~ } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } }  } } } } } } } } }	 }
 } } } } } } } } } } } } } } } } } } } }}t t d S r   )r   Za0(   a1Za2Za3Za4Za5Za6Za7Za8Za9Za10Za11Za12Za13Za14Za15Za16Za17Za18Za19Za20Za21Za22Za23Za24Za25Za26Za27Za28Za29Za30Za31Za32Za33Za34Za35Za36Za37Za38Za39Za40Za41Za42Za43Za44Za45Za46Za47Za48Za49Za50Za51Za52Za53Za54Za55Za56Za57Za58Za59Za60Za61Za62Za63Za64Za65Za66Za67Za68Za69Za70Za71Za72Za73Za74Za75Za76Za77Za78Za79Za80Za81Za82Za83Za84Za85Za86Za87Za88Za89Za90Za91Za92Za93Za94Za95Za96Za97Za98Za99Za100Za101Za102Za103Za104Za105Za106Za107Za108Za109Za110Za111Za112Za113Za114Za115Za116Za117Za118Za119Za120Za121Za122Za123Za124Za125Za126Za127Za128Za129Za130Za131Za132Za133Za134Za135Za136Za137Za138Za139Za140Za141Za142Za143Za144Za145Za146Za147Za148Za149Za150Za151Za152Za153Za154Za155Za156Za157Za158Za159Za160Za161Za162Za163Za164Za165Za166Za167Za168Za169Za170Za171Za172Za173Za174Za175Za176Za177Za178Za179Za180Za181Za182Za183Za184Za185Za186Za187Za188Za189Za190Za191Za192Za193Za194Za195Za196Za197Za198Za199Za200Za201Za202Za203Za204Za205Za206Za207Za208Za209Za210Za211Za212Za213Za214Za215Za216Za217Za218Za219Za220Za221Za222Za223Za224Za225Za226Za227Za228Za229Za230Za231Za232Za233Za234Za235Za236Za237Za238Za239Za240Za241Za242Za243Za244Za245Za246Za247Za248Za249Za250Za251Za252Za253Za254Za255Za256Za257Za258Za259Za260Za261Za262Za263Za264Za265Za266Za267Za268Za269Za270Za271Za272Za273Za274Za275Za276Za277Za278Za279Za280Za281Za282Za283Za284Za285Za286Za287Za288Za289Za290Za291Za292Za293Za294Za295Za296Za297Za298Za299Za300Za301Za302Za303Za304Za305Za306Za307Za308Za309Za310Za311Za312Za313Za314Za315Za316Za317Za318Za319Za320Za321Za322Za323Za324Za325Za326Za327Za328Za329Za330Za331Za332Za333Za334Za335Za336Za337Za338Za339Za340Za341Za342Za343Za344Za345Za346Za347Za348Za349Za350Za351Za352Za353Za354Za355Za356Za357Za358Za359Za360Za361Za362Za363Za364Za365Za366Za367Za368Za369Za370Za371Za372Za373Za374Za375Za376Za377Za378Za379Za380Za381Za382Za383Za384Za385Za386Za387Za388Za389Za390Za391Za392Za393Za394Za395Za396Za397Za398Za399Za400Za401Za402Za403Za404Za405Za406Za407Za408Za409Za410Za411Za412Za413Za414Za415Za416Za417Za418Za419Za420Za421Za422Za423Za424Za425Za426Za427Za428Za429Za430Za431Za432Za433Za434Za435Za436Za437Za438Za439Za440Za441Za442Za443Za444Za445Za446Za447Za448Za449Za450Za451Za452Za453Za454Za455Za456Za457Za458Za459Za460Za461Za462Za463Za464Za465Za466Za467Za468Za469Za470Za471Za472Za473Za474Za475Za476Za477Za478Za479Za480Za481Za482Za483Za484Za485Za486Za487Za488Za489Za490Za491Za492Za493Za494Za495Za496Za497Za498Za499Za500Za501Za502Za503Za504Za505Za506Za507Za508Za509Za510Za511Za512Za513Za514Za515Za516Za517Za518Za519Za520Za521Za522Za523Za524Za525Za526Za527Za528Za529Za530Za531Za532Za533Za534Za535Za536Za537Za538Za539Za540Za541Za542Za543Za544Za545Za546Za547Za548Za549Za550Za551Za552Za553Za554Za555Za556Za557Za558Za559Za560Za561Za562Za563Za564Za565Za566Za567Za568Za569Za570Za571Za572Za573Za574Za575Za576Za577Za578Za579Za580Za581Za582Za583Za584Za585Za586Za587Za588Za589Za590Za591Za592Za593Za594Za595Za596Za597Za598Za599Za600Za601Za602Za603Za604Za605Za606Za607Za608Za609Za610Za611Za612Za613Za614Za615Za616Za617Za618Za619Za620Za621Za622Za623Za624Za625Za626Za627Za628Za629Za630Za631Za632Za633Za634Za635Za636Za637Za638Za639Za640Za641Za642Za643Za644Za645Za646Za647Za648Za649Za650Za651Za652Za653Za654Za655Za656Za657Za658Za659Za660Za661Za662Za663Za664Za665Za666Za667Za668Za669Za670Za671Za672Za673Za674Za675Za676Za677Za678Za679Za680Za681Za682Za683Za684Za685Za686Za687Za688Za689Za690Za691Za692Za693Za694Za695Za696Za697Za698Za699Za700Za701Za702Za703Za704Za705Za706Za707Za708Za709Za710Za711Za712Za713Za714Za715Za716Za717Za718Za719Za720Za721Za722Za723Za724Za725Za726Za727Za728Za729Za730Za731Za732Za733Za734Za735Za736Za737Za738Za739Za740Za741Za742Za743Za744Za745Za746Za747Za748Za749Za750Za751Za752Za753Za754Za755Za756Za757Za758Za759Za760Za761Za762Za763Za764Za765Za766Za767Za768Za769Za770Za771Za772Za773Za774Za775Za776Za777Za778Za779Za780Za781Za782Za783Za784Za785Za786Za787Za788Za789Za790Za791Za792Za793Za794Za795Za796Za797Za798Za799Za800r   r   r   r     sX  R*										









          !!!!!!!!!!""""""""""##########$$$$$$$$$$%%%%%%%%%%&&&&&&&&&&''''''''''(((((((((())))))))))**********++++++++++,,,,,,,,,,----------..........//////////0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999::::::::::;;;;;;;;;;<<<<<<<<<<==========>>>>>>>>>>??????????@@@@@@@@@@AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEEFFFFFFFFFFGGGGGGGGGGHHHHHHHHHHIIIIIIIIIIJJJJJJJJJJKKKKKKKKKKLLLLLLLLLLMMMMMMMMMMNNNNNNNNNNOOOOOOOOOzXNameErrorTests.test_name_error_suggestions_do_not_trigger_for_too_many_locals.<locals>.fr  r  r  r   r   r   >test_name_error_suggestions_do_not_trigger_for_too_many_locals  s   U

zMNameErrorTests.test_name_error_suggestions_do_not_trigger_for_too_many_localsc                 C   s   dd }z|  W n- t y6 } z!t }tjt   W d    n1 s'w   Y  W Y d }~nd }~ww | d|  dd }z|  W n- t yu } z!t }tjt   W d    n1 sfw   Y  W Y d }~nd }~ww | d|  d S )Nc                  S   s
   d } t  r   rC   r  r   r   r   r   ,  s   z@NameErrorTests.test_name_error_with_custom_exceptions.<locals>.fr  c                  S   s   d } t r   r  r  r   r   r   r   8  s   r  r  r   r   r   &test_name_error_with_custom_exceptions+  s(   



z5NameErrorTests.test_name_error_with_custom_exceptionsc                 C   r  )Nc                  S   s   d} t | d}d S )Nr   )r   )r"  Z	somethongr   r   r   r   E  s   zDNameErrorTests.test_unbound_local_error_doesn_not_match.<locals>.foor"  )UnboundLocalErrorr   r   rU   r  r   r  r  )r   r   r,   r1   r   r   r   (test_unbound_local_error_doesn_not_matchD  s   

z7NameErrorTests.test_unbound_local_error_doesn_not_matchN)r   r   r   r  r  r  r  r  r  r  r  r  r   r   r   r   r  A  s    -

7^r  c                   @   sl   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )AttributeErrorTestsc                 C   sT   t d}| |j | |j t }t dd|d}| |jd | |j| d S )NzOuch!ZOuchZcarryr  r  )r3   r   r  r  r   r0   r   )r   r,   sentinelr   r   r   test_attributesT  s   z#AttributeErrorTests.test_attributesc              
   C   sd   G dd d}| }z|j  W d S  ty1 } z| d|j | ||j W Y d }~d S d }~ww )Nc                   @      e Zd ZdZdS )z<AttributeErrorTests.test_getattr_has_name_and_obj.<locals>.ANr   r   r   r  r   r   r   r   rR  `      rR  r  r  r3   r0   r  r  r   rR  r  r,   r   r   r   test_getattr_has_name_and_obj_  s   z1AttributeErrorTests.test_getattr_has_name_and_objc              
   C   sf   G dd d}| }z|   W d S  ty2 } z| d|j | ||j W Y d }~d S d }~ww )Nc                   @   r   )zGAttributeErrorTests.test_getattr_has_name_and_obj_for_method.<locals>.Ac                 S      d S r   r   r(   r   r   r   r  l  r  zMAttributeErrorTests.test_getattr_has_name_and_obj_for_method.<locals>.A.blechNr  r   r   r   r   rR  k  r   rR  r  r  r  r   r   r   (test_getattr_has_name_and_obj_for_methodj  s   z<AttributeErrorTests.test_getattr_has_name_and_obj_for_methodc                 C   s  G dd d}G dd d}G dd d}G dd d}G d	d
 d
}G dd d}|df|df|df|df|df|dffD ]@\}}z| j  W n- tyu }	 z!t }
tjt   W d    n1 sfw   Y  W Y d }	~	nd }	~	ww | ||
  q>d S )Nc                   @       e Zd Zd Z Z ZZdZdS )zBAttributeErrorTests.test_getattr_suggestions.<locals>.SubstitutionN)r   r   r   r  r  r   r  r  r   r   r   r   r  w      r  c                   @   r  )zAAttributeErrorTests.test_getattr_suggestions.<locals>.EliminationN)r   r   r   r  r  r   r  r  r   r   r   r   r  {  r  r  c                   @   r  )z>AttributeErrorTests.test_getattr_suggestions.<locals>.AdditionN)r   r   r   r  r  r   r  r  r   r   r   r   r    r  r  c                   @      e Zd ZdZdZdS )zQAttributeErrorTests.test_getattr_suggestions.<locals>.SubstitutionOverEliminationN)r   r   r   r  r  r   r   r   r   r        r  c                   @   r  )zNAttributeErrorTests.test_getattr_suggestions.<locals>.SubstitutionOverAdditionN)r   r   r   r  r  r   r   r   r   r    r	  r  c                   @   r  )zMAttributeErrorTests.test_getattr_suggestions.<locals>.EliminationOverAdditionN)r   r   r   r  r  r   r   r   r   r    r	  r  r  r  r  z'bluc'?r  	r  r3   r   r   rU   r  r   ry   r  )r   r  r  r  r  r  r  rl  r  r,   r1   r   r   r   test_getattr_suggestionsv  s.   
z,AttributeErrorTests.test_getattr_suggestionsc                 C      G dd d}z| j  W n- ty: } z!t }tjt   W d    n1 s+w   Y  W Y d }~nd }~ww | d|  d S )Nc                   @   r  )zZAttributeErrorTests.test_getattr_suggestions_do_not_trigger_for_long_attributes.<locals>.ANr  r   r   r   r   rR    r   rR  r  )	Zsomethingverywrongr3   r   r   rU   r  r   r  r  r   rR  r,   r1   r   r   r   ;test_getattr_suggestions_do_not_trigger_for_long_attributes     
zOAttributeErrorTests.test_getattr_suggestions_do_not_trigger_for_long_attributesc                 C   s  G dd d}| j ddk z|j W n- ty@ } z!t }tjt   W d    n1 s1w   Y  W Y d }~nd }~ww | d|	  | d|	  | d|	  | d|	  | d	|	  | d
|	  W d    n1 s{w   Y  | j ddk z|j
 W n- ty } z!t }tjt   W d    n1 sw   Y  W Y d }~nd }~ww | d|	  | d|	  | d|	  | d|	  | d	|	  | d
|	  W d    n1 sw   Y  | j ddm z|j W n/ ty4 } z"t }tjt   W d    n	1 s%w   Y  W Y d }~nd }~ww | d|	  | d|	  | d|	  | d|	  | d	|	  | d
|	  W d    n	1 spw   Y  | j ddn z|j W n/ ty } z"t }tjt   W d    n	1 sw   Y  W Y d }~nd }~ww | d|	  | d|	  | d|	  | d|	  | d	|	  | d
|	  W d    d S 1 sw   Y  d S )Nc                   @   s    e Zd Zd Z Z Z ZZdS )zfAttributeErrorTests.test_getattr_error_bad_suggestions_do_not_trigger_for_small_names.<locals>.MyClassN)r   r   r   r  r  r5   r  r  r   r   r   r   MyClass  s    r  r  r  r  r  r  r  r  r  rq  r  r  )r.   r  r3   r   r   rU   r  r   r  r  rq  r  r  )r   r  r,   r1   r   r   r   Atest_getattr_error_bad_suggestions_do_not_trigger_for_small_names  s   







$zUAttributeErrorTests.test_getattr_error_bad_suggestions_do_not_trigger_for_small_namesc                 C   s   G dd d}t dD ]}t|d| d  qz| j W n- tyJ } z!t }tjt   W d    n1 s;w   Y  W Y d }~nd }~ww | 	d|
  d S )Nc                   @   r  )zTAttributeErrorTests.test_getattr_suggestions_do_not_trigger_for_big_dicts.<locals>.ANr  r   r   r   r   rR    r   rR  i  Zindex_r  )r]   r   r  r3   r   r   rU   r  r   r  r  )r   rR  indexr,   r1   r   r   r   5test_getattr_suggestions_do_not_trigger_for_big_dicts  s   
zIAttributeErrorTests.test_getattr_suggestions_do_not_trigger_for_big_dictsc                 C   s  G dd d}z| j  W n- ty: } z!t }tjt   W d    n1 s+w   Y  W Y d }~nd }~ww | d|  G dd d}z| j  W n- ty} } z!t }tjt   W d    n1 snw   Y  W Y d }~nd }~ww | d|  d S )Nc                   @      e Zd ZdZdd ZdS )?AttributeErrorTests.test_getattr_suggestions_no_args.<locals>.ANc                 S   rk  r   r3   r   attrr   r   r   __getattr__  r   KAttributeErrorTests.test_getattr_suggestions_no_args.<locals>.A.__getattr__r   r   r   r  r  r   r   r   r   rR    r#   rR  r  c                   @   r  )r  Nc                 S      t r   r  r  r   r   r   r    r  r  r  r   r   r   r   rR     r#   r
  r  r   r   r    test_getattr_suggestions_no_args  s(   

z4AttributeErrorTests.test_getattr_suggestions_no_argsc                    s   G dd d G  fddd}G dd d}G dd d}|||fD ]>}z| j  W n- tyX } z!t }tjt   W d    n1 sIw   Y  W Y d }~nd }~ww | d	|  q#d S )
Nc                   @   r  )zTAttributeErrorTests.test_getattr_suggestions_invalid_args.<locals>.NonStringifyClassN)r   r   r   r)   __repr__r   r   r   r   NonStringifyClass  r	  r  c                       s   e Zd ZdZ fddZdS )zDAttributeErrorTests.test_getattr_suggestions_invalid_args.<locals>.ANc                    s
   t   r   r  r  r  r   r   r    r   zPAttributeErrorTests.test_getattr_suggestions_invalid_args.<locals>.A.__getattr__r  r   r   r   r   rR    s    rR  c                   @   r  )zDAttributeErrorTests.test_getattr_suggestions_invalid_args.<locals>.BNc                 S   s
   t dd)NError   r  r  r   r   r   r    r   zPAttributeErrorTests.test_getattr_suggestions_invalid_args.<locals>.B.__getattr__r  r   r   r   r   rS    r#   rS  c                   @   r  )zDAttributeErrorTests.test_getattr_suggestions_invalid_args.<locals>.CNc                 S   r%   )Nr"  r  r  r   r   r   r    r*   zPAttributeErrorTests.test_getattr_suggestions_invalid_args.<locals>.C.__getattr__r  r   r   r   r   rT    r#   rT  r  r
  )r   rR  rS  rT  rl  r,   r1   r   r   r   %test_getattr_suggestions_invalid_args  s   
z9AttributeErrorTests.test_getattr_suggestions_invalid_argsc                 C   r  )Nc                   @   r   )zEAttributeErrorTests.test_getattr_suggestions_for_same_name.<locals>.Ac                 S   s   dgS )Nr  r   r(   r   r   r   rs  ,  r   zMAttributeErrorTests.test_getattr_suggestions_for_same_name.<locals>.A.__dir__N)r   r   r   rs  r   r   r   r   rR  +  r   rR  zDid you mean)	r  r3   r   r   rU   r  r   r  r  r  r   r   r   &test_getattr_suggestions_for_same_name*  r  z:AttributeErrorTests.test_getattr_suggestions_for_same_namec                 C   s   G dd d}z| j  W n- ty: } z!t }tjt   W d    n1 s+w   Y  W Y d }~nd }~ww | d|  | d|  d S )Nc                   @   r    )zEAttributeErrorTests.test_attribute_error_with_failing_dict.<locals>.TrE   c                 S   r%   )Noh no!r  r(   r   r   r   rs  9  r*   zMAttributeErrorTests.test_attribute_error_with_failing_dict.<locals>.T.__dir__N)r   r   r   r  rs  r   r   r   r   T7  r#   r&  r  r%  )	Zblichr3   r   r   rU   r  r   r  r  )r   r&  r,   r1   r   r   r   &test_attribute_error_with_failing_dict6  s   
z:AttributeErrorTests.test_attribute_error_with_failing_dictc                 C   s|   zt ddd t y3 } z!t }tjt   W d    n1 s$w   Y  W Y d }~nd }~ww | d|  d S )N   r"  r  ?)r3   r   r   rU   r  r   r  r  )r   r,   r1   r   r   r   "test_attribute_error_with_bad_nameE  s   
z6AttributeErrorTests.test_attribute_error_with_bad_nameN)r   r   r   r  r  r  r  r  r  r  r  r#  r$  r'  r*  r   r   r   r   r  S  s    '9r  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ImportErrorTestsc                 C   s  t d}| |j | |j t ddd}| |jd | |j t ddd}| |jd | |j t dddd}| |jd | |jd d}| t| t dd	d
 W d    n1 sdw   Y  | t| t ddd	d W d    n1 sw   Y  | t| t ddd	d W d    n1 sw   Y  | t| t d	d
 W d    n1 sw   Y  | t| t dd	dd W d    d S 1 sw   Y  d S )NtestZ
somemoduler  somepathpathsomename)r/  r  z8'invalid' is an invalid keyword argument for ImportErrorkeyword)invalidr  )r  r2  r/  )r/  r2  T)r2  Zanother)r<   r   r  r/  r0   r   rO   )r   r,   rf   r   r   r   r  Q  s8   "z ImportErrorTests.test_attributesc                 C   s   t dddd}| |jd | |jd | |jd | |jd |  | |jd | |jd  | |jd  | |jd  d S )Nr,  r  r/  r  r/  r,  r   )r<   r0   r   rf   r  r/  r   r  r   r   r   test_reset_attributess  s   z&ImportErrorTests.test_reset_attributesc                 C   sV   t dtfdd d}t|}| t|t| W d    d S 1 s$w   Y  d S )Nrg  T)quiets   abc)r   BytesWarningr<   r0   r/   )r   argr,   r   r   r   test_non_str_argument  s
   "z&ImportErrorTests.test_non_str_argumentc                 C   s   t  t ddt ddt dddfD ]e}tdi |}ttjd D ])}tt||}| |jd | |j	d | |j
|j
 | |j|j q!tjtjfD ]$}||}| |jd | |j	d | |j
|j
 | |j|j qQqd S )	Nr0  r  r-  r.  r3  r,  rE   r4  )dictr<   r]   r   r   rZ   r   r0   r   rf   r  r/  copydeepcopy)r   kwargsZorigprotor,   rU  r   r   r   test_copy_pickle  s(   
z!ImportErrorTests.test_copy_pickleN)r   r   r   r  r5  r9  r?  r   r   r   r   r+  O  s
    "r+  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )SyntaxErrorTestsc                 C   s  dt dfdt dfdt dfdt dfdt d	fd
t d	fdt d	fdt d	fdt dfg	}|D ]O\}}| j|d= ztd| typ } z#t }tjt   W d    n1 s_w   Y  |}W Y d }~nd }~ww W d    q11 s{w   Y  q1d S )N)bad.pyrE   r}   abcdefgrE   r   z
               File "bad.py", line 1
                 abcdefg
                  ^^^^^
             SyntaxError: bad bad
             )rA  rE   r}   rB  rE   r   z
               File "bad.py", line 1
                 abcdefg
                  ^
             SyntaxError: bad bad
             )rA  rE   r}   rB  rE   )rA  rE   r~   rB  rE   r}   z
               File "bad.py", line 1
                 abcdefg
                    ^
             SyntaxError: bad bad
             )rA  rE   rB  rE   rC  zn
               File "bad.py", line 1
                 abcdefg
             SyntaxError: bad bad
             )rA  rE   rD  rB  rE   )rA  rE   r   rB  rE   r   )rA  rE   r   rB  rE   r   rA  rE   r}   rB  rE   d   z
               File "bad.py", line 1
                 abcdefg
                  ^^^^^^
             SyntaxError: bad bad
             )r   bad bad)r   r.   rI   r   r   rU   r  r   )r   casesr   r   r,   r1   the_exceptionr   r   r   test_range_of_offsets  sx   				O

z&SyntaxErrorTests.test_range_of_offsetsc                 C   s   d}zEt tddd}|| W d    n1 sw   Y  tdddt\}}}|d }| |d	 d
 | |d d W tt d S tt w )NuU   # -*- coding: cp437 -*-
"┬ó┬ó┬ó┬ó┬ó┬ó" + f(4, x for x in range(1))
r5   cp437r7   rv  z-Xutf8r6   u@       "┬ó┬ó┬ó┬ó┬ó┬ó" + f(4, x for x in range(1))rC  z-                          ^^^^^^^^^^^^^^^^^^^)	rV   r   writer   rz  rw   
splitlinesr0   r   )r   rp   Ztestfiler|  r}  r1   r   r   r   test_encodings  s   zSyntaxErrorTests.test_encodingsc           	      C   s   d}t d|}|\}}}}}}| ||j | ||j | ||j | ||j | ||j | ||j | d|j d S )NrF  rH  	rI   r0   r   rq   r   rr   r   ru   rf   )	r   r   rJ  r   rq   rr   errorr   r   r   r   r   test_attributes_new_constructor	  s   
z0SyntaxErrorTests.test_attributes_new_constructorc                 C   s   d}t d|}|\}}}}| ||j | ||j | d |j | ||j | d |j | ||j | d|j d S )N)rA  rE   r}   rB  rH  rR  )r   r   rJ  r   rq   rr   rS  r   r   r   test_attributes_old_constructor	  s   
z0SyntaxErrorTests.test_attributes_old_constructorc                 C   s@   d}|  ttd| d}|  ttd| d}|  ttd| d S )N)rA  rE   r}   rH  )rA  rE   r}   r~   r   r   r   )rA  rE   r}   rB  rE   )rS   rO   rI   r   r   r   r   r   test_incorrect_constructor	  s   z+SyntaxErrorTests.test_incorrect_constructorN)r   r   r   rK  rQ  rT  rU  rW  r   r   r   r   r@    s    Yr@  c                   @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )PEP626Testsc              
   G   s   z|  W n t y } z	|j}W Y d }~n
d }~ww | d g }|j}|r@|j}||jd u r3d n|j|jj  |j}|s'| 	t
|| d S )Nr   )r'   r   r_   tb_nextr   r   f_linenor   co_firstlinenor0   tuple)r   r   r   rY  tlinesframer   r   r   lineno_after_raise*	  s$   

zPEP626Tests.lineno_after_raisec                 C      dd }|  |d d S )Nc                   S      dd  d S r1  r   r   r   r   r   simple=	  s   z:PEP626Tests.test_lineno_after_raise_simple.<locals>.simplerE   r`  )r   rc  r   r   r   test_lineno_after_raise_simple<	  s   z*PEP626Tests.test_lineno_after_raise_simplec                 C   ra  )Nc                   S   s$   zdd  W d S    dd  Y d S r1  r   r   r   r   r   	in_exceptC	  s
   z@PEP626Tests.test_lineno_after_raise_in_except.<locals>.in_exceptr~   rd  )r   rf  r   r   r   !test_lineno_after_raise_in_exceptB	     z-PEP626Tests.test_lineno_after_raise_in_exceptc                 C   ra  )Nc               
   S   s6   zdd  W d S  t y }  zW Y d } ~ d S d } ~ ww r1  )rO   rX  r   r   r   other_exceptL	  s   z@PEP626Tests.test_lineno_after_other_except.<locals>.other_exceptr   rd  )r   ri  r   r   r   test_lineno_after_other_exceptK	     z*PEP626Tests.test_lineno_after_other_exceptc                 C   ra  )Nc               
   S   s>   zdd  W d S  t y }  zdd  W Y d } ~ d S d } ~ ww r1  r&   rX  r   r   r   in_named_exceptT	  s   z@PEP626Tests.test_lineno_in_named_except.<locals>.in_named_exceptr~   rd  )r   rl  r   r   r   test_lineno_in_named_exceptS	  rh  z'PEP626Tests.test_lineno_in_named_exceptc                 C   ra  )Nc                   S   s   zdd  W d S w r1  r   r   r   r   r   in_try]	  s   
z.PEP626Tests.test_lineno_in_try.<locals>.in_tryr~   rd  )r   rn  r   r   r   test_lineno_in_try\	  rk  zPEP626Tests.test_lineno_in_tryc                 C   ra  )Nc                   S   s   zW dd  d S dd  w r1  r   r   r   r   r   in_finally_normale	  s   zDPEP626Tests.test_lineno_in_finally_normal.<locals>.in_finally_normalr~   rd  )r   rp  r   r   r   test_lineno_in_finally_normald	  rh  z)PEP626Tests.test_lineno_in_finally_normalc                 C   ra  )Nc                   S   s"   zdd  W dd  d S dd  w r1  r   r   r   r   r   in_finally_exceptn	  s   
zDPEP626Tests.test_lineno_in_finally_except.<locals>.in_finally_exceptr~   rd  )r   rr  r   r   r   test_lineno_in_finally_exceptm	  rh  z)PEP626Tests.test_lineno_in_finally_exceptc                    s*   G dd d  fdd}|  |d d S )Nc                   @   r  )z0PEP626Tests.test_lineno_after_with.<locals>.Noopc                 S   r  r   r   r(   r   r   r   r  x	  r  z:PEP626Tests.test_lineno_after_with.<locals>.Noop.__enter__c                 W   r  r   r   rV  r   r   r   r  z	  r  z9PEP626Tests.test_lineno_after_with.<locals>.Noop.__exit__Nr  r   r   r   r   Noopw	  r  rt  c                      4      dd  W d    d S 1 sw   Y  d S r1  r   r   rt  r   r   
after_with|	  s   "z6PEP626Tests.test_lineno_after_with.<locals>.after_withr}   rd  r   rw  r   rv  r   test_lineno_after_withv	  s   z"PEP626Tests.test_lineno_after_withc                 C   s4   dd }|  |d |jjdd|_|  |d  d S )Nc                   S   rb  r1  r   r   r   r   r   r   	  rA  z8PEP626Tests.test_missing_lineno_shows_as_none.<locals>.frE   s   )co_linetable)r`  __code__rs   )r   r   r   r   r   !test_missing_lineno_shows_as_none	  s   z-PEP626Tests.test_missing_lineno_shows_as_nonec                    s,   G dd d  fdd}|  |dd d S )Nc                   @   r  )zCPEP626Tests.test_lineno_after_raise_in_with_exit.<locals>.ExitFailsc                 S   r  r   r   r(   r   r   r   r  	  r  zMPEP626Tests.test_lineno_after_raise_in_with_exit.<locals>.ExitFails.__enter__c                 W   r  r   r  rV  r   r   r   r  	  r  zLPEP626Tests.test_lineno_after_raise_in_with_exit.<locals>.ExitFails.__exit__Nr  r   r   r   r   	ExitFails	  r  r}  c                      ru  r1  r   r   r}  r   r   rw  	  s   
"zDPEP626Tests.test_lineno_after_raise_in_with_exit.<locals>.after_withrE   rd  rx  r   r~  r   $test_lineno_after_raise_in_with_exit	  s   z0PEP626Tests.test_lineno_after_raise_in_with_exitN)r   r   r   r`  re  rg  rj  rm  ro  rq  rs  ry  r|  r  r   r   r   r   rX  (	  s    				rX  __main__))r;  gcr  rU   r  r   r  r   textwrapr   Ztest.supportr   r   r   r   r   r   r	   Ztest.support.import_helperr
   Ztest.support.os_helperr   r   Ztest.support.warnings_helperr   r,  r   r'   r   r!   r$   ZTestCaser+   Zglobal_for_suggestionsr  r  r+  r@  rX  r   r  r   r   r   r   <module>   sV   $            %   }L m