o
    b͞                     @   s   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z ddlmZmZ ejjejd dkdd	ZG d
d dejZeG dd dejZdS )zTests for the python3 checkers.    )absolute_importN)	testutils)python3)INFERENCE_FAILURE	INFERENCE   zPython 2 only)reasonc                   @   s  e Zd ZejZdd Ze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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/d0 Zd1d2 Zd3d4 Z d5d6 Z!d7d8 Z"d9d: Z#d;d< Z$d=d> Z%d?d@ Z&dAdB Z'dCdD Z(dEdF Z)dGdH Z*dIdJ Z+dKdL Z,dMdN Z-edOdP Z.edQdR Z/dSdT Z0dUdV Z1dWdX Z2dYdZ Z3d[d\ Z4d]d^ Z5d_d` Z6dadb Z7dcdd Z8dedf Z9dgdh Z:didj Z;dkdl Z<dmdn Z=dodp Z>dqdr Z?dsdt Z@edudv ZAedwdx ZBdydz ZCd{d| ZDd}d~ ZEdd ZFdd ZGdd ZHdd ZIdd ZJedd ZKedd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUedd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd Zddd Zedd Zfdd ZgddĄ ZhddƄ ZiddȄ Zjddʄ Zkdd̄ Zldd΄ ZmddЄ Zndd҄ ZoddԄ Zpddք Zqdd؄ Zrddڄ Zsdd܄ Ztddބ Zudd Zvdd Zwdd ZxdS )TestPython3Checkerc                 C   s`   t |d }| d }| tj||d | j| W d    d S 1 s)w   Y  d S )Nz  #@z-builtinnode)astroidextract_nodelowerassertAddsMessagesr   MessagecheckerZ
visit_name)selfbuiltin_namer   message r   c/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/test/unittest_checker_python3.pycheck_bad_builtin*   s
   "z$TestPython3Checker.check_bad_builtinc                 C   s    g d}|D ]}|  | qd S )N)applybuffercmpcoerceZexecfilefileinputinternlong	raw_inputroundreduceStandardErrorunichrunicodexrangereload)r   )r   builtinsbuiltinr   r   r   test_bad_builtins0   s   z$TestPython3Checker.test_bad_builtinsc                 C   L   d |}t|}|   | | W d    d S 1 sw   Y  d S )Nfor x in {}(): passformatr   parseassertNoMessageswalkr   fxncodemoduler   r   r   as_iterable_in_for_loop_testH   
   


"z/TestPython3Checker.as_iterable_in_for_loop_testc                 C   d   d |}td |}tj||d}| | | j| W d    d S 1 s+w   Y  d S )N{}-builtin-not-iteratingzV
        for x in (whatever(
            {}() #@
        )):
            pass
        r
   r.   r   r   r   r   r   r   
visit_callr   r3   r   r   r   r   r   r   $as_used_by_iterable_in_for_loop_testN      

"z7TestPython3Checker.as_used_by_iterable_in_for_loop_testc                 C   r+   )Nzx = (x for x in {}())r-   r2   r   r   r   as_iterable_in_genexp_test^   r7   z-TestPython3Checker.as_iterable_in_genexp_testc                 C   r+   )Nzx = test(*{}())r-   r2   r   r   r   as_iterable_in_starred_contextd   r7   z1TestPython3Checker.as_iterable_in_starred_contextc                 C   r+   )Nzx = [x for x in {}(None, [1])]r-   r2   r   r   r   as_iterable_in_listcomp_testj   r7   z/TestPython3Checker.as_iterable_in_listcomp_testc                 C   r+   )Nzyield from {}()r-   r2   r   r   r   as_iterable_in_yield_fromp   r7   z,TestPython3Checker.as_iterable_in_yield_fromc                 C   r8   )Nr9   zP
        list(
            __({}(x))
            for x in [1]
        )
        r
   r:   r<   r   r   r   !as_used_in_variant_in_genexp_testv   r>   z4TestPython3Checker.as_used_in_variant_in_genexp_testc                 C   r8   )Nr9   zG
        [
            __({}(None, x))
        for x in [[1]]]
        r
   r:   r<   r   r   r   #as_used_in_variant_in_listcomp_test      
	"z6TestPython3Checker.as_used_in_variant_in_listcomp_testc                 C   sJ   t d||}|   | | W d    d S 1 sw   Y  d S )Nzx = {}({}())r   r/   r.   r0   r1   )r   r3   callable_fnr5   r   r   r   (as_argument_to_callable_constructor_test   s   
"z;TestPython3Checker.as_argument_to_callable_constructor_testc                 C   sH   t d|}|   | | W d    d S 1 sw   Y  d S )Nzlist(filter(None, {}()))rF   )r   rG   r5   r   r   r   "as_argument_to_materialized_filter   s   
"z5TestPython3Checker.as_argument_to_materialized_filterc                 C   r8   )Nr9   z2
        y(
            {}() #@
        )
        r
   r:   r<   r   r   r   as_argument_to_random_fxn_test   rE   z1TestPython3Checker.as_argument_to_random_fxn_testc                 C   r+   )Nzx = ''.join({}())r-   r2   r   r   r   as_argument_to_str_join_test   r7   z/TestPython3Checker.as_argument_to_str_join_testc                 C   sN   dj |d}t|}|   | | W d    d S 1 s w   Y  d S )Na  
        from __future__ import absolute_import
        import itertools
        from itertools import product
        for i,j in product({fxn}(), repeat=2):
            pass
        for i,j in itertools.product({fxn}(), repeat=2):
            pass
        )r3   r-   r2   r   r   r   "as_argument_to_itertools_functions   s   

"z5TestPython3Checker.as_argument_to_itertools_functionsc                 C   sJ   t d|}|   | j| W d    d S 1 sw   Y  d S )Nz!
        a, b = __({}())
        )r   r   r.   r0   r   r;   )r   r3   r   r   r   r   as_iterable_in_unpacking   s   
"z+TestPython3Checker.as_iterable_in_unpackingc                 C   r8   )Nr9   z
        a = __({}())
        r
   r:   r<   r   r   r   as_assignment   s   
"z TestPython3Checker.as_assignmentc                 C   s   |  | | | | | | | | | | | | | | | | | | 	| | 
| | | | | | | dD ]}| || qHdS )z:Helper for verifying a function isn't used as an iterator.)iterlisttuplesortedsetsumanyall	enumeratedictOrderedDictN)r6   r=   r?   rA   rC   rD   rJ   rK   rM   rN   rI   rB   r@   rL   rH   )r   r3   funcr   r   r   iterating_context_tests   s"   













z*TestPython3Checker.iterating_context_testsc                 C   s   t d\}}|   | j|j W d    n1 sw   Y  tjd|jd}| | | j|j W d    d S 1 sBw   Y  d S )Nz
        from __future__ import absolute_import
        from collections import defaultdict
        d = defaultdict(list)
        a, b = d.keys() #@
        x = d.keys() #@
        zdict-keys-not-iteratingr
   )	r   r   r0   r   r;   valuer   r   r   )r   Z	iteratingZnot_iteratingr   r   r   r   1test_dict_subclasses_methods_in_iterating_context   s   

"zDTestPython3Checker.test_dict_subclasses_methods_in_iterating_contextc              
   C   s   g d}ddg}dD ]e}d |}|D ]%}| |}t|}|   | | W d    n1 s3w   Y  q|D ]3}| |}t|}d |}	tj|	|d}
| |
 | j	
| W d    n1 siw   Y  q;q
d S )N)r,   z(x for x in {}())z[x for x in {}()]z
iter({}())za, b = {}()z	max({}())z	min({}())z	3 in {}()zset().update({}())z[].extend({}())z{{}}.update({}())z
            from __future__ import absolute_import
            from itertools import chain
            chain.from_iterable({}())
            zx = __({}())z__({}())[0])keysitemsvaluesz{{}}.{}zdict-{}-not-iteratingr
   )r.   r   r/   r0   r1   r   r   r   r   r   r;   )r   Ziterating_codeZnon_iterating_codemethodZdict_methodr4   Z
with_valuer5   r   r   r   r   r   r   &test_dict_methods_in_iterating_context  s,   






z9TestPython3Checker.test_dict_methods_in_iterating_contextc                 C      |  d d S )Nmapr[   r   r   r   r   test_map_in_iterating_context5     z0TestPython3Checker.test_map_in_iterating_contextc                 C   rc   )Nzipre   rf   r   r   r   test_zip_in_iterating_context8  rh   z0TestPython3Checker.test_zip_in_iterating_contextc                 C   rc   )Nrangere   rf   r   r   r   test_range_in_iterating_context;  rh   z2TestPython3Checker.test_range_in_iterating_contextc                 C   rc   )Nfilterre   rf   r   r   r    test_filter_in_iterating_context>  rh   z3TestPython3Checker.test_filter_in_iterating_contextc                 C   sZ   t d|}tj||d}| | | j| W d   dS 1 s&w   Y  dS ):Helper for verifying that a certain method is not defined.ze
            class Foo(object):
                def __{}__(self, other):  #@
                    passr
   N)r   r   r.   r   r   r   r   visit_functiondef)r   ra   warningr   r   r   r   r   defined_method_testA  s   "z&TestPython3Checker.defined_method_testc                 C      |  dd d S )NZdelslicezdelslice-methodrr   rf   r   r   r   test_delslice_methodO     z'TestPython3Checker.test_delslice_methodc                 C   rs   )NZgetslicezgetslice-methodrt   rf   r   r   r   test_getslice_methodR  rv   z'TestPython3Checker.test_getslice_methodc                 C   rs   )NZsetslicezsetslice-methodrt   rf   r   r   r   test_setslice_methodU  rv   z'TestPython3Checker.test_setslice_methodc                 C   rs   )Nr   zcoerce-methodrt   rf   r   r   r   test_coerce_methodX  rv   z%TestPython3Checker.test_coerce_methodc                 C   rs   )Noctz
oct-methodrt   rf   r   r   r   test_oct_method[  rv   z"TestPython3Checker.test_oct_methodc                 C   rs   )Nhexz
hex-methodrt   rf   r   r   r   test_hex_method^  rv   z"TestPython3Checker.test_hex_methodc                 C   rs   )NZnonzeroznonzero-methodrt   rf   r   r   r   test_nonzero_methoda  rv   z&TestPython3Checker.test_nonzero_methodc                 C   rs   )Nr   z
cmp-methodrt   rf   r   r   r   test_cmp_methodd  rv   z"TestPython3Checker.test_cmp_methodc                 C   rs   )Ndivz
div-methodrt   rf   r   r   r   test_div_methodg  rv   z"TestPython3Checker.test_div_methodc                 C   rs   )NZidivzidiv-methodrt   rf   r   r   r   test_idiv_methodj  rv   z#TestPython3Checker.test_idiv_methodc                 C   rs   )NZrdivzrdiv-methodrt   rf   r   r   r   test_rdiv_methodm  rv   z#TestPython3Checker.test_rdiv_methodc                 C   D   t d}|   | j| W d   dS 1 sw   Y  dS )ro   z
            class Foo(object):  #@
                def __eq__(self, other):
                    pass
                def __hash__(self):
                    passNr   r   r0   r   visit_classdefr   r   r   r   r   test_eq_and_hash_methodp  s   
"z*TestPython3Checker.test_eq_and_hash_methodc                 C   r   )ro   z
            class Foo(object):  #@
                def __eq__(self, other):
                    pass
                __hash__ = NoneNr   r   r   r   r   test_eq_and_hash_is_none}  s   
"z+TestPython3Checker.test_eq_and_hash_is_nonec                 C   sT   t d}tjd|d}| | | j| W d   dS 1 s#w   Y  dS )ro   ze
            class Foo(object):  #@
                def __eq__(self, other):
                    passzeq-without-hashr
   Nr   r   r   r   r   r   r   r   r   r   r   r   r   test_eq_without_hash_method  s   "z.TestPython3Checker.test_eq_without_hash_methodc                 C   T   t d}tjd|d}| | | j| W d    d S 1 s#w   Y  d S )Nzprint "Hello, World!" #@zprint-statementr
   )r   r   r   r   r   r   Zvisit_printr   r   r   r   test_print_statement  
   
"z'TestPython3Checker.test_print_statementc                 C   r   )Nz`test`backtickr
   )r   r   r   r   r   r   Z
visit_reprr   r   r   r   test_backtick  r   z TestPython3Checker.test_backtickc                 C      t d}tjd|d}| | | j| W d    n1 s"w   Y  |   | j| W d    d S 1 s=w   Y  d S )Nzimport string  #@no-absolute-importr
   )r   r   r   r   r   r   visit_importr0   r   r   r   r   test_relative_import     

"z'TestPython3Checker.test_relative_importc                 C   r   )Nzfrom os import path  #@r   r
   )r   r   r   r   r   r   visit_importfromr0   r   r   r   r   test_relative_from_import  r   z,TestPython3Checker.test_relative_from_importc                 C   sZ   t d}t d}|   ||fD ]}| | qW d    d S 1 s&w   Y  d S )Nz1from __future__ import absolute_import; import osz;from __future__ import absolute_import; from os import pathr   r/   r0   r1   )r   Zmodule_importZmodule_fromr5   r   r   r   test_absolute_import  s   
"z'TestPython3Checker.test_absolute_importc                 C   d   t d}tjd|d}tjd|d}| || | j| W d    d S 1 s+w   Y  d S )Nz?
        def test():
            from lala import * #@
        r   r
   zimport-star-module-levelr   r   r   r   r   r   r   )r   r   absolutestarr   r   r   test_import_star_module_level  s   "z0TestPython3Checker.test_import_star_module_levelc                 C   r   )Nz	3 / 2  #@zold-divisionr
   )r   r   r   r   r   r   visit_binopr   r   r   r   test_division  
   
"z TestPython3Checker.test_divisionc                 C   B   t d}|   | | W d    d S 1 sw   Y  d S )Nz&from __future__ import division; 3 / 2r   r   r5   r   r   r   #test_division_with_future_statement     

"z6TestPython3Checker.test_division_with_future_statementc                 C   D   t d}|   | j| W d    d S 1 sw   Y  d S )Nz 3 // 2  #@r   r   r0   r   r   r   r   r   r   test_floor_division     

"z&TestPython3Checker.test_floor_divisionc                 C   s\   t d}t d}|   ||fD ]}| j| qW d    d S 1 s'w   Y  d S )Nz
3.0 / 2 #@z 3 / 2.0  #@r   )r   Z	left_nodeZ
right_noder   r   r   r   test_division_by_float  s   


"z)TestPython3Checker.test_division_by_floatc              	   C   `   dD ]+}t d| }tjd|d}| | | j| W d    n1 s(w   Y  qd S )Nr^   r`   r_   zx.iter%s()  #@dict-iter-methodr
   r   r   r   r   r   r   r;   r   methr   r   r   r   r   test_dict_iter_method     z(TestPython3Checker.test_dict_iter_methodc              	   C   \   t d}|D ]$}tjd|d}| | | j| W d    n1 s&w   Y  qd S )NaN  
        from collections import defaultdict
        {}.iterkeys() #@
        defaultdict(list).iterkeys() #@
        class Someclass(dict):
            pass
        Someclass().iterkeys() #@

        # Emits even though we are not sure they are dicts
        x.iterkeys() #@

        def func(x):
            x.iterkeys() #@
        r   r
   r   r   nodesr   r   r   r   r   test_dict_iter_method_on_dict     z0TestPython3Checker.test_dict_iter_method_on_dictc                 C   h   t d}t d}t d}|   |||fD ]}| j| qW d    d S 1 s-w   Y  d S )Nzx.iterkeys(x)  #@zx.iterkeys(*x)  #@zx.iterkeys(y=x)  #@r   r   r0   r   r;   r   Zarg_nodeZstararg_nodeZ
kwarg_noder   r   r   r   test_dict_not_iter_method      



"z,TestPython3Checker.test_dict_not_iter_methodc              	   C   r   )Nr   zx.view%s()  #@dict-view-methodr
   r   r   r   r   r   test_dict_view_method  r   z(TestPython3Checker.test_dict_view_methodc              	   C   r   )NaG  
        from collections import defaultdict
        {}.viewkeys() #@
        defaultdict(list).viewkeys() #@
        class Someclass(dict):
            pass
        Someclass().viewkeys() #@

        # Emits even though they might not be dicts
        x.viewkeys() #@

        def func(x):
            x.viewkeys() #@
        r   r
   r   r   r   r   r   test_dict_viewkeys  r   z%TestPython3Checker.test_dict_viewkeysc                 C   r   )Nzx.next()  #@znext-method-calledr
   r   r   r   r   r   test_next_method%  r   z#TestPython3Checker.test_next_methodc                 C   r   )Nzx.next(x)  #@zx.next(*x)  #@zx.next(y=x)  #@r   r   r   r   r   test_not_next_method+  r   z'TestPython3Checker.test_not_next_methodc                 C   r   )NzH
            class Foo(object):  #@
                __metaclass__ = typezmetaclass-assignmentr
   r   r   r   r   r   test_metaclass_assignment3     "z,TestPython3Checker.test_metaclass_assignmentc                 C   r   )Nz__metaclass__ = typer   r   r   r   r    test_metaclass_global_assignment=  r   z3TestPython3Checker.test_metaclass_global_assignmentc                 C   s^   t d}|jjd }| tjd|d | j|j W d    d S 1 s(w   Y  d S )Nzdef func((a, b)):#@
 passr   zparameter-unpackingr
   )r   r   argsr   r   r   r   visit_arguments)r   r   argr   r   r   test_parameter_unpackingB  s   
"z+TestPython3Checker.test_parameter_unpackingc                 C   r   )Nzraise Exception, "test"zold-raise-syntaxr
   r   r   r   r   r   r   Zvisit_raiser   r   r   r   test_old_raise_syntaxK  r   z(TestPython3Checker.test_old_raise_syntaxc                 C   r   )Nz!
        f.xreadlines #@
        zxreadlines-attributer
   r   r   r   r   r   r   visit_attributer   r   r   r   test_xreadlines_attributeR  r   z,TestPython3Checker.test_xreadlines_attributec                 C   r   )Nzr
        try:
            raise Exception("test")
        except Exception as e:
            e.message #@
        zexception-message-attributer
   r   r   r   r   r    test_exception_message_attribute\     "z3TestPython3Checker.test_exception_message_attributec                 C   r   )Nz
        e.message #@
        r   r   r0   r   r   r   r   r   r   test_normal_message_attributei     
"z0TestPython3Checker.test_normal_message_attributec                 C   r   )Nzfoobar.encode("hex") #@invalid-str-codecr
   r   r   r   r   r   test_invalid_codecr  r   z%TestPython3Checker.test_invalid_codecc                 C   r   )Nz$foobar.encode("ascii", "ignore")  #@r   r   r   r   r   test_valid_codecx  r   z#TestPython3Checker.test_valid_codecc                 C   r   )Nzfoobar.raz(encoding="hex")  #@r   r   r   r   r   test_visit_call_with_kwarg}  r   z-TestPython3Checker.test_visit_call_with_kwargc                 C   r   )Nzopen(foobar, encoding="hex") #@r   r
   r   r   r   r   r   test_invalid_open_codec  r   z*TestPython3Checker.test_invalid_open_codecc                 C   r   )Nz"open(foobar, encoding="palmos") #@r   r   r   r   r   test_valid_open_codec  r   z(TestPython3Checker.test_valid_open_codecc                 C   r   )Nzraise "Test"zraising-stringr
   r   r   r   r   r   test_raising_string  r   z&TestPython3Checker.test_raising_stringc                 C   sH   t td}|   | | W d    d S 1 sw   Y  d S )Nz]
        abc = 1l
        raise Exception, "test"
        raise "test"
        `abc`
        )r   r/   textwrapdedentr0   r1   r   r   r   r    test_checker_disabled_by_default  s   

"z3TestPython3Checker.test_checker_disabled_by_defaultc              	   C   r   )Nz
        [].sort(cmp=lambda x: x) #@
        a = list(range(x))
        a.sort(cmp=lambda x: x) #@

        sorted([], cmp=lambda x: x) #@
        zusing-cmp-argumentr
   r   r   r   r   r   test_using_cmp_argument  s   	z*TestPython3Checker.test_using_cmp_argumentc                 C   r   )Nz2
        import sys
        sys.maxint #@
        sys-max-intr
   r   r   r   r   r   test_sys_maxint     "z"TestPython3Checker.test_sys_maxintc                 C   r   )Nz/
        from itertools import izip #@
        r   r
   zdeprecated-itertools-functionr   r   r   absolute_import_messager   r   r   r   test_itertools_izip     "z&TestPython3Checker.test_itertools_izipc                 C   r   )Nz1
        from types import StringType #@
        r   r
   zdeprecated-types-fieldr   r   r   r   r   test_deprecated_types_fields  r   z/TestPython3Checker.test_deprecated_types_fieldsc                 C   r   )Nz+
        from sys import maxint #@
        r   r
   r   r   r   r   r   r   test_sys_maxint_imort_from  r   z-TestPython3Checker.test_sys_maxint_imort_fromc                 C   r   )Nz6
        sys = object()
        sys.maxint #@
        r   r   r   r   r   test_object_maxint     
"z%TestPython3Checker.test_object_maxintc                 C   r   )Nz(
        import urllib2, sys #@
        r   r
   bad-python3-importr   r   r   r   r   r   r   r   r   r   r   test_bad_import  r   z"TestPython3Checker.test_bad_importc                 C   r   )Nz:
        import turtle #@
        turtle.Turtle()
        r   r
   r   r   r   r   r   r   r   test_bad_import_turtle  r   z)TestPython3Checker.test_bad_import_turtlec                 C   r   )NzL
        from dbm import open as open_ #@
        open_("dummy.db")
        r   r
   r   r   r   r   r   test_bad_import_dbm  r   z&TestPython3Checker.test_bad_import_dbmc              	   C   sl   ddg}|D ]-}t |}tjd|d}| | | j| W d    n1 s*w   Y  d| j_qd S )Nzfrom .commands import titizfrom . import commandsr   r
   F)r   r   r   r   r   r   r   Z_future_absolute_import)r   Zsamplesr4   r   r   r   r   r   test_bad_import_not_on_relative	  s   

z2TestPython3Checker.test_bad_import_not_on_relativec                 C   r   )NzN
        import six
        if six.PY2:
            import urllib2 #@
        r   r
   r   r   r   r   r   test_bad_import_conditional     "z.TestPython3Checker.test_bad_import_conditionalc                 C   r   )Nzd
        try:
            from hashlib import sha
        except:
            import sha #@
        r   r
   r   r   r   r   r   "test_bad_import_try_except_handler  r   z5TestPython3Checker.test_bad_import_try_except_handlerc                 C   r   )Nz
        try:
            import md5  #@
        except:
            from hashlib import md5
        finally:
            pass
        r   r
   r   r   r   r   r   test_bad_import_try,  s   
"z&TestPython3Checker.test_bad_import_tryc                 C   r   )Nz]
        try:
            import Queue  #@
        finally:
            import queue
        r   r
   r   r   r   r   r   r   test_bad_import_try_finally;  s   "z.TestPython3Checker.test_bad_import_try_finallyc                 C   r   )Nz3
        from cStringIO import StringIO #@
        r   r
   r   r   r   r   r   r   test_bad_import_fromI  r   z'TestPython3Checker.test_bad_import_fromc                 C   r   )Nz;
        import string
        string.maketrans #@
        deprecated-string-functionr
   r   r   r   r   r   test_bad_string_attributeT  r   z,TestPython3Checker.test_bad_string_attributec                 C   r   )Nz9
        import operator
        operator.div #@
        zdeprecated-operator-functionr
   r   r   r   r   r   test_bad_operator_attribute_  r   z.TestPython3Checker.test_bad_operator_attributec                 C   s   t d\}}t d}tjd|d}| | | j|j W d    n1 s*w   Y  | 	  | 
| W d    d S 1 sDw   Y  d S )Nz<
        a = [i for i in range(10)] #@
        i #@
        z
        {c for c in range(10)} #@
        {j:j for j in range(10)} #@
        [image_child] = [x for x in range(10)]
        thumbnail = func(__(image_child))
        zcomprehension-escaper
   )r   r   r/   r   r   r   r   Zvisit_listcompr\   r0   r1   )r   ZassignZescaped_nodeZgood_moduler   r   r   r   test_comprehension_escapej  s   
"z,TestPython3Checker.test_comprehension_escapec                 C   r   )NzP
        [i for i in range(3)]
        for i in range(3):
            i
        )r   r   r0   r1   r   r   r   r   *test_comprehension_escape_newly_introduced  s   
"z=TestPython3Checker.test_comprehension_escape_newly_introducedc                 C   s   t d}tjd|jd jd}| | | j|jd j	d  W d    n1 s,w   Y  | 
 ! | j|jd j	d  | j|jd j	d  W d    d S 1 sYw   Y  d S )Na#  
        try: 1/0
        except ValueError as exc:
            pass
        exc #@
        try:
           2/0
        except (ValueError, TypeError) as exc:
           exc = 2
        exc #@
        try:
           2/0
        except (ValueError, TypeError): #@
           exc = 2
        zexception-escape   r
   r   r      )r   r/   r   r   bodyr\   r   r   Zvisit_excepthandlerhandlersr0   )r   r5   r   r   r   r   test_exception_escape  s   
"z(TestPython3Checker.test_exception_escapec                 C   r   )Nz5
        import sys
        sys.exc_clear #@
        zdeprecated-sys-functionr
   r   r   r   r   r   test_bad_sys_attribute  r   z)TestPython3Checker.test_bad_sys_attributec              	   C   r   )Nz
        import urllib
        urllib.addbase #@
        urllib.splithost #@
        urllib.urlretrieve #@
        urllib.urlopen #@
        urllib.urlencode #@
        zdeprecated-urllib-functionr
   r   r   r   r   r   test_bad_urllib_attribute  s   
z,TestPython3Checker.test_bad_urllib_attributec                 C   r   )Nz?
        import string
        string.ascii_letters #@
        r   r   r   r   r   test_ok_string_attribute  r   z+TestPython3Checker.test_ok_string_attributec                 C   r   )NzF
        import string
        string.upper("hello world") #@
        r   r
   r   r   r   r   r   test_bad_string_call  r   z'TestPython3Checker.test_bad_string_callc                 C   r   )Nz`
        import six.moves.configparser
        six.moves.configparser.ConfigParser() #@
        r   r   r   r   r   test_ok_shadowed_call  r   z(TestPython3Checker.test_ok_shadowed_callc                 C   r   )Nz=
        import string
        string.Foramtter() #@
        r   r   r   r   r   test_ok_string_call  r   z&TestPython3Checker.test_ok_string_callc                 C   r   )Nz.
         from string import atoi #@
         r   r
   r   r   r   r   r   r   test_bad_string_import_from  r   z.TestPython3Checker.test_bad_string_import_fromc                 C   r   )Nz0
         from string import digits #@
         r   r
   r   r   r   r   r   test_ok_string_import_from  r   z-TestPython3Checker.test_ok_string_import_fromc                 C   V   t d}tjd|td}| | | j| W d    d S 1 s$w   Y  d S )Nz7
         foobar.translate(None, 'abc123') #@
         deprecated-str-translate-callr   
confidencer   r   r   r   r   r   r   r;   r   r   r   r   *test_bad_str_translate_call_string_literal  s   "z=TestPython3Checker.test_bad_str_translate_call_string_literalc                 C   r	  )NzR
         def raz(foobar):
           foobar.translate(None, 'hello') #@
         r
  r  r  r   r   r   r   $test_bad_str_translate_call_variable	     "z7TestPython3Checker.test_bad_str_translate_call_variablec                 C   r	  )NzU
         foobar = "hello world"
         foobar.translate(None, foobar) #@
         r
  r  )r   r   r   r   r   r   r   r;   r   r   r   r   %test_bad_str_translate_call_infer_str  r  z8TestPython3Checker.test_bad_str_translate_call_infer_strc                 C   r   )Nz1
         foobar.translate(None, 33) #@
         r   r   r   r   r   "test_ok_str_translate_call_integer#  r   z5TestPython3Checker.test_ok_str_translate_call_integerc                 C   r   )Nz?
         foobar.translate(None, 'foobar', raz=33) #@
         r   r   r   r   r   "test_ok_str_translate_call_keyword,  r   z5TestPython3Checker.test_ok_str_translate_call_keywordc                 C   r   )NzL
         foobar = {}
         foobar.translate(None, 'foobar') #@
         r   r   r   r   r   "test_ok_str_translate_call_not_str5  r   z5TestPython3Checker.test_ok_str_translate_call_not_strc                 C   s^   d}t |}|jj}tjd|d}| | | | W d    d S 1 s(w   Y  d S )Nz
        from __future__ import absolute_import
        import sys
        x = {}
        if sys.maxsize:
            x.iterkeys()  #@
        r   r
   )r   r   parentr   r   r   r1   )r   r4   r   r5   r   r   r   r   test_non_py2_conditional?  s   
"z+TestPython3Checker.test_non_py2_conditionalc                 C   F   d}t |}|   | | W d    d S 1 sw   Y  d S )Nz
        from __future__ import absolute_import
        import six
        x = {}
        if six.PY2:
            x.iterkeys()
        r   r   r4   r5   r   r   r   test_six_conditionalM  
   

"z'TestPython3Checker.test_six_conditionalc                 C   r  )Nz
        from __future__ import absolute_import
        import sys
        x = {}
        if sys.version_info[0] == 2:
            x.iterkeys()
        r   r  r   r   r   test_versioninfo_conditionalY  r  z/TestPython3Checker.test_versioninfo_conditionalc                 C   r  )Nz
        from __future__ import absolute_import
        import sys
        x = {}
        if sys.version_info == (2, 7):
            x.iterkeys()
        r   r  r   r   r   "test_versioninfo_tuple_conditionale  r  z5TestPython3Checker.test_versioninfo_tuple_conditionalc                 C   r  )Nz
        from __future__ import absolute_import
        import six
        import string
        string.translate if six.PY2 else None
        r   r  r   r   r   test_six_ifexp_conditionalq  s
   

"z-TestPython3Checker.test_six_ifexp_conditionalc                 C   r   )Nz\
            class Foo(object):
                def next(self):  #@
                    passnext-method-definedr
   r   r   r   r   r   r   rp   r   r   r   r   test_next_defined|  r   z$TestPython3Checker.test_next_definedc                 C   r   )Nzf
            class Foo(object):
                def next(self, foo=None):  #@
                    passr   r   r0   r   rp   r   r   r   r   test_next_defined_too_many_args  r   z2TestPython3Checker.test_next_defined_too_many_argsc                 C   r   )Nzz
            class Foo(object):
                @staticmethod
                def next(self):  #@
                    passr!  r   r   r   r   -test_next_defined_static_method_too_many_args  s   
"z@TestPython3Checker.test_next_defined_static_method_too_many_argsc                 C   r   )Nzv
            class Foo(object):
                @staticmethod
                def next():  #@
                    passr  r
   r  r   r   r   r   test_next_defined_static_method  r   z2TestPython3Checker.test_next_defined_static_methodc                 C   r   )Nzx
            class Foo(object):
                @classmethod
                def next(cls):  #@
                    passr  r
   r  r   r   r   r   test_next_defined_class_method  r   z1TestPython3Checker.test_next_defined_class_methodN)y__name__
__module____qualname__r   ZPython3CheckerCHECKER_CLASSr   python2_onlyr*   r6   r=   r?   r@   rA   rB   rC   rD   rH   rI   rJ   rK   rL   rM   rN   r[   r]   rb   rg   rj   rl   rn   rr   ru   rw   rx   ry   r{   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r"  r#  r$  r%  r   r   r   r   r	   &   s    
 '

		



	



	



		

r	   c                   @   s:   e Zd ZejZdd Zdd Zdd Zdd Z	d	d
 Z
dS )TestPython3TokenCheckerc                 C   sT   t |}t j|dd}| | | j| W d    d S 1 s#w   Y  d S )Nr   )line)r   _tokenize_strr   r   r   process_tokens)r   r4   Zsymbolic_messagetokensr   r   r   r   _test_token_message  r   z+TestPython3TokenChecker._test_token_messagec                 C   s   dD ]}|  |d qd S )N)Z1lZ1Lzlong-suffixr0  )r   r4   r   r   r   test_long_suffix  s   z(TestPython3TokenChecker.test_long_suffixc                 C   rs   )Nz1 <> 2zold-ne-operatorr1  rf   r   r   r   test_old_ne_operator  rv   z,TestPython3TokenChecker.test_old_ne_operatorc              	   C   sb   dD ]}|  |d qdD ]!}t|}|   | j| W d    n1 s)w   Y  qd S )N)Z045Z055Z075Z077Z076543zold-octal-literal)Z45Z00Z085Z081r0  r   r-  r0   r   r.  )r   ZoctalZ	non_octalr/  r   r   r   test_old_octal_literal  s   

z.TestPython3TokenChecker.test_old_octal_literalc              	   C   s\   d}|  |d dD ]!}t|}|   | j| W d    n1 s&w   Y  q
d S )Nu	   b"测试"znon-ascii-bytes-literal)   测试r7  Zabcdef   r5  )r   r4   r/  r   r   r   test_non_ascii_bytes_literal  s   

z4TestPython3TokenChecker.test_non_ascii_bytes_literalN)r&  r'  r(  r   ZPython3TokenCheckerr)  r0  r2  r3  r6  r9  r   r   r   r   r+    s    
r+  )__doc__
__future__r   sysr   Zpytestr   Zpylintr   Zpylint.checkersr   r   Zpylint.interfacesr   r   markZskipifversion_infor*  ZCheckerTestCaser	   r+  r   r   r   r   <module>   s,            