ó
î%![c           @   s»   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d e  j f d	 „  ƒ  YZ	 d
 e  j f d „  ƒ  YZ
 e d k r· e  j ƒ  n  d S(   iÿÿÿÿN(   t   bases(   t   builder(   t
   exceptions(   t   nodes(   t   objects(   t
   test_utilst   ObjectsTestc           B   s   e  Z d  „  Z RS(   c         C   só   t  j d ƒ } t | j ƒ  ƒ } |  j | t j ƒ |  j | j ƒ  d t	 j
 ƒ | j ƒ  } |  j t | ƒ d ƒ |  j | d t j ƒ |  j g  | D] } | j ^ q— d d g ƒ | j } |  j | j ƒ  d t	 j
 ƒ |  j | t j ƒ d  S(   Ns,   
        frozenset({1: 2, 2: 3}) #@
        s   %s.frozenseti   i    i   (   R   t   extract_nodet   nextt   infert   assertIsInstanceR   t	   FrozenSett   assertEqualt   pytypeR    t   BUILTINSt   iteredt   lenR   t   Constt   valuet   _proxiedt   qnamet   ClassDef(   t   selft   nodet   inferredR   t   constt   proxied(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_frozenset   s    	,	(   t   __name__t
   __module__R   (    (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyR      s   t
   SuperTestsc           B   s×   e  Z d  „  Z d „  Z d „  Z e j d d ƒ d „  ƒ Z e j d d ƒ d „  ƒ Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sè   t  j d ƒ } t | d j j ƒ  ƒ } |  j | t j ƒ |  j | j	 ƒ  d t j
 ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j	 ƒ  d t j
 ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j	 ƒ  d t j
 ƒ d  S(   Ns­  
        class Module(object):
            pass
        class StaticMethod(object):
            @staticmethod
            def static():
                # valid, but we don't bother with it.
                return super(StaticMethod, StaticMethod) #@
        # super outside methods aren't inferred
        super(Module, Module) #@
        # no argument super is not recognised outside methods as well.
        super() #@
        i    s   %s.superi   i   (   R   R   R   R   R	   R
   R    t   InstanceR   R   R   (   R   t	   ast_nodest	   in_statict   module_levelt   no_arguments(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt$   test_inferring_super_outside_methods(   s    	c         C   sU   t  j d ƒ } t | j ƒ  ƒ } |  j | t j ƒ |  j | j ƒ  d t j	 ƒ d  S(   Nsd   
        class Test(object):
            def __init__(self):
                super(Test) #@
        s   %s.super(
   R   R   R   R	   R
   R    R   R   R   R   (   R   R   t	   unbounded(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt(   test_inferring_unbound_super_doesnt_workB   s
    	c         C   sŸ   t  j d ƒ } t | d j ƒ  ƒ } |  j | t j ƒ |  j | j ƒ  d t j	 ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j ƒ  d t j	 ƒ d  S(   Ns   
        class Test(object):
            def __init__(self):
                super(Lala, self) #@
                super(Test, lala) #@
        i    s   %s.superi   (
   R   R   R   R	   R
   R    R   R   R   R   (   R   R    t   firstt   second(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt0   test_use_default_inference_on_not_inferring_argsL   s    	t   maxvers   3.0c         C   s¢   t  j d ƒ } t | j ƒ  ƒ } |  j | t j ƒ |  j | j t j	 ƒ |  j
 | j j d ƒ |  j t j ƒ  } | j ƒ  Wd  QX|  j
 t | j ƒ d ƒ d  S(   Nsj   
        class OldStyle:
            def __init__(self):
                super(OldStyle, self) #@
        t   OldStyles*   Unable to call super on old-style classes.(   R   R   R   R	   R
   R   t   Supert   mro_pointerR   R   R   t   namet   assertRaisesR   t
   SuperErrort	   super_mrot   strt	   exception(   R   R   t   oldt   cm(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_on_old_style_class[   s    	t   minverc         C   s  t  j d ƒ } t | d j ƒ  ƒ } |  j | t j ƒ |  j | j t j	 ƒ |  j
 | j j d ƒ |  j | j t j ƒ |  j
 | j j d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j t j ƒ |  j
 | j j d ƒ |  j | j t j ƒ |  j
 | j j d ƒ d  S(   NsÚ   
        class First(object): pass
        class Second(First):
            def test(self):
                super() #@
            @classmethod
            def test_classmethod(cls):
                super() #@
        i    t   Secondi   (   R   R   R   R	   R
   R   R,   t   typeR    R   R   R.   R-   R   R   (   R   R    R'   R(   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_no_arguments_supern   s    	c         C   s˜  t  j d ƒ } t | d j ƒ  ƒ } |  j | t j ƒ |  j | j t j	 ƒ |  j
 | j j d ƒ |  j | j t j ƒ |  j
 | j j d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j t j	 ƒ |  j
 | j j d ƒ |  j | j t j ƒ |  j
 | j j d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j t j ƒ |  j
 | j j d ƒ |  j | j t j ƒ |  j
 | j j d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j t j ƒ |  j
 | j j d ƒ |  j | j t j ƒ |  j
 | j j d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j t j ƒ |  j
 | j j d	 ƒ |  j | j t j ƒ |  j
 | j j d	 ƒ d  S(
   Ns¦  
        class First(object): pass
        class Second(First): pass
        class Third(First):
            def test(self):
                super(Third, self) #@
                super(Second, self) #@

                # mro position and the type
                super(Third, Third) #@
                super(Third, Second) #@
                super(Fourth, Fourth) #@

        class Fourth(Third):
            pass
        i    t   Thirdi   R8   i   i   i   t   Fourth(   R   R   R   R	   R
   R   R,   R9   R    R   R   R.   R-   R   R   (   R   R    R'   R(   t   thirdt   fourtht   fifth(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_simple_cases‡   s@    	c         C   sm   t  j d ƒ } t | j ƒ  ƒ } |  j | t j ƒ t | j ƒ  ƒ } |  j | t j ƒ |  j | | ƒ d  S(   Nsl   
        class Super(object):
            def __init__(self):
                super(Super, self) #@
        (   R   R   R   R	   R
   R   R,   t   assertIs(   R   R   R   t
   reinferred(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_inferÅ   s    	c         C   s/  t  j d ƒ } t | d j ƒ  ƒ } |  j | t j ƒ |  j t j	 ƒ  } | j
 ƒ  Wd  QX|  j | j j j t j ƒ |  j | j j j j d ƒ x“ t | d t j t j f ƒ D]r \ } } t | j ƒ  ƒ } |  j | t j | ƒ |  j t j	 ƒ  } | j
 ƒ  Wd  QX|  j | j j j | ƒ qµ Wd  S(   Nsj  
        class Super(object):
            def __init__(self):
                # MRO pointer is not a type
                super(1, self) #@
                # MRO type is not a subtype
                super(Super, 1) #@
                # self is not a subtype of Bupper
                super(Bupper, self) #@
        class Bupper(Super):
            pass
        i    i   (   R   R   R   R	   R
   R   R,   R/   R   R0   R1   R3   t   super_R-   R   R   R   R   t   zipR    R   R9   (   R   R    R'   R5   R   t   invalid_typeR   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_inferring_invalid_supersÑ   s    	c         C   s^   t  j d ƒ } t | j ƒ  ƒ } | j } |  j | j ƒ  d t j ƒ |  j	 | t
 j ƒ d  S(   Nsl   
        class Super(object):
            def __init__(self):
                super(Super, self) #@
        s   %s.super(   R   R   R   R	   R   R   R   R    R   R
   R   R   (   R   R   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_proxiedì   s    		c         C   sÓ  t  j d ƒ } t | d j ƒ  ƒ } |  j | t j ƒ |  j | j d ƒ t | d j ƒ  ƒ } |  j | t	 j
 ƒ |  j | j j d ƒ |  j | j d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j d ƒ t | d j ƒ  ƒ } |  j | t	 j
 ƒ |  j | j j d ƒ |  j | j d ƒ t | d	 j ƒ  ƒ } |  j | t	 j
 ƒ |  j | j j d ƒ |  j | j d ƒ t | d
 j ƒ  ƒ } |  j | t	 j
 ƒ |  j | j j d ƒ |  j | j d ƒ d  S(   Ns  
        class First(object):
            def method(self):
                pass
            @classmethod
            def class_method(cls):
                pass
        class Super_Type_Type(First):    
            def method(self):
                super(Super_Type_Type, Super_Type_Type).method #@
                super(Super_Type_Type, Super_Type_Type).class_method #@
            @classmethod
            def class_method(cls):
                super(Super_Type_Type, Super_Type_Type).method #@
                super(Super_Type_Type, Super_Type_Type).class_method #@

        class Super_Type_Object(First):    
            def method(self):
                super(Super_Type_Object, self).method #@
                super(Super_Type_Object, self).class_method #@
        i    t   methodi   t   Firstt   classmethodi   i   i   i   (   R   R   R   R	   R
   R   t   FunctionDefR   R.   R    t   BoundMethodt   boundR9   (   R   R    R'   R(   R=   R>   R?   t   sixth(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_bound_model÷   s0    	c      	   C   sÊ  t  j d ƒ } t | d j ƒ  ƒ } |  j | t j ƒ |  j | j j	 d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j j	 d ƒ |  j
 t j ƒ  t | d j ƒ  ƒ Wd  QXt | d j ƒ  ƒ } |  j
 t j ƒ  | j d ƒ Wd  QX|  j
 t j ƒ  t | j d ƒ ƒ Wd  QXt | d	 j ƒ  ƒ } |  j | t j ƒ |  j | j	 d
 ƒ |  j | j j	 d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j	 d ƒ |  j | j j	 d ƒ d  S(   Ns3  
        class First(object):
            def test(self): pass
        class Second(First):
            def test2(self): pass
        class Third(Second):
            test3 = 42
            def __init__(self):
                super(Third, self).test2 #@
                super(Third, self).test #@
                # test3 is local, no MRO lookup is done.
                super(Third, self).test3 #@
                super(Third, self) #@

                # Unbounds.
                super(Third, Third).test2 #@
                super(Third, Third).test #@

        i    R8   i   RJ   i   i   t   test3i   t   test2i   t   test(   R   R   R   R	   R
   R    RM   R   RN   R.   R/   R   t   InferenceErrort   AttributeInferenceErrort   getattrt   igetattrR   RL   t   parent(   R   R    R'   R(   R>   t   first_unboundt   second_unbound(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt%   test_super_getattr_single_inheritance,  s.    	c         C   sQ   t  j d ƒ } t | j ƒ  ƒ } |  j t j ƒ  t | j d ƒ ƒ Wd  QXd  S(   Ns–   
        class A(object):
           test = 42
        class Super(A, A):
           def __init__(self):
               super(Super, self) #@
        RS   (   R   R   R   R	   R/   R   RU   RV   (   R   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_invalid_mroZ  s
    	c         C   sA  t  j d ƒ } t | d j ƒ  ƒ } |  j | t j ƒ |  j | j j	 d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j j	 d ƒ t | d j ƒ  ƒ } |  j | t j ƒ |  j | j j	 d ƒ t | d j ƒ  ƒ } |  j | j j	 d ƒ t | d	 j ƒ  ƒ } |  j | t
 j ƒ |  j | j j ƒ  j	 d ƒ d  S(
   Ns@  
        class A(object):
            def spam(self): return "A"
            def foo(self): return "A"
            @staticmethod
            def static(self): pass
        class B(A):
            def boo(self): return "B"
            def spam(self): return "B"
        class C(A):
            def boo(self): return "C"
        class E(C, B):
            def __init__(self):
                super(E, self).boo #@
                super(C, self).boo #@
                super(E, self).spam #@
                super(E, self).foo #@
                super(E, self).static #@
        i    t   Ci   t   Bi   i   t   Ai   (   R   R   R   R	   R
   R    RM   R   RN   R.   R   RL   RX   t   scope(   R   R    R'   R(   R=   R>   t   static(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_complex_mrof  s     	c   	      C   sÑ  t  j d ƒ } t | d j ƒ  ƒ } | j d ƒ d } |  j | t j ƒ |  j | j	 d ƒ | j d ƒ d } |  j | t j ƒ |  j | j	 d ƒ | j d ƒ d } |  j | t
 j ƒ |  j | j	 d ƒ | j d ƒ d } |  j | | j ƒ t | d j ƒ  ƒ } | j d ƒ d } |  j | j	 d ƒ | j d ƒ d } |  j | t j ƒ |  j | j	 d ƒ t | d	 j ƒ  ƒ } | j d ƒ d } |  j | j	 d
 ƒ | j d ƒ d } |  j | j	 d ƒ d  S(   Ns»   
        class X(object): pass
        class A(X):
            def __init__(self):
                super(A, self) #@
                super(A, A) #@
                super(X, A) #@
        i    t   __thisclass__R_   t   __self_class__t   __self__t	   __class__i   i   t   X(   R   R   R   R	   RV   R
   R   R   R   R.   R    R   R   (	   R   R    R'   t	   thisclasst	   selfclasst   self_t   clsR(   R=   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_data_model‰  s2    	c         C   s0   |  j  g  | j ƒ  D] } | j ^ q | ƒ d  S(   N(   R   R1   R.   (   R   t   klasst   expected_mrot   member(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   assertEqualMro¬  s    c         C   s  t  j d ƒ } t | d j ƒ  ƒ } |  j | d d d d g ƒ t | d j ƒ  ƒ } |  j | d d d g ƒ t | d j ƒ  ƒ } |  j | d d g ƒ t | d	 j ƒ  ƒ } |  j t j ƒ  | j ƒ  Wd  QXt | d
 j ƒ  ƒ } |  j t j ƒ  | j ƒ  Wd  QXd  S(   Ns5  
        class A(object): pass
        class B(A): pass
        class C(A): pass
        class E(C, B):
            def __init__(self):
                super(E, self) #@
                super(C, self) #@
                super(B, self) #@

                super(B, 1) #@
                super(1, B) #@
        i    R]   R^   R_   t   objecti   i   i   i   (	   R   R   R   R	   Rp   R/   R   R0   R1   (   R   R    R'   R(   R=   R>   R?   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_mro±  s    	c         C   se   t  j d ƒ } t | d j ƒ  ƒ } |  j | t j ƒ t | d j ƒ  ƒ } |  j | t j ƒ d  S(   Ns·   
        from collections import Missing
        class A(object):
            def __init__(self):
                super(Missing, self) #@
                super(A, Missing) #@
        i    i   (   R   R   R   R	   R
   R    R   (   R   R    R'   R(   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_yes_objectsÍ  s    	c         C   sk   t  j d ƒ } t | j ƒ  ƒ } |  j t j ƒ  | j ƒ  Wd  QX|  j t j ƒ  | j ƒ  Wd  QXd  S(   Ns†   
        import collections
        class A(object):
            def __init__(self):
                super(A, collections) #@
        (   R   R   R   R	   R/   R   R0   R1   (   R   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_invalid_typesÚ  s    	c         C   sK   t  j d ƒ } t | j ƒ  ƒ } |  j | t j ƒ |  j | j d ƒ d  S(   Nsü   
        class Foo(object):
            @property
            def dict(self):
                return 42

        class Bar(Foo):
            @property
            def dict(self):
                return super(Bar, self).dict

        Bar().dict
        i*   (	   R   R   R   R	   R
   R   R   R   R   (   R   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   test_super_propertiesç  s
    	(   R   R   R$   R&   R)   R   t   require_versionR6   R:   R@   RC   RG   RH   RP   R[   R\   Rb   Rl   Rp   Rr   Rs   Rt   Ru   (    (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyR   &   s&   		
		>				5	.		#	#				t   __main__(   t   unittestt   astroidR    R   R   R   R   R   t   TestCaseR   R   R   t   main(    (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_objects.pyt   <module>   s   ÿ Õ