Lines Matching refs:inspect
5 import inspect
46 predicates = set([inspect.isbuiltin, inspect.isclass, inspect.iscode,
47 inspect.isframe, inspect.isfunction, inspect.ismethod,
48 inspect.ismodule, inspect.istraceback,
49 inspect.isgenerator, inspect.isgeneratorfunction])
56 if predicate == inspect.isgeneratorfunction and\
57 other == inspect.isfunction:
67 count = len(filter(lambda x:x.startswith('is'), dir(inspect)))
68 # This test is here for remember you to update Doc/library/inspect.rst
76 self.istest(inspect.isbuiltin, 'sys.exit')
77 self.istest(inspect.isbuiltin, '[].append')
78 self.istest(inspect.iscode, 'mod.spam.func_code')
79 self.istest(inspect.isframe, 'tb.tb_frame')
80 self.istest(inspect.isfunction, 'mod.spam')
81 self.istest(inspect.ismethod, 'mod.StupidGit.abuse')
82 self.istest(inspect.ismethod, 'git.argue')
83 self.istest(inspect.ismodule, 'mod')
84 self.istest(inspect.istraceback, 'tb')
85 self.istest(inspect.isdatadescriptor, '__builtin__.file.closed')
86 self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace')
87 self.istest(inspect.isgenerator, '(x for x in xrange(2))')
88 self.istest(inspect.isgeneratorfunction, 'generator_function_example')
90 self.istest(inspect.isgetsetdescriptor,
93 self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals))
95 self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days')
97 self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
100 self.assertTrue(inspect.isroutine(mod.spam))
101 self.assertTrue(inspect.isroutine([].count))
104 self.istest(inspect.isclass, 'mod.StupidGit')
105 self.assertTrue(inspect.isclass(list))
108 self.assertTrue(inspect.isclass(newstyle))
113 self.assertFalse(inspect.isclass(CustomGetattr()))
121 members = dict(inspect.getmembers(x))
142 self.assertTrue(inspect.isabstract(AbstractClassExample))
143 self.assertFalse(inspect.isabstract(ClassExample))
144 self.assertFalse(inspect.isabstract(a))
145 self.assertFalse(inspect.isabstract(int))
146 self.assertFalse(inspect.isabstract(5))
156 self.istest(inspect.istraceback, 'git.ex[2]')
157 self.istest(inspect.isframe, 'mod.fr')
162 (modfile, 16, 'eggs', [' st = inspect.stack()\n'], 0))
180 args, varargs, varkw, locals = inspect.getargvalues(mod.fr)
185 self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals),
189 args, varargs, varkw, locals = inspect.getargvalues(mod.fr.f_back)
193 self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals),
203 with open(inspect.getsourcefile(self.fodderFile)) as fp:
211 self.assertEqual(inspect.getsource(obj),
218 classes = inspect.getmembers(mod, inspect.isclass)
224 tree = inspect.getclasstree([cls[1] for cls in classes], 1)
236 functions = inspect.getmembers(mod, inspect.isfunction)
243 self.assertEqual(inspect.getdoc(mod), 'A module docstring.')
244 self.assertEqual(inspect.getdoc(mod.StupidGit),
246 self.assertEqual(inspect.getdoc(git.abuse),
250 self.assertEqual(inspect.cleandoc('An\n indented\n docstring.'),
254 self.assertEqual(inspect.getcomments(mod), '# line 1\n')
255 self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n')
259 self.assertEqual(inspect.getmodule(mod), mod)
261 self.assertEqual(inspect.getmodule(mod.StupidGit), mod)
263 self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod)
265 self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod)
267 self.assertEqual(inspect.getmodule(str), sys.modules["__builtin__"])
269 self.assertEqual(inspect.getmodule(None, modfile), mod)
276 self.assertEqual(inspect.getsourcefile(mod.spam), modfile)
277 self.assertEqual(inspect.getsourcefile(git.abuse), modfile)
280 self.assertEqual(inspect.getsourcefile(co), None)
282 self.assertEqual(inspect.getsourcefile(co), fn)
285 self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__)
294 self.assertEqual(inspect.getsourcefile(m.x.func_code), '<string>')
296 inspect.getmodule(compile('a=10','','single'))
311 inspect.getsource(ns["x"])
327 # Test inspect.getsource with a one-line lambda function.
331 # Test inspect.getsource with a three-line lambda function,
336 # Test inspect.getsource with a two-line lambda function,
341 # Test inspect.getsource with a regular one-line function.
345 # Test inspect.getsource with a regular function where
351 # Test inspect.getsource with a regular function where
357 # Test inspect.getsource with a one-line lambda function
362 # Test inspect.getsource with a lambda function defined
395 self.assertRaises(IOError, inspect.getsource, unicodedata)
396 self.assertRaises(IOError, inspect.findsource, unicodedata)
401 self.assertRaises(IOError, inspect.findsource, co)
402 self.assertRaises(IOError, inspect.getsource, co)
404 self.assertEqual(inspect.findsource(co), (lines,0))
405 self.assertEqual(inspect.getsource(co), lines[0])
410 self.assertRaises(IOError, inspect.findsource, co)
411 self.assertRaises(IOError, inspect.getsource, co)
441 return [t[:3] for t in inspect.classify_class_attrs(cls)]
453 got = inspect.getmro(D)
464 got = inspect.getmro(D)
470 args, varargs, varkw, defaults = inspect.getargspec(routine)
476 self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
607 inspect.classify_class_attrs(builtin)
615 self.assertIn(('f', B.f), inspect.getmembers(B))
618 self.assertIn(('f', B.f), inspect.getmembers(B, inspect.ismethod))
620 self.assertIn(('f', b.f), inspect.getmembers(b))
621 self.assertIn(('f', b.f), inspect.getmembers(b, inspect.ismethod))
628 self.assertIn(('f', B.f), inspect.getmembers(B))
629 self.assertIn(('f', B.f), inspect.getmembers(B, inspect.ismethod))
631 self.assertIn(('f', b.f), inspect.getmembers(b))
632 self.assertIn(('f', b.f), inspect.getmembers(b, inspect.ismethod))
643 r2 = eval('inspect.getcallargs(func, %s)' % call_params_string, None,
656 eval('inspect.getcallargs(func, %s)' % call_param_string, None,