Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_inspect.TestRetrievingSourceCode Class Reference
Inheritance diagram for test.test_inspect.TestRetrievingSourceCode:
Inheritance graph
[legend]
Collaboration diagram for test.test_inspect.TestRetrievingSourceCode:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_getclasses
def test_getfunctions
def test_getdoc
def test_cleandoc
def test_getcomments
def test_getmodule
def test_getsource
def test_getsourcefile
def test_getfile
def test_getmodule_recursion
def test_proceed_with_fake_filename
def sourcerange
def assertSourceEqual

Public Attributes

 source

Static Public Attributes

 fodderModule = mod

Detailed Description

Definition at line 215 of file test_inspect.py.


Member Function Documentation

def test.test_inspect.GetSourceBase.assertSourceEqual (   self,
  obj,
  top,
  bottom 
) [inherited]

Definition at line 211 of file test_inspect.py.

00211 
00212     def assertSourceEqual(self, obj, top, bottom):
00213         self.assertEqual(inspect.getsource(obj),
00214                          self.sourcerange(top, bottom))

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_inspect.GetSourceBase.sourcerange (   self,
  top,
  bottom 
) [inherited]

Definition at line 207 of file test_inspect.py.

00207 
00208     def sourcerange(self, top, bottom):
00209         lines = self.source.split("\n")
00210         return "\n".join(lines[top-1:bottom]) + "\n"

Here is the caller graph for this function:

Definition at line 252 of file test_inspect.py.

00252 
00253     def test_cleandoc(self):
00254         self.assertEqual(inspect.cleandoc('An\n    indented\n    docstring.'),
00255                          'An\nindented\ndocstring.')

Here is the call graph for this function:

Definition at line 218 of file test_inspect.py.

00218 
00219     def test_getclasses(self):
00220         classes = inspect.getmembers(mod, inspect.isclass)
00221         self.assertEqual(classes,
00222                          [('FesteringGob', mod.FesteringGob),
00223                           ('MalodorousPervert', mod.MalodorousPervert),
00224                           ('ParrotDroppings', mod.ParrotDroppings),
00225                           ('StupidGit', mod.StupidGit)])
00226         tree = inspect.getclasstree([cls[1] for cls in classes], 1)
00227         self.assertEqual(tree,
00228                          [(object, ()),
00229                           [(mod.ParrotDroppings, (object,)),
00230                            (mod.StupidGit, (object,)),
00231                            [(mod.MalodorousPervert, (mod.StupidGit,)),
00232                             [(mod.FesteringGob, (mod.MalodorousPervert,
00233                                                     mod.ParrotDroppings))
00234                              ]
00235                             ]
00236                            ]
00237                           ])

Here is the call graph for this function:

Definition at line 256 of file test_inspect.py.

00256 
00257     def test_getcomments(self):
00258         self.assertEqual(inspect.getcomments(mod), '# line 1\n')
00259         self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n')

Here is the call graph for this function:

Definition at line 245 of file test_inspect.py.

00245 
00246     def test_getdoc(self):
00247         self.assertEqual(inspect.getdoc(mod), 'A module docstring.')
00248         self.assertEqual(inspect.getdoc(mod.StupidGit),
00249                          'A longer,\n\nindented\n\ndocstring.')
00250         self.assertEqual(inspect.getdoc(git.abuse),
00251                          'Another\n\ndocstring\n\ncontaining\n\ntabs')

Here is the call graph for this function:

Definition at line 287 of file test_inspect.py.

00287 
00288     def test_getfile(self):
00289         self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__)

Here is the call graph for this function:

Definition at line 238 of file test_inspect.py.

00238 
00239     def test_getfunctions(self):
00240         functions = inspect.getmembers(mod, inspect.isfunction)
00241         self.assertEqual(functions, [('eggs', mod.eggs),
00242                                      ('spam', mod.spam)])

Here is the call graph for this function:

Definition at line 260 of file test_inspect.py.

00260 
00261     def test_getmodule(self):
00262         # Check actual module
00263         self.assertEqual(inspect.getmodule(mod), mod)
00264         # Check class (uses __module__ attribute)
00265         self.assertEqual(inspect.getmodule(mod.StupidGit), mod)
00266         # Check a method (no __module__ attribute, falls back to filename)
00267         self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod)
00268         # Do it again (check the caching isn't broken)
00269         self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod)
00270         # Check a builtin
00271         self.assertEqual(inspect.getmodule(str), sys.modules["builtins"])
00272         # Check filename override
00273         self.assertEqual(inspect.getmodule(None, modfile), mod)

Here is the call graph for this function:

Definition at line 290 of file test_inspect.py.

00290 
00291     def test_getmodule_recursion(self):
00292         from types import ModuleType
00293         name = '__inspect_dummy'
00294         m = sys.modules[name] = ModuleType(name)
00295         m.__file__ = "<string>" # hopefully not a real filename...
00296         m.__loader__ = "dummy"  # pretend the filename is understood by a loader
00297         exec("def x(): pass", m.__dict__)
00298         self.assertEqual(inspect.getsourcefile(m.x.__code__), '<string>')
00299         del sys.modules[name]
00300         inspect.getmodule(compile('a=10','','single'))

Here is the call graph for this function:

Definition at line 274 of file test_inspect.py.

00274 
00275     def test_getsource(self):
00276         self.assertSourceEqual(git.abuse, 29, 39)
00277         self.assertSourceEqual(mod.StupidGit, 21, 46)

Here is the call graph for this function:

Definition at line 278 of file test_inspect.py.

00278 
00279     def test_getsourcefile(self):
00280         self.assertEqual(normcase(inspect.getsourcefile(mod.spam)), modfile)
00281         self.assertEqual(normcase(inspect.getsourcefile(git.abuse)), modfile)
00282         fn = "_non_existing_filename_used_for_sourcefile_test.py"
00283         co = compile("None", fn, "exec")
00284         self.assertEqual(inspect.getsourcefile(co), None)
00285         linecache.cache[co.co_filename] = (1, None, "None", co.co_filename)
00286         self.assertEqual(normcase(inspect.getsourcefile(co)), fn)

Here is the call graph for this function:

doctest monkeypatches linecache to enable inspection

Definition at line 301 of file test_inspect.py.

00301 
00302     def test_proceed_with_fake_filename(self):
00303         '''doctest monkeypatches linecache to enable inspection'''
00304         fn, source = '<test>', 'def x(): pass\n'
00305         getlines = linecache.getlines
00306         def monkey(filename, module_globals=None):
00307             if filename == fn:
00308                 return source.splitlines(True)
00309             else:
00310                 return getlines(filename, module_globals)
00311         linecache.getlines = monkey
00312         try:
00313             ns = {}
00314             exec(compile(source, fn, 'single'), ns)
00315             inspect.getsource(ns["x"])
00316         finally:
00317             linecache.getlines = getlines

Here is the call graph for this function:


Member Data Documentation

Reimplemented from test.test_inspect.GetSourceBase.

Definition at line 216 of file test_inspect.py.

Definition at line 205 of file test_inspect.py.


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