Back to index

python3.2  3.2.2
Public Member Functions
test.test_inspect.TestClassesAndFunctions Class Reference

List of all members.

Public Member Functions

def test_newstyle_mro
def assertArgSpecEquals
def assertFullArgSpecEquals
def test_getargspec
def test_getfullargspec
def test_getargspec_method
def test_classify_newstyle

Detailed Description

Definition at line 432 of file test_inspect.py.


Member Function Documentation

def test.test_inspect.TestClassesAndFunctions.assertArgSpecEquals (   self,
  routine,
  args_e,
  varargs_e = None,
  varkw_e = None,
  defaults_e = None,
  formatted = None 
)

Definition at line 445 of file test_inspect.py.

00445 
00446                             varkw_e=None, defaults_e=None, formatted=None):
00447         args, varargs, varkw, defaults = inspect.getargspec(routine)
00448         self.assertEqual(args, args_e)
00449         self.assertEqual(varargs, varargs_e)
00450         self.assertEqual(varkw, varkw_e)
00451         self.assertEqual(defaults, defaults_e)
00452         if formatted is not None:
00453             self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
00454                              formatted)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_inspect.TestClassesAndFunctions.assertFullArgSpecEquals (   self,
  routine,
  args_e,
  varargs_e = None,
  varkw_e = None,
  defaults_e = None,
  kwonlyargs_e = [],
  kwonlydefaults_e = None,
  ann_e = {},
  formatted = None 
)

Definition at line 458 of file test_inspect.py.

00458 
00459                                     ann_e={}, formatted=None):
00460         args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \
00461             inspect.getfullargspec(routine)
00462         self.assertEqual(args, args_e)
00463         self.assertEqual(varargs, varargs_e)
00464         self.assertEqual(varkw, varkw_e)
00465         self.assertEqual(defaults, defaults_e)
00466         self.assertEqual(kwonlyargs, kwonlyargs_e)
00467         self.assertEqual(kwonlydefaults, kwonlydefaults_e)
00468         self.assertEqual(ann, ann_e)
00469         if formatted is not None:
00470             self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults,
00471                                                     kwonlyargs, kwonlydefaults, ann),
00472                              formatted)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 510 of file test_inspect.py.

00510 
00511     def test_classify_newstyle(self):
00512         class A(object):
00513 
00514             def s(): pass
00515             s = staticmethod(s)
00516 
00517             def c(cls): pass
00518             c = classmethod(c)
00519 
00520             def getp(self): pass
00521             p = property(getp)
00522 
00523             def m(self): pass
00524 
00525             def m1(self): pass
00526 
00527             datablob = '1'
00528 
00529         attrs = attrs_wo_objs(A)
00530         self.assertIn(('s', 'static method', A), attrs, 'missing static method')
00531         self.assertIn(('c', 'class method', A), attrs, 'missing class method')
00532         self.assertIn(('p', 'property', A), attrs, 'missing property')
00533         self.assertIn(('m', 'method', A), attrs,
00534                       'missing plain method: %r' % attrs)
00535         self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
00536         self.assertIn(('datablob', 'data', A), attrs, 'missing data')
00537 
00538         class B(A):
00539 
00540             def m(self): pass
00541 
00542         attrs = attrs_wo_objs(B)
00543         self.assertIn(('s', 'static method', A), attrs, 'missing static method')
00544         self.assertIn(('c', 'class method', A), attrs, 'missing class method')
00545         self.assertIn(('p', 'property', A), attrs, 'missing property')
00546         self.assertIn(('m', 'method', B), attrs, 'missing plain method')
00547         self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
00548         self.assertIn(('datablob', 'data', A), attrs, 'missing data')
00549 
00550 
00551         class C(A):
00552 
00553             def m(self): pass
00554             def c(self): pass
00555 
00556         attrs = attrs_wo_objs(C)
00557         self.assertIn(('s', 'static method', A), attrs, 'missing static method')
00558         self.assertIn(('c', 'method', C), attrs, 'missing plain method')
00559         self.assertIn(('p', 'property', A), attrs, 'missing property')
00560         self.assertIn(('m', 'method', C), attrs, 'missing plain method')
00561         self.assertIn(('m1', 'method', A), attrs, 'missing plain method')
00562         self.assertIn(('datablob', 'data', A), attrs, 'missing data')
00563 
00564         class D(B, C):
00565 
00566             def m1(self): pass
00567 
00568         attrs = attrs_wo_objs(D)
00569         self.assertIn(('s', 'static method', A), attrs, 'missing static method')
00570         self.assertIn(('c', 'method', C), attrs, 'missing plain method')
00571         self.assertIn(('p', 'property', A), attrs, 'missing property')
00572         self.assertIn(('m', 'method', B), attrs, 'missing plain method')
00573         self.assertIn(('m1', 'method', D), attrs, 'missing plain method')
00574         self.assertIn(('datablob', 'data', A), attrs, 'missing data')

Here is the call graph for this function:

Definition at line 473 of file test_inspect.py.

00473 
00474     def test_getargspec(self):
00475         self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted='(x, y)')
00476 
00477         self.assertArgSpecEquals(mod.spam,
00478                                  ['a', 'b', 'c', 'd', 'e', 'f'],
00479                                  'g', 'h', (3, 4, 5),
00480                                  '(a, b, c, d=3, e=4, f=5, *g, **h)')
00481 
00482         self.assertRaises(ValueError, self.assertArgSpecEquals,
00483                           mod2.keyworded, [])
00484 
00485         self.assertRaises(ValueError, self.assertArgSpecEquals,
00486                           mod2.annotated, [])
00487         self.assertRaises(ValueError, self.assertArgSpecEquals,
00488                           mod2.keyword_only_arg, [])
00489 

Here is the call graph for this function:

Definition at line 504 of file test_inspect.py.

00504 
00505     def test_getargspec_method(self):
00506         class A(object):
00507             def m(self):
00508                 pass
00509         self.assertArgSpecEquals(A.m, ['self'])

Definition at line 490 of file test_inspect.py.

00490 
00491     def test_getfullargspec(self):
00492         self.assertFullArgSpecEquals(mod2.keyworded, [], varargs_e='arg1',
00493                                      kwonlyargs_e=['arg2'],
00494                                      kwonlydefaults_e={'arg2':1},
00495                                      formatted='(*arg1, arg2=1)')
00496 
00497         self.assertFullArgSpecEquals(mod2.annotated, ['arg1'],
00498                                      ann_e={'arg1' : list},
00499                                      formatted='(arg1: list)')
00500         self.assertFullArgSpecEquals(mod2.keyword_only_arg, [],
00501                                      kwonlyargs_e=['arg'],
00502                                      formatted='(*, arg)')
00503 

Here is the call graph for this function:

Definition at line 433 of file test_inspect.py.

00433 
00434     def test_newstyle_mro(self):
00435         # The same w/ new-class MRO.
00436         class A(object):    pass
00437         class B(A): pass
00438         class C(A): pass
00439         class D(B, C): pass
00440 
00441         expected = (D, B, C, A, object)
00442         got = inspect.getmro(D)
00443         self.assertEqual(expected, got)

Here is the call graph for this function:


The documentation for this class was generated from the following file: