blob: 04f22b40cd92cf80412f58b726e22185eb7b530a [file] [log] [blame]
Johannes Gijsberscb9015d2004-12-12 16:20:22 +00001import sys
2import unittest
3import inspect
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +00004
Johannes Gijsberscb9015d2004-12-12 16:20:22 +00005from test.test_support import TESTFN, run_unittest
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +00006
Johannes Gijsberscb9015d2004-12-12 16:20:22 +00007from test import inspect_fodder as mod
8from test import inspect_fodder2 as mod2
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +00009
10# Functions tested in this suite:
11# ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode,
12# isbuiltin, isroutine, getmembers, getdoc, getfile, getmodule,
13# getsourcefile, getcomments, getsource, getclasstree, getargspec,
14# getargvalues, formatargspec, formatargvalues, currentframe, stack, trace
Martin v. Löwise59e2ba2003-05-03 09:09:02 +000015# isdatadescriptor
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000016
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000017modfile = mod.__file__
18if modfile.endswith('c') or modfile.endswith('o'):
19 modfile = modfile[:-1]
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000020
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000021import __builtin__
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000022
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000023try:
24 1/0
25except:
26 tb = sys.exc_traceback
27
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000028git = mod.StupidGit()
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000029
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000030class IsTestBase(unittest.TestCase):
31 predicates = set([inspect.isbuiltin, inspect.isclass, inspect.iscode,
32 inspect.isframe, inspect.isfunction, inspect.ismethod,
33 inspect.ismodule, inspect.istraceback])
34
35 def istest(self, predicate, exp):
36 obj = eval(exp)
37 self.failUnless(predicate(obj), '%s(%s)' % (predicate.__name__, exp))
38
39 for other in self.predicates - set([predicate]):
40 self.failIf(other(obj), 'not %s(%s)' % (other.__name__, exp))
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000041
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000042class TestPredicates(IsTestBase):
43 def test_eleven(self):
44 # Doc/lib/libinspect.tex claims there are 11 such functions
45 count = len(filter(lambda x:x.startswith('is'), dir(inspect)))
46 self.assertEqual(count, 11, "There are %d (not 11) is* functions" % count)
47
48 def test_excluding_predicates(self):
49 self.istest(inspect.isbuiltin, 'sys.exit')
50 self.istest(inspect.isbuiltin, '[].append')
51 self.istest(inspect.isclass, 'mod.StupidGit')
52 self.istest(inspect.iscode, 'mod.spam.func_code')
53 self.istest(inspect.isframe, 'tb.tb_frame')
54 self.istest(inspect.isfunction, 'mod.spam')
55 self.istest(inspect.ismethod, 'mod.StupidGit.abuse')
56 self.istest(inspect.ismethod, 'git.argue')
57 self.istest(inspect.ismodule, 'mod')
58 self.istest(inspect.istraceback, 'tb')
59 self.istest(inspect.isdatadescriptor, '__builtin__.file.closed')
60 self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace')
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000061
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000062 def test_isroutine(self):
63 self.assert_(inspect.isroutine(mod.spam))
64 self.assert_(inspect.isroutine([].count))
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000065
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000066class TestInterpreterStack(IsTestBase):
67 def __init__(self, *args, **kwargs):
68 unittest.TestCase.__init__(self, *args, **kwargs)
69
70 git.abuse(7, 8, 9)
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000071
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000072 def test_abuse_done(self):
73 self.istest(inspect.istraceback, 'git.ex[2]')
74 self.istest(inspect.isframe, 'mod.fr')
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000075
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000076 def test_stack(self):
77 self.assert_(len(mod.st) >= 5)
78 self.assertEqual(mod.st[0][1:],
79 (modfile, 16, 'eggs', [' st = inspect.stack()\n'], 0))
80 self.assertEqual(mod.st[1][1:],
81 (modfile, 9, 'spam', [' eggs(b + d, c + f)\n'], 0))
82 self.assertEqual(mod.st[2][1:],
83 (modfile, 43, 'argue', [' spam(a, b, c)\n'], 0))
84 self.assertEqual(mod.st[3][1:],
85 (modfile, 39, 'abuse', [' self.argue(a, b, c)\n'], 0))
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000086
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000087 def test_trace(self):
88 self.assertEqual(len(git.tr), 3)
89 self.assertEqual(git.tr[0][1:], (modfile, 43, 'argue',
90 [' spam(a, b, c)\n'], 0))
91 self.assertEqual(git.tr[1][1:], (modfile, 9, 'spam',
92 [' eggs(b + d, c + f)\n'], 0))
93 self.assertEqual(git.tr[2][1:], (modfile, 18, 'eggs',
94 [' q = y / 0\n'], 0))
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +000095
Johannes Gijsberscb9015d2004-12-12 16:20:22 +000096 def test_frame(self):
97 args, varargs, varkw, locals = inspect.getargvalues(mod.fr)
98 self.assertEqual(args, ['x', 'y'])
99 self.assertEqual(varargs, None)
100 self.assertEqual(varkw, None)
101 self.assertEqual(locals, {'x': 11, 'p': 11, 'y': 14})
102 self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals),
103 '(x=11, y=14)')
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +0000104
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000105 def test_previous_frame(self):
106 args, varargs, varkw, locals = inspect.getargvalues(mod.fr.f_back)
107 self.assertEqual(args, ['a', 'b', 'c', 'd', ['e', ['f']]])
108 self.assertEqual(varargs, 'g')
109 self.assertEqual(varkw, 'h')
110 self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals),
111 '(a=7, b=8, c=9, d=3, (e=4, (f=5,)), *g=(), **h={})')
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +0000112
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000113class GetSourceBase(unittest.TestCase):
114 # Subclasses must override.
115 fodderFile = None
116
117 def __init__(self, *args, **kwargs):
118 unittest.TestCase.__init__(self, *args, **kwargs)
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +0000119
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000120 self.source = file(inspect.getsourcefile(self.fodderFile)).read()
Ka-Ping Yee6397c7c2001-02-27 14:43:21 +0000121
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000122 def sourcerange(self, top, bottom):
123 lines = self.source.split("\n")
124 return "\n".join(lines[top-1:bottom]) + "\n"
Tim Peterse0b2d7a2001-09-22 06:10:55 +0000125
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000126 def assertSourceEqual(self, obj, top, bottom):
127 self.assertEqual(inspect.getsource(obj),
128 self.sourcerange(top, bottom))
129
130class TestRetrievingSourceCode(GetSourceBase):
131 fodderFile = mod
132
133 def test_getclasses(self):
134 classes = inspect.getmembers(mod, inspect.isclass)
135 self.assertEqual(classes,
136 [('FesteringGob', mod.FesteringGob),
137 ('MalodorousPervert', mod.MalodorousPervert),
138 ('ParrotDroppings', mod.ParrotDroppings),
139 ('StupidGit', mod.StupidGit)])
140 tree = inspect.getclasstree([cls[1] for cls in classes], 1)
141 self.assertEqual(tree,
142 [(mod.ParrotDroppings, ()),
143 (mod.StupidGit, ()),
144 [(mod.MalodorousPervert, (mod.StupidGit,)),
145 [(mod.FesteringGob, (mod.MalodorousPervert,
146 mod.ParrotDroppings))
147 ]
148 ]
149 ])
150
151 def test_getfunctions(self):
152 functions = inspect.getmembers(mod, inspect.isfunction)
153 self.assertEqual(functions, [('eggs', mod.eggs),
154 ('spam', mod.spam)])
Johannes Gijsbersc473c992004-08-18 12:40:31 +0000155
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000156 def test_getdoc(self):
157 self.assertEqual(inspect.getdoc(mod), 'A module docstring.')
158 self.assertEqual(inspect.getdoc(mod.StupidGit),
159 'A longer,\n\nindented\n\ndocstring.')
160 self.assertEqual(inspect.getdoc(git.abuse),
161 'Another\n\ndocstring\n\ncontaining\n\ntabs')
Johannes Gijsbersc473c992004-08-18 12:40:31 +0000162
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000163 def test_getcomments(self):
164 self.assertEqual(inspect.getcomments(mod), '# line 1\n')
165 self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n')
Johannes Gijsbersc473c992004-08-18 12:40:31 +0000166
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000167 def test_getmodule(self):
168 self.assertEqual(inspect.getmodule(mod.StupidGit), mod)
Johannes Gijsbersc473c992004-08-18 12:40:31 +0000169
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000170 def test_getsource(self):
171 self.assertSourceEqual(git.abuse, 29, 39)
172 self.assertSourceEqual(mod.StupidGit, 21, 46)
Johannes Gijsbersc473c992004-08-18 12:40:31 +0000173
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000174 def test_getsourcefile(self):
175 self.assertEqual(inspect.getsourcefile(mod.spam), modfile)
176 self.assertEqual(inspect.getsourcefile(git.abuse), modfile)
Johannes Gijsbersc473c992004-08-18 12:40:31 +0000177
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000178 def test_getfile(self):
179 self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__)
Johannes Gijsbersc473c992004-08-18 12:40:31 +0000180
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000181class TestDecorators(GetSourceBase):
182 fodderFile = mod2
Johannes Gijsbersc473c992004-08-18 12:40:31 +0000183
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000184 def test_wrapped_decorator(self):
185 self.assertSourceEqual(mod2.wrapped, 14, 17)
Johannes Gijsbersc473c992004-08-18 12:40:31 +0000186
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000187 def test_replacing_decorator(self):
188 self.assertSourceEqual(mod2.gone, 9, 10)
Tim Peterse0b2d7a2001-09-22 06:10:55 +0000189
Johannes Gijsbers1542f342004-12-12 16:46:28 +0000190class TestOneliners(GetSourceBase):
191 fodderFile = mod2
192 def test_oneline_lambda(self):
193 # Test inspect.getsource with a one-line lambda function.
194 self.assertSourceEqual(mod2.oll, 25, 25)
195
196 def test_threeline_lambda(self):
197 # Test inspect.getsource with a three-line lambda function,
198 # where the second and third lines are _not_ indented.
199 self.assertSourceEqual(mod2.tll, 28, 30)
200
201 def test_twoline_indented_lambda(self):
202 # Test inspect.getsource with a two-line lambda function,
203 # where the second line _is_ indented.
204 self.assertSourceEqual(mod2.tlli, 33, 34)
205
206 def test_onelinefunc(self):
207 # Test inspect.getsource with a regular one-line function.
208 self.assertSourceEqual(mod2.onelinefunc, 37, 37)
209
210 def test_manyargs(self):
211 # Test inspect.getsource with a regular function where
212 # the arguments are on two lines and _not_ indented and
213 # the body on the second line with the last arguments.
214 self.assertSourceEqual(mod2.manyargs, 40, 41)
215
216 def test_twolinefunc(self):
217 # Test inspect.getsource with a regular function where
218 # the body is on two lines, following the argument list and
219 # continued on the next line by a \\.
220 self.assertSourceEqual(mod2.twolinefunc, 44, 45)
221
222 def test_lambda_in_list(self):
223 # Test inspect.getsource with a one-line lambda function
224 # defined in a list, indented.
225 self.assertSourceEqual(mod2.a[1], 49, 49)
226
227 def test_anonymous(self):
228 # Test inspect.getsource with a lambda function defined
229 # as argument to another function.
230 self.assertSourceEqual(mod2.anonymous, 55, 55)
231
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000232# Helper for testing classify_class_attrs.
Tim Peters13b49d32001-09-23 02:00:29 +0000233def attrs_wo_objs(cls):
234 return [t[:3] for t in inspect.classify_class_attrs(cls)]
235
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000236class TestClassesAndFunctions(unittest.TestCase):
237 def test_classic_mro(self):
238 # Test classic-class method resolution order.
239 class A: pass
240 class B(A): pass
241 class C(A): pass
242 class D(B, C): pass
Tim Peters13b49d32001-09-23 02:00:29 +0000243
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000244 expected = (D, B, A, C)
245 got = inspect.getmro(D)
246 self.assertEqual(expected, got)
Tim Peters13b49d32001-09-23 02:00:29 +0000247
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000248 def test_newstyle_mro(self):
249 # The same w/ new-class MRO.
250 class A(object): pass
251 class B(A): pass
252 class C(A): pass
253 class D(B, C): pass
Tim Peters13b49d32001-09-23 02:00:29 +0000254
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000255 expected = (D, B, C, A, object)
256 got = inspect.getmro(D)
257 self.assertEqual(expected, got)
Tim Peters13b49d32001-09-23 02:00:29 +0000258
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000259 def assertArgSpecEquals(self, routine, args_e, varargs_e = None,
260 varkw_e = None, defaults_e = None,
261 formatted = None):
262 args, varargs, varkw, defaults = inspect.getargspec(routine)
263 self.assertEqual(args, args_e)
264 self.assertEqual(varargs, varargs_e)
265 self.assertEqual(varkw, varkw_e)
266 self.assertEqual(defaults, defaults_e)
267 if formatted is not None:
268 self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults),
269 formatted)
Tim Peters13b49d32001-09-23 02:00:29 +0000270
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000271 def test_getargspec(self):
272 self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted = '(x, y)')
Tim Peters13b49d32001-09-23 02:00:29 +0000273
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000274 self.assertArgSpecEquals(mod.spam,
275 ['a', 'b', 'c', 'd', ['e', ['f']]],
276 'g', 'h', (3, (4, (5,))),
277 '(a, b, c, d=3, (e, (f,))=(4, (5,)), *g, **h)')
Tim Peters13b49d32001-09-23 02:00:29 +0000278
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000279 def test_getargspec_method(self):
280 class A(object):
281 def m(self):
282 pass
283 self.assertArgSpecEquals(A.m, ['self'])
Tim Peters13b49d32001-09-23 02:00:29 +0000284
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000285 def test_getargspec_sublistofone(self):
286 def sublistOfOne((foo)): return 1
287
288 self.assertArgSpecEquals(sublistOfOne, [['foo']])
289
290 def test_classify_oldstyle(self):
291 class A:
292 def s(): pass
293 s = staticmethod(s)
294
295 def c(cls): pass
296 c = classmethod(c)
297
298 def getp(self): pass
299 p = property(getp)
300
301 def m(self): pass
302
303 def m1(self): pass
304
305 datablob = '1'
306
307 attrs = attrs_wo_objs(A)
308 self.assert_(('s', 'static method', A) in attrs, 'missing static method')
309 self.assert_(('c', 'class method', A) in attrs, 'missing class method')
310 self.assert_(('p', 'property', A) in attrs, 'missing property')
311 self.assert_(('m', 'method', A) in attrs, 'missing plain method')
312 self.assert_(('m1', 'method', A) in attrs, 'missing plain method')
313 self.assert_(('datablob', 'data', A) in attrs, 'missing data')
314
315 class B(A):
316 def m(self): pass
317
318 attrs = attrs_wo_objs(B)
319 self.assert_(('s', 'static method', A) in attrs, 'missing static method')
320 self.assert_(('c', 'class method', A) in attrs, 'missing class method')
321 self.assert_(('p', 'property', A) in attrs, 'missing property')
322 self.assert_(('m', 'method', B) in attrs, 'missing plain method')
323 self.assert_(('m1', 'method', A) in attrs, 'missing plain method')
324 self.assert_(('datablob', 'data', A) in attrs, 'missing data')
Tim Peters13b49d32001-09-23 02:00:29 +0000325
326
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000327 class C(A):
328 def m(self): pass
329 def c(self): pass
Tim Peters13b49d32001-09-23 02:00:29 +0000330
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000331 attrs = attrs_wo_objs(C)
332 self.assert_(('s', 'static method', A) in attrs, 'missing static method')
333 self.assert_(('c', 'method', C) in attrs, 'missing plain method')
334 self.assert_(('p', 'property', A) in attrs, 'missing property')
335 self.assert_(('m', 'method', C) in attrs, 'missing plain method')
336 self.assert_(('m1', 'method', A) in attrs, 'missing plain method')
337 self.assert_(('datablob', 'data', A) in attrs, 'missing data')
Tim Peters13b49d32001-09-23 02:00:29 +0000338
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000339 class D(B, C):
340 def m1(self): pass
Tim Peters13b49d32001-09-23 02:00:29 +0000341
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000342 attrs = attrs_wo_objs(D)
343 self.assert_(('s', 'static method', A) in attrs, 'missing static method')
344 self.assert_(('c', 'class method', A) in attrs, 'missing class method')
345 self.assert_(('p', 'property', A) in attrs, 'missing property')
346 self.assert_(('m', 'method', B) in attrs, 'missing plain method')
347 self.assert_(('m1', 'method', D) in attrs, 'missing plain method')
348 self.assert_(('datablob', 'data', A) in attrs, 'missing data')
Tim Peters13b49d32001-09-23 02:00:29 +0000349
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000350 # Repeat all that, but w/ new-style classes.
351 def test_classify_newstyle(self):
352 class A(object):
Tim Peters13b49d32001-09-23 02:00:29 +0000353
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000354 def s(): pass
355 s = staticmethod(s)
Tim Peters13b49d32001-09-23 02:00:29 +0000356
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000357 def c(cls): pass
358 c = classmethod(c)
Tim Peters13b49d32001-09-23 02:00:29 +0000359
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000360 def getp(self): pass
361 p = property(getp)
Tim Peters13b49d32001-09-23 02:00:29 +0000362
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000363 def m(self): pass
Tim Peters13b49d32001-09-23 02:00:29 +0000364
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000365 def m1(self): pass
Tim Peters13b49d32001-09-23 02:00:29 +0000366
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000367 datablob = '1'
Tim Peters13b49d32001-09-23 02:00:29 +0000368
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000369 attrs = attrs_wo_objs(A)
370 self.assert_(('s', 'static method', A) in attrs, 'missing static method')
371 self.assert_(('c', 'class method', A) in attrs, 'missing class method')
372 self.assert_(('p', 'property', A) in attrs, 'missing property')
373 self.assert_(('m', 'method', A) in attrs, 'missing plain method')
374 self.assert_(('m1', 'method', A) in attrs, 'missing plain method')
375 self.assert_(('datablob', 'data', A) in attrs, 'missing data')
Tim Peters13b49d32001-09-23 02:00:29 +0000376
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000377 class B(A):
Tim Peters13b49d32001-09-23 02:00:29 +0000378
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000379 def m(self): pass
Tim Peters13b49d32001-09-23 02:00:29 +0000380
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000381 attrs = attrs_wo_objs(B)
382 self.assert_(('s', 'static method', A) in attrs, 'missing static method')
383 self.assert_(('c', 'class method', A) in attrs, 'missing class method')
384 self.assert_(('p', 'property', A) in attrs, 'missing property')
385 self.assert_(('m', 'method', B) in attrs, 'missing plain method')
386 self.assert_(('m1', 'method', A) in attrs, 'missing plain method')
387 self.assert_(('datablob', 'data', A) in attrs, 'missing data')
Tim Peters13b49d32001-09-23 02:00:29 +0000388
389
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000390 class C(A):
Tim Peters13b49d32001-09-23 02:00:29 +0000391
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000392 def m(self): pass
393 def c(self): pass
Tim Peters13b49d32001-09-23 02:00:29 +0000394
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000395 attrs = attrs_wo_objs(C)
396 self.assert_(('s', 'static method', A) in attrs, 'missing static method')
397 self.assert_(('c', 'method', C) in attrs, 'missing plain method')
398 self.assert_(('p', 'property', A) in attrs, 'missing property')
399 self.assert_(('m', 'method', C) in attrs, 'missing plain method')
400 self.assert_(('m1', 'method', A) in attrs, 'missing plain method')
401 self.assert_(('datablob', 'data', A) in attrs, 'missing data')
Tim Peters13b49d32001-09-23 02:00:29 +0000402
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000403 class D(B, C):
Tim Peters13b49d32001-09-23 02:00:29 +0000404
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000405 def m1(self): pass
Tim Peters13b49d32001-09-23 02:00:29 +0000406
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000407 attrs = attrs_wo_objs(D)
408 self.assert_(('s', 'static method', A) in attrs, 'missing static method')
409 self.assert_(('c', 'method', C) in attrs, 'missing plain method')
410 self.assert_(('p', 'property', A) in attrs, 'missing property')
411 self.assert_(('m', 'method', B) in attrs, 'missing plain method')
412 self.assert_(('m1', 'method', D) in attrs, 'missing plain method')
413 self.assert_(('datablob', 'data', A) in attrs, 'missing data')
Jeremy Hyltonc4bf5ed2003-06-27 18:43:12 +0000414
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000415def test_main():
Johannes Gijsbers1542f342004-12-12 16:46:28 +0000416 run_unittest(TestDecorators, TestRetrievingSourceCode, TestOneliners,
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000417 TestInterpreterStack, TestClassesAndFunctions, TestPredicates)
Martin v. Löwis893ffa42003-10-31 15:35:53 +0000418
Johannes Gijsberscb9015d2004-12-12 16:20:22 +0000419if __name__ == "__main__":
420 test_main()
421