ó
'![c           @   s¢   d  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
 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d S(   s%   Unit tests for the variables checker.iÿÿÿÿN(   t	   variables(   t   CheckerTestCaset   lintert
   set_configt   Messaget   TestVariablesCheckerc           B   sŒ   e  Z e j Z d  „  Z e d d ƒ d „  ƒ Z d „  Z d „  Z	 e d d ƒ d „  ƒ Z
 e d d ƒ d	 „  ƒ Z e d d ƒ d
 „  ƒ Z RS(   c         C   s3   t  j d ƒ } |  j ƒ   |  j | ƒ Wd QXd S(   s4    Issue 78 report a false positive for unused-module sˆ   
        from sys import path
        path += ['stuff']
        def func():
            other = 1
            return len(other)
        N(   t   astroidt   parset   assertNoMessagest   walk(   t   selft   module(    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   test_bitbucket_issue_78   s    	t   ignored_modulest   argparsec         C   s6   t  j d ƒ } |  j ƒ   |  j j | ƒ Wd QXd S(   s‘   Make sure that 'from ... import ...' does not emit a
        'no-name-in-module' with a module that is configured
        to be ignored.
        s:   
        from argparse import THIS_does_not_EXIST
        N(   R   t   extract_nodeR   t   checkert   visit_importfrom(   R
   t   node(    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   test_no_name_in_module_skipped&   s    	c         C   sn   t  j d ƒ } | j j j t  j d ƒ ƒ | j ƒ  } |  j ƒ  % |  j j	 | ƒ |  j j
 | ƒ Wd  QXd  S(   Ns   __all__ = []t   test(   R   R   t   valuet   eltst   appendt   Constt   rootR   R   t   visit_modulet   leave_module(   R
   R   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt    test_all_elements_without_parent3   s    c         C   s6   t  j d ƒ } |  j ƒ   |  j j | ƒ Wd  QXd  S(   Ns2   
        from future.builtins import open
        (   R   R   R   R   R   (   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   test_redefined_builtin_ignored;   s    	t   redefining_builtins_modulest   osc         C   s6   t  j d ƒ } |  j ƒ   |  j j | ƒ Wd  QXd  S(   Ns%   
        from os import open
        (   R   R   R   R   R   (   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt%   test_redefined_builtin_custom_modulesB   s    	c         C   sR   t  j d ƒ } |  j t d d | j d d d ƒƒ  |  j j | ƒ Wd  QXd  S(   Ns2   
        from future.builtins import open
        s   redefined-builtinR   i    t   argst   open(   R   R   t   assertAddsMessagesR   t   bodyR   R   (   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt*   test_redefined_builtin_modname_not_ignoredJ   s
    	#c         C   sL   t  j d ƒ } |  j ƒ  + |  j j | j ƒ  ƒ |  j j | ƒ Wd  QXd  S(   Ns=   
        def test():
            from os import open
        (   R   R   R   R   R   R   t   visit_functiondef(   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt"   test_redefined_builtin_in_functionS   s
    	(   R   (   R   (   R   (   R   (   t   __name__t
   __module__R    t   VariablesCheckert   CHECKER_CLASSR   R   R   R   R   R    R%   R'   (    (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyR      s   					t    TestVariablesCheckerWithTearDownc           B   s†   e  Z e j Z d  „  Z d „  Z e d d ƒ d „  ƒ Z e d d ƒ d „  ƒ Z	 e d d ƒ d	 „  ƒ Z
 d
 „  Z d „  Z d „  Z RS(   c         C   s2   t  t |  ƒ j ƒ  |  j j |  _ g  |  j _ d  S(   N(   t   superR,   t   setup_methodR   t   _to_consumet   _to_consume_backup(   R
   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyR.   b   s    c         C   s   |  j  |  j _ d  S(   N(   R0   R   R/   (   R
   t   method(    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   teardown_methodg   s    t	   callbackst	   callback_t	   _callbackc      
   C   s>  t  j d ƒ } |  j ƒ  % |  j j | ƒ |  j j | ƒ Wd QXt  j d ƒ } |  j ƒ  % |  j j | ƒ |  j j | ƒ Wd QXt  j d ƒ } |  j t d d | d d d ƒƒ % |  j j | ƒ |  j j | ƒ Wd QXt  j d	 ƒ } |  j t d d | d d d ƒƒ % |  j j | ƒ |  j j | ƒ Wd QXd S(
   s#    Test the --calbacks option works. s^   
        def callback_one(abc):
             ''' should not emit unused-argument. '''
        Nsd   
        def two_callback(abc, defg):
             ''' should not emit unused-argument. '''
        sY   
        def normal_func(abc):
             ''' should emit unused-argument. '''
        s   unused-argumentR   t   abcR!   s[   
        def cb_func(abc):
             ''' Previous callbacks are overridden. '''
        (   R   R   R   R   R&   t   leave_functiondefR#   R   (   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   test_custom_callback_stringj   s,    			 	 R   R   c         C   sR   t  j d ƒ } |  j t d d | j d d d ƒƒ  |  j j | ƒ Wd  QXd  S(   Ns2   
        from future.builtins import open
        s   redefined-builtinR   i    R!   R"   (   R   R   R#   R   R$   R   R   (   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyR%      s
    	#c         C   sL   t  j d ƒ } |  j ƒ  + |  j j | j ƒ  ƒ |  j j | ƒ Wd  QXd  S(   Ns=   
        def test():
            from os import open
        (   R   R   R   R   R   R   R&   (   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyR'   ˜   s
    	c         C   s3   t  j d ƒ } |  j ƒ   |  j | ƒ Wd  QXd  S(   Ns"   
        import math as _
        (   R   R   R   R	   (   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   test_import_as_underscore¢   s    	c         C   s3   t  j d ƒ } |  j ƒ   |  j | ƒ Wd  QXd  S(   Ns…   
        class MyObject(object):
            method1 = lambda func: func()
            method2 = lambda function: function()
        (   R   R   R   R	   (   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   test_lambda_in_classdef©   s    	c         C   sq   t  j d ƒ } t  j d ƒ } |  j ƒ   |  j | ƒ Wd  QXt  j d ƒ } |  j ƒ   |  j | ƒ Wd  QXd  S(   NsG   
        def foof(x=[i for i in [1, 2]]):
            return x
        sL   
        def foof(x=[(i, 1) for i in [1, 2]]):
            return x
        sC   
        def foof(x=lambda zoo: zoo):
            return x
        (   R   R   R   R	   (   R
   R   (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   test_scope_in_defaults·   s    			(   R4   R5   (   R   (   R   (   R(   R)   R    R*   R+   R.   R2   R   R8   R%   R'   R9   R:   R;   (    (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyR,   ^   s   			%	
		t   TestMissingSubmodulec           B   s   e  Z e j Z d  „  Z RS(   c         C   sŸ   t  j j t  j j t  j j t ƒ ƒ d ƒ } t j j d | ƒ zG t j	 t  j j | d ƒ ƒ t j
 j ƒ  j ƒ  } | d k s† t ‚ Wd  t j j d ƒ Xd  S(   Nt   regrtest_datai    t   package_alls3   E:  3: Undefined variable name 'missing' in __all__(   R   t   patht   joint   dirnamet   abspatht   __file__t   syst   insertR   t   checkt   reportert   finalizet   stript   AssertionErrort   pop(   R
   t	   regr_datat   got(    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   test_package_allÐ   s    $	(   R(   R)   R    R*   R+   RN   (    (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyR<   Í   s   	(   t   __doc__RD   R   R   t   pylint.checkersR    t   pylint.testutilsR   R   R   R   R   R,   R<   (    (    (    sE   lib/python2.7/site-packages/pylint/test/unittest_checker_variables.pyt   <module>   s   "Ho