<s> import re <EOL> import sys <EOL> import types <EOL> import unittest <EOL> import inspect <EOL> import linecache <EOL> import datetime <EOL> from UserList import UserList <EOL> from UserDict import UserDict <EOL> from test . test_support import run_unittest , check_py3k_warnings <EOL> with check_py3k_warnings ( <EOL> ( "<STR_LIT>" , SyntaxWarning ) , <EOL> quiet = True ) : <EOL> from test import inspect_fodder as mod <EOL> from test import inspect_fodder2 as mod2 <EOL> import unicodedata <EOL> modfile = mod . __file__ <EOL> if modfile . endswith ( ( '<STR_LIT:c>' , '<STR_LIT:o>' ) ) : <EOL> modfile = modfile [ : - <NUM_LIT:1> ] <EOL> import __builtin__ <EOL> try : <EOL> <NUM_LIT:1> // <NUM_LIT:0> <EOL> except : <EOL> tb = sys . exc_traceback <EOL> git = mod . StupidGit ( ) <EOL> class IsTestBase ( unittest . TestCase ) : <EOL> predicates = set ( [ inspect . isbuiltin , inspect . isclass , inspect . iscode , <EOL> inspect . isframe , inspect . isfunction , inspect . ismethod , <EOL> inspect . ismodule , inspect . istraceback , <EOL> inspect . isgenerator , inspect . isgeneratorfunction ] ) <EOL> def istest ( self , predicate , exp ) : <EOL> obj = eval ( exp ) <EOL> self . assertTrue ( predicate ( obj ) , '<STR_LIT>' % ( predicate . __name__ , exp ) ) <EOL> for other in self . predicates - set ( [ predicate ] ) : <EOL> if predicate == inspect . isgeneratorfunction and other == inspect . isfunction : <EOL> continue <EOL> self . assertFalse ( other ( obj ) , '<STR_LIT>' % ( other . __name__ , exp ) ) <EOL> def generator_function_example ( self ) : <EOL> for i in xrange ( <NUM_LIT:2> ) : <EOL> yield i <EOL> class TestPredicates ( IsTestBase ) : <EOL> def test_sixteen ( self ) : <EOL> count = len ( filter ( lambda x : x . startswith ( '<STR_LIT>' ) , dir ( inspect ) ) ) <EOL> expected = <NUM_LIT:16> <EOL> err_msg = "<STR_LIT>" % ( count , expected ) <EOL> self . assertEqual ( count , expected , err_msg ) <EOL> def test_excluding_predicates ( self ) : <EOL> self . istest ( inspect . isbuiltin , '<STR_LIT>' ) <EOL> self . istest ( inspect . isbuiltin , '<STR_LIT>' ) <EOL> self . istest ( inspect . iscode , '<STR_LIT>' ) <EOL> self . istest ( inspect . isframe , '<STR_LIT>' ) <EOL> self . istest ( inspect . isfunction , '<STR_LIT>' ) <EOL> self . istest ( inspect . ismethod , '<STR_LIT>' ) <EOL> self . istest ( inspect . ismethod , '<STR_LIT>' ) <EOL> self . istest ( inspect . ismodule , '<STR_LIT>' ) <EOL> self . istest ( inspect . istraceback , '<STR_LIT>' ) <EOL> self . istest ( inspect . isdatadescriptor , '<STR_LIT>' ) <EOL> self . istest ( inspect . isdatadescriptor , '<STR_LIT>' ) <EOL> self . istest ( inspect . isgenerator , '<STR_LIT>' ) <EOL> self . istest ( inspect . isgeneratorfunction , '<STR_LIT>' ) <EOL> if hasattr ( types , '<STR_LIT>' ) : <EOL> self . istest ( inspect . isgetsetdescriptor , <EOL> '<STR_LIT>' ) <EOL> else : <EOL> self . assertFalse ( inspect . isgetsetdescriptor ( type ( tb . tb_frame ) . f_locals ) ) <EOL> if hasattr ( types , '<STR_LIT>' ) : <EOL> self . istest ( inspect . ismemberdescriptor , '<STR_LIT>' ) <EOL> else : <EOL> self . assertFalse ( inspect . ismemberdescriptor ( datetime . timedelta . days ) ) <EOL> def test_isroutine ( self ) : <EOL> self . assertTrue ( inspect . isroutine ( mod . spam ) ) <EOL> self . assertTrue ( inspect . isroutine ( [ ] . count ) ) <EOL> def test_isclass ( self ) : <EOL> self . istest ( inspect . isclass , '<STR_LIT>' ) <EOL> self . assertTrue ( inspect . isclass ( list ) ) <EOL> class newstyle ( object ) : pass <EOL> self . assertTrue ( inspect . isclass ( newstyle ) ) <EOL> class CustomGetattr ( object ) : <EOL> def __getattr__ ( self , attr ) : <EOL> return None <EOL> self . assertFalse ( inspect . isclass ( CustomGetattr ( ) ) ) <EOL> def test_get_slot_members ( self ) : <EOL> class C ( object ) : <EOL> __slots__ = ( "<STR_LIT:a>" , "<STR_LIT:b>" ) <EOL> x = C ( ) <EOL> x . a = <NUM_LIT> <EOL> members = dict ( inspect . getmembers ( x ) ) <EOL> self . assertIn ( '<STR_LIT:a>' , members ) <EOL> self . assertNotIn ( '<STR_LIT:b>' , members ) <EOL> def test_isabstract ( self ) : <EOL> from abc import ABCMeta , abstractmethod <EOL> class AbstractClassExample ( object ) : <EOL> __metaclass__ = ABCMeta <EOL> @ abstractmethod <EOL> def foo ( self ) : <EOL> pass <EOL> class ClassExample ( AbstractClassExample ) : <EOL> def foo ( self ) : <EOL> pass <EOL> a = ClassExample ( ) <EOL> self . assertTrue ( inspect . isabstract ( AbstractClassExample ) ) <EOL> self . assertFalse ( inspect . isabstract ( ClassExample ) ) <EOL> self . assertFalse ( inspect . isabstract ( a ) ) <EOL> self . assertFalse ( inspect . isabstract ( int ) ) <EOL> self . assertFalse ( inspect . isabstract ( <NUM_LIT:5> ) ) <EOL> class TestInterpreterStack ( IsTestBase ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> unittest . TestCase . __init__ ( self , * args , ** kwargs ) <EOL> git . abuse ( <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> ) <EOL> def test_abuse_done ( self ) : <EOL> self . istest ( inspect . istraceback , '<STR_LIT>' ) <EOL> self . istest ( inspect . isframe , '<STR_LIT>' ) <EOL> def test_stack ( self ) : <EOL> self . assertTrue ( len ( mod . st ) >= <NUM_LIT:5> ) <EOL> self . assertEqual ( mod . st [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] , <EOL> ( modfile , <NUM_LIT:16> , '<STR_LIT>' , [ '<STR_LIT>' ] , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( mod . st [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] , <EOL> ( modfile , <NUM_LIT:9> , '<STR_LIT>' , [ '<STR_LIT>' ] , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( mod . st [ <NUM_LIT:2> ] [ <NUM_LIT:1> : ] , <EOL> ( modfile , <NUM_LIT> , '<STR_LIT>' , [ '<STR_LIT>' ] , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( mod . st [ <NUM_LIT:3> ] [ <NUM_LIT:1> : ] , <EOL> ( modfile , <NUM_LIT> , '<STR_LIT>' , [ '<STR_LIT>' ] , <NUM_LIT:0> ) ) <EOL> def test_trace ( self ) : <EOL> self . assertEqual ( len ( git . tr ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( git . tr [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] , ( modfile , <NUM_LIT> , '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( git . tr [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] , ( modfile , <NUM_LIT:9> , '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( git . tr [ <NUM_LIT:2> ] [ <NUM_LIT:1> : ] , ( modfile , <NUM_LIT> , '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <NUM_LIT:0> ) ) <EOL> def test_frame ( self ) : <EOL> args , varargs , varkw , locals = inspect . getargvalues ( mod . fr ) <EOL> self . assertEqual ( args , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) <EOL> self . assertEqual ( varargs , None ) <EOL> self . assertEqual ( varkw , None ) <EOL> self . assertEqual ( locals , { '<STR_LIT:x>' : <NUM_LIT:11> , '<STR_LIT:p>' : <NUM_LIT:11> , '<STR_LIT:y>' : <NUM_LIT> } ) <EOL> self . assertEqual ( inspect . formatargvalues ( args , varargs , varkw , locals ) , <EOL> '<STR_LIT>' ) <EOL> def test_previous_frame ( self ) : <EOL> args , varargs , varkw , locals = inspect . getargvalues ( mod . fr . f_back ) <EOL> self . assertEqual ( args , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , [ '<STR_LIT:e>' , [ '<STR_LIT:f>' ] ] ] ) <EOL> self . assertEqual ( varargs , '<STR_LIT:g>' ) <EOL> self . assertEqual ( varkw , '<STR_LIT:h>' ) <EOL> self . assertEqual ( inspect . formatargvalues ( args , varargs , varkw , locals ) , <EOL> '<STR_LIT>' ) <EOL> class GetSourceBase ( unittest . TestCase ) : <EOL> fodderFile = None <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> unittest . TestCase . __init__ ( self , * args , ** kwargs ) <EOL> with open ( inspect . getsourcefile ( self . fodderFile ) ) as fp : <EOL> self . source = fp . read ( ) <EOL> def sourcerange ( self , top , bottom ) : <EOL> lines = self . source . split ( "<STR_LIT:\n>" ) <EOL> return "<STR_LIT:\n>" . join ( lines [ top - <NUM_LIT:1> : bottom ] ) + "<STR_LIT:\n>" <EOL> def assertSourceEqual ( self , obj , top , bottom ) : <EOL> self . assertEqual ( inspect . getsource ( obj ) , <EOL> self . sourcerange ( top , bottom ) ) <EOL> class TestRetrievingSourceCode ( GetSourceBase ) : <EOL> fodderFile = mod <EOL> def test_getclasses ( self ) : <EOL> classes = inspect . getmembers ( mod , inspect . isclass ) <EOL> self . assertEqual ( classes , <EOL> [ ( '<STR_LIT>' , mod . FesteringGob ) , <EOL> ( '<STR_LIT>' , mod . MalodorousPervert ) , <EOL> ( '<STR_LIT>' , mod . ParrotDroppings ) , <EOL> ( '<STR_LIT>' , mod . StupidGit ) , <EOL> ( '<STR_LIT>' , mod . MalodorousPervert ) , <EOL> ] ) <EOL> tree = inspect . getclasstree ( [ cls [ <NUM_LIT:1> ] for cls in classes ] ) <EOL> self . assertEqual ( tree , <EOL> [ ( mod . ParrotDroppings , ( ) ) , <EOL> [ ( mod . FesteringGob , ( mod . MalodorousPervert , <EOL> mod . ParrotDroppings ) ) <EOL> ] , <EOL> ( mod . StupidGit , ( ) ) , <EOL> [ ( mod . MalodorousPervert , ( mod . StupidGit , ) ) , <EOL> [ ( mod . FesteringGob , ( mod . MalodorousPervert , <EOL> mod . ParrotDroppings ) ) <EOL> ] <EOL> ] <EOL> ] ) <EOL> tree = inspect . getclasstree ( [ cls [ <NUM_LIT:1> ] for cls in classes ] , True ) <EOL> self . assertEqual ( tree , <EOL> [ ( mod . ParrotDroppings , ( ) ) , <EOL> ( mod . StupidGit , ( ) ) , <EOL> [ ( mod . MalodorousPervert , ( mod . StupidGit , ) ) , <EOL> [ ( mod . FesteringGob , ( mod . MalodorousPervert , <EOL> mod . ParrotDroppings ) ) <EOL> ] <EOL> ] <EOL> ] ) <EOL> def test_getfunctions ( self ) : <EOL> functions = inspect . getmembers ( mod , inspect . isfunction ) <EOL> self . assertEqual ( functions , [ ( '<STR_LIT>' , mod . eggs ) , <EOL> ( '<STR_LIT>' , mod . spam ) ] ) <EOL> @ unittest . skipIf ( sys . flags . optimize >= <NUM_LIT:2> , <EOL> "<STR_LIT>" ) <EOL> def test_getdoc ( self ) : <EOL> self . assertEqual ( inspect . getdoc ( mod ) , '<STR_LIT>' ) <EOL> self . assertEqual ( inspect . getdoc ( mod . StupidGit ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( inspect . getdoc ( git . abuse ) , <EOL> '<STR_LIT>' ) <EOL> def test_cleandoc ( self ) : <EOL> self . assertEqual ( inspect . cleandoc ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> def test_getcomments ( self ) : <EOL> self . assertEqual ( inspect . getcomments ( mod ) , '<STR_LIT>' ) <EOL> self . assertEqual ( inspect . getcomments ( mod . StupidGit ) , '<STR_LIT>' ) <EOL> def test_getmodule ( self ) : <EOL> self . assertEqual ( inspect . getmodule ( mod ) , mod ) <EOL> self . assertEqual ( inspect . getmodule ( mod . StupidGit ) , mod ) <EOL> self . assertEqual ( inspect . getmodule ( mod . StupidGit . abuse ) , mod ) <EOL> self . assertEqual ( inspect . getmodule ( mod . StupidGit . abuse ) , mod ) <EOL> self . assertEqual ( inspect . getmodule ( str ) , sys . modules [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( inspect . getmodule ( None , modfile ) , mod ) <EOL> def test_getsource ( self ) : <EOL> self . assertSourceEqual ( git . abuse , <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertSourceEqual ( mod . StupidGit , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_getsourcefile ( self ) : <EOL> self . assertEqual ( inspect . getsourcefile ( mod . spam ) , modfile ) <EOL> self . assertEqual ( inspect . getsourcefile ( git . abuse ) , modfile ) <EOL> fn = "<STR_LIT>" <EOL> co = compile ( "<STR_LIT:None>" , fn , "<STR_LIT>" ) <EOL> self . assertEqual ( inspect . getsourcefile ( co ) , None ) <EOL> linecache . cache [ co . co_filename ] = ( <NUM_LIT:1> , None , "<STR_LIT:None>" , co . co_filename ) <EOL> self . assertEqual ( inspect . getsourcefile ( co ) , fn ) <EOL> def test_getfile ( self ) : <EOL> self . assertEqual ( inspect . getfile ( mod . StupidGit ) , mod . __file__ ) <EOL> def test_getmodule_recursion ( self ) : <EOL> from types import ModuleType <EOL> name = '<STR_LIT>' <EOL> m = sys . modules [ name ] = ModuleType ( name ) <EOL> m . __file__ = "<STR_LIT>" <EOL> m . __loader__ = "<STR_LIT>" <EOL> exec "<STR_LIT>" in m . __dict__ <EOL> self . assertEqual ( inspect . getsourcefile ( m . x . func_code ) , '<STR_LIT>' ) <EOL> del sys . modules [ name ] <EOL> inspect . getmodule ( compile ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_proceed_with_fake_filename ( self ) : <EOL> '''<STR_LIT>''' <EOL> fn , source = '<STR_LIT>' , '<STR_LIT>' <EOL> getlines = linecache . getlines <EOL> def monkey ( filename , module_globals = None ) : <EOL> if filename == fn : <EOL> return source . splitlines ( True ) <EOL> else : <EOL> return getlines ( filename , module_globals ) <EOL> linecache . getlines = monkey <EOL> try : <EOL> ns = { } <EOL> exec compile ( source , fn , '<STR_LIT>' ) in ns <EOL> inspect . getsource ( ns [ "<STR_LIT:x>" ] ) <EOL> finally : <EOL> linecache . getlines = getlines <EOL> class TestDecorators ( GetSourceBase ) : <EOL> fodderFile = mod2 <EOL> def test_wrapped_decorator ( self ) : <EOL> self . assertSourceEqual ( mod2 . wrapped , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_replacing_decorator ( self ) : <EOL> self . assertSourceEqual ( mod2 . gone , <NUM_LIT:9> , <NUM_LIT:10> ) <EOL> class TestOneliners ( GetSourceBase ) : <EOL> fodderFile = mod2 <EOL> def test_oneline_lambda ( self ) : <EOL> self . assertSourceEqual ( mod2 . oll , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_threeline_lambda ( self ) : <EOL> self . assertSourceEqual ( mod2 . tll , <NUM_LIT> , <NUM_LIT:30> ) <EOL> def test_twoline_indented_lambda ( self ) : <EOL> self . assertSourceEqual ( mod2 . tlli , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_onelinefunc ( self ) : <EOL> self . assertSourceEqual ( mod2 . onelinefunc , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_manyargs ( self ) : <EOL> self . assertSourceEqual ( mod2 . manyargs , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_twolinefunc ( self ) : <EOL> self . assertSourceEqual ( mod2 . twolinefunc , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_lambda_in_list ( self ) : <EOL> self . assertSourceEqual ( mod2 . a [ <NUM_LIT:1> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_anonymous ( self ) : <EOL> self . assertSourceEqual ( mod2 . anonymous , <NUM_LIT> , <NUM_LIT> ) <EOL> class TestBuggyCases ( GetSourceBase ) : <EOL> fodderFile = mod2 <EOL> def test_with_comment ( self ) : <EOL> self . assertSourceEqual ( mod2 . with_comment , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_multiline_sig ( self ) : <EOL> self . assertSourceEqual ( mod2 . multiline_sig [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT:64> ) <EOL> def test_nested_class ( self ) : <EOL> self . assertSourceEqual ( mod2 . func69 ( ) . func71 , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_one_liner_followed_by_non_name ( self ) : <EOL> self . assertSourceEqual ( mod2 . func77 , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_one_liner_dedent_non_name ( self ) : <EOL> self . assertSourceEqual ( mod2 . cls82 . func83 , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_with_comment_instead_of_docstring ( self ) : <EOL> self . assertSourceEqual ( mod2 . func88 , <NUM_LIT> , <NUM_LIT> ) <EOL> def test_method_in_dynamic_class ( self ) : <EOL> self . assertSourceEqual ( mod2 . method_in_dynamic_class , <NUM_LIT> , <NUM_LIT> ) <EOL> @ unittest . skipIf ( <EOL> not hasattr ( unicodedata , '<STR_LIT>' ) or <EOL> unicodedata . __file__ [ - <NUM_LIT:4> : ] in ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> def test_findsource_binary ( self ) : <EOL> self . assertRaises ( IOError , inspect . getsource , unicodedata ) <EOL> self . assertRaises ( IOError , inspect . findsource , unicodedata ) <EOL> def test_findsource_code_in_linecache ( self ) : <EOL> lines = [ "<STR_LIT>" ] <EOL> co = compile ( lines [ <NUM_LIT:0> ] , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertRaises ( IOError , inspect . findsource , co ) <EOL> self . assertRaises ( IOError , inspect . getsource , co ) <EOL> linecache . cache [ co . co_filename ] = ( <NUM_LIT:1> , None , lines , co . co_filename ) <EOL> self . assertEqual ( inspect . findsource ( co ) , ( lines , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( inspect . getsource ( co ) , lines [ <NUM_LIT:0> ] ) <EOL> def test_findsource_without_filename ( self ) : <EOL> for fname in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> co = compile ( '<STR_LIT>' , fname , "<STR_LIT>" ) <EOL> self . assertRaises ( IOError , inspect . findsource , co ) <EOL> self . assertRaises ( IOError , inspect . getsource , co ) <EOL> class _BrokenDataDescriptor ( object ) : <EOL> """<STR_LIT>""" <EOL> def __get__ ( * args ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> def __set__ ( * args ) : <EOL> raise RuntimeError <EOL> def __getattr__ ( * args ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> class _BrokenMethodDescriptor ( object ) : <EOL> """<STR_LIT>""" <EOL> def __get__ ( * args ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> def __getattr__ ( * args ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> def attrs_wo_objs ( cls ) : <EOL> return [ t [ : <NUM_LIT:3> ] for t in inspect . classify_class_attrs ( cls ) ] <EOL> class TestClassesAndFunctions ( unittest . TestCase ) : <EOL> def test_classic_mro ( self ) : <EOL> class A : pass <EOL> class B ( A ) : pass <EOL> class C ( A ) : pass <EOL> class D ( B , C ) : pass <EOL> expected = ( D , B , A , C ) <EOL> got = inspect . getmro ( D ) <EOL> self . assertEqual ( expected , got ) <EOL> def test_newstyle_mro ( self ) : <EOL> class A ( object ) : pass <EOL> class B ( A ) : pass <EOL> class C ( A ) : pass <EOL> class D ( B , C ) : pass <EOL> expected = ( D , B , C , A , object ) <EOL> got = inspect . getmro ( D ) <EOL> self . assertEqual ( expected , got ) <EOL> def assertArgSpecEquals ( self , routine , args_e , varargs_e = None , <EOL> varkw_e = None , defaults_e = None , <EOL> formatted = None ) : <EOL> args , varargs , varkw , defaults = inspect . getargspec ( routine ) <EOL> self . assertEqual ( args , args_e ) <EOL> self . assertEqual ( varargs , varargs_e ) <EOL> self . assertEqual ( varkw , varkw_e ) <EOL> self . assertEqual ( defaults , defaults_e ) <EOL> if formatted is not None : <EOL> self . assertEqual ( inspect . formatargspec ( args , varargs , varkw , defaults ) , <EOL> formatted ) <EOL> def test_getargspec ( self ) : <EOL> self . assertArgSpecEquals ( mod . eggs , [ '<STR_LIT:x>' , '<STR_LIT:y>' ] , formatted = '<STR_LIT>' ) <EOL> self . assertArgSpecEquals ( mod . spam , <EOL> [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , [ '<STR_LIT:e>' , [ '<STR_LIT:f>' ] ] ] , <EOL> '<STR_LIT:g>' , '<STR_LIT:h>' , ( <NUM_LIT:3> , ( <NUM_LIT:4> , ( <NUM_LIT:5> , ) ) ) , <EOL> '<STR_LIT>' ) <EOL> def test_getargspec_method ( self ) : <EOL> class A ( object ) : <EOL> def m ( self ) : <EOL> pass <EOL> self . assertArgSpecEquals ( A . m , [ '<STR_LIT>' ] ) <EOL> def test_getargspec_sublistofone ( self ) : <EOL> with check_py3k_warnings ( <EOL> ( "<STR_LIT>" , SyntaxWarning ) , <EOL> ( "<STR_LIT>" , SyntaxWarning ) ) : <EOL> exec '<STR_LIT>' <EOL> self . assertArgSpecEquals ( sublistOfOne , [ [ '<STR_LIT:foo>' ] ] ) <EOL> exec '<STR_LIT>' <EOL> self . assertArgSpecEquals ( fakeSublistOfOne , [ '<STR_LIT:foo>' ] ) <EOL> def _classify_test ( self , newstyle ) : <EOL> """<STR_LIT>""" <EOL> if newstyle : <EOL> base = object <EOL> else : <EOL> class base : <EOL> pass <EOL> class A ( base ) : <EOL> def s ( ) : pass <EOL> s = staticmethod ( s ) <EOL> def c ( cls ) : pass <EOL> c = classmethod ( c ) <EOL> def getp ( self ) : pass <EOL> p = property ( getp ) <EOL> def m ( self ) : pass <EOL> def m1 ( self ) : pass <EOL> datablob = '<STR_LIT:1>' <EOL> dd = _BrokenDataDescriptor ( ) <EOL> md = _BrokenMethodDescriptor ( ) <EOL> attrs = attrs_wo_objs ( A ) <EOL> self . assertIn ( ( '<STR_LIT:s>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:c>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:p>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:m>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:data>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:data>' , A ) , attrs , '<STR_LIT>' ) <EOL> class B ( A ) : <EOL> def m ( self ) : pass <EOL> attrs = attrs_wo_objs ( B ) <EOL> self . assertIn ( ( '<STR_LIT:s>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:c>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:p>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:m>' , '<STR_LIT>' , B ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:data>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:data>' , A ) , attrs , '<STR_LIT>' ) <EOL> class C ( A ) : <EOL> def m ( self ) : pass <EOL> def c ( self ) : pass <EOL> attrs = attrs_wo_objs ( C ) <EOL> self . assertIn ( ( '<STR_LIT:s>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:c>' , '<STR_LIT>' , C ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:p>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:m>' , '<STR_LIT>' , C ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:data>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:data>' , A ) , attrs , '<STR_LIT>' ) <EOL> class D ( B , C ) : <EOL> def m1 ( self ) : pass <EOL> attrs = attrs_wo_objs ( D ) <EOL> self . assertIn ( ( '<STR_LIT:s>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> if newstyle : <EOL> self . assertIn ( ( '<STR_LIT:c>' , '<STR_LIT>' , C ) , attrs , '<STR_LIT>' ) <EOL> else : <EOL> self . assertIn ( ( '<STR_LIT:c>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:p>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT:m>' , '<STR_LIT>' , B ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' , D ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:data>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' , A ) , attrs , '<STR_LIT>' ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:data>' , A ) , attrs , '<STR_LIT>' ) <EOL> def test_classify_oldstyle ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _classify_test ( False ) <EOL> def test_classify_newstyle ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _classify_test ( True ) <EOL> def test_classify_builtin_types ( self ) : <EOL> for name in dir ( __builtin__ ) : <EOL> builtin = getattr ( __builtin__ , name ) <EOL> if isinstance ( builtin , type ) : <EOL> inspect . classify_class_attrs ( builtin ) <EOL> def test_getmembers_method ( self ) : <EOL> class B : <EOL> def f ( self ) : <EOL> pass <EOL> self . assertIn ( ( '<STR_LIT:f>' , B . f ) , inspect . getmembers ( B ) ) <EOL> self . assertIn ( ( '<STR_LIT:f>' , B . f ) , inspect . getmembers ( B , inspect . ismethod ) ) <EOL> b = B ( ) <EOL> self . assertIn ( ( '<STR_LIT:f>' , b . f ) , inspect . getmembers ( b ) ) <EOL> self . assertIn ( ( '<STR_LIT:f>' , b . f ) , inspect . getmembers ( b , inspect . ismethod ) ) <EOL> class B ( object ) : <EOL> def f ( self ) : <EOL> pass <EOL> self . assertIn ( ( '<STR_LIT:f>' , B . f ) , inspect . getmembers ( B ) ) <EOL> self . assertIn ( ( '<STR_LIT:f>' , B . f ) , inspect . getmembers ( B , inspect . ismethod ) ) <EOL> b = B ( ) <EOL> self . assertIn ( ( '<STR_LIT:f>' , b . f ) , inspect . getmembers ( b ) ) <EOL> self . assertIn ( ( '<STR_LIT:f>' , b . f ) , inspect . getmembers ( b , inspect . ismethod ) ) <EOL> class TestGetcallargsFunctions ( unittest . TestCase ) : <EOL> is_tuplename = re . compile ( r'<STR_LIT>' ) . match <EOL> def assertEqualCallArgs ( self , func , call_params_string , locs = None ) : <EOL> locs = dict ( locs or { } , func = func ) <EOL> r1 = eval ( '<STR_LIT>' % call_params_string , None , locs ) <EOL> r2 = eval ( '<STR_LIT>' % call_params_string , None , <EOL> locs ) <EOL> self . assertEqual ( r1 , r2 ) <EOL> def assertEqualException ( self , func , call_param_string , locs = None ) : <EOL> locs = dict ( locs or { } , func = func ) <EOL> try : <EOL> eval ( '<STR_LIT>' % call_param_string , None , locs ) <EOL> except Exception , ex1 : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> try : <EOL> eval ( '<STR_LIT>' % call_param_string , None , <EOL> locs ) <EOL> except Exception , ex2 : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> self . assertIs ( type ( ex1 ) , type ( ex2 ) ) <EOL> self . assertEqual ( str ( ex1 ) , str ( ex2 ) ) <EOL> def makeCallable ( self , signature ) : <EOL> """<STR_LIT>""" <EOL> with check_py3k_warnings ( <EOL> ( "<STR_LIT>" , SyntaxWarning ) , <EOL> quiet = True ) : <EOL> code = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return eval ( code % signature , { '<STR_LIT>' : self . is_tuplename } ) <EOL> def test_plain ( self ) : <EOL> f = self . makeCallable ( '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT:2>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> def test_varargs ( self ) : <EOL> f = self . makeCallable ( '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT:2>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> def test_varkw ( self ) : <EOL> f = self . makeCallable ( '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> def test_varkw_only ( self ) : <EOL> f = self . makeCallable ( '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> def test_tupleargs ( self ) : <EOL> f = self . makeCallable ( '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> def test_multiple_features ( self ) : <EOL> f = self . makeCallable ( '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqualCallArgs ( f , '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_errors ( self ) : <EOL> f0 = self . makeCallable ( '<STR_LIT>' ) <EOL> f1 = self . makeCallable ( '<STR_LIT>' ) <EOL> f2 = self . makeCallable ( '<STR_LIT>' ) <EOL> self . assertEqualException ( f0 , '<STR_LIT:1>' ) <EOL> self . assertEqualException ( f0 , '<STR_LIT>' ) <EOL> self . assertEqualException ( f0 , '<STR_LIT>' ) <EOL> self . assertEqualException ( f1 , '<STR_LIT>' ) <EOL> self . assertEqualException ( f1 , '<STR_LIT:1>' ) <EOL> self . assertEqualException ( f1 , '<STR_LIT>' ) <EOL> self . assertEqualException ( f1 , '<STR_LIT>' ) <EOL> self . assertEqualException ( f2 , '<STR_LIT>' ) <EOL> self . assertEqualException ( f2 , '<STR_LIT>' ) <EOL> for f in f1 , f2 : <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> f = self . makeCallable ( '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT:1>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> self . assertEqualException ( f , '<STR_LIT>' ) <EOL> f3 = self . makeCallable ( '<STR_LIT>' ) <EOL> self . assertEqualException ( f3 , '<STR_LIT>' ) <EOL> self . assertEqualException ( f3 , '<STR_LIT>' ) <EOL> class TestGetcallargsMethods ( TestGetcallargsFunctions ) : <EOL> def setUp ( self ) : <EOL> class Foo ( object ) : <EOL> pass <EOL> self . cls = Foo <EOL> self . inst = Foo ( ) <EOL> def makeCallable ( self , signature ) : <EOL> assert '<STR_LIT>' not in signature <EOL> mk = super ( TestGetcallargsMethods , self ) . makeCallable <EOL> self . cls . method = mk ( '<STR_LIT>' + signature ) <EOL> return self . inst . method <EOL> class TestGetcallargsUnboundMethods ( TestGetcallargsMethods ) : <EOL> def makeCallable ( self , signature ) : <EOL> super ( TestGetcallargsUnboundMethods , self ) . makeCallable ( signature ) <EOL> return self . cls . method <EOL> def assertEqualCallArgs ( self , func , call_params_string , locs = None ) : <EOL> return super ( TestGetcallargsUnboundMethods , self ) . assertEqualCallArgs ( <EOL> * self . _getAssertEqualParams ( func , call_params_string , locs ) ) <EOL> def assertEqualException ( self , func , call_params_string , locs = None ) : <EOL> return super ( TestGetcallargsUnboundMethods , self ) . assertEqualException ( <EOL> * self . _getAssertEqualParams ( func , call_params_string , locs ) ) <EOL> def _getAssertEqualParams ( self , func , call_params_string , locs = None ) : <EOL> assert '<STR_LIT>' not in call_params_string <EOL> locs = dict ( locs or { } , inst = self . inst ) <EOL> return ( func , '<STR_LIT>' + call_params_string , locs ) <EOL> def test_main ( ) : <EOL> run_unittest ( <EOL> TestDecorators , TestRetrievingSourceCode , TestOneliners , TestBuggyCases , <EOL> TestInterpreterStack , TestClassesAndFunctions , TestPredicates , <EOL> TestGetcallargsFunctions , TestGetcallargsMethods , <EOL> TestGetcallargsUnboundMethods ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
