Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_pyclbr.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 4ecce8fed6e1 |
| children | 30086aa33123 6768b2350c57 |
| rev | line source |
|---|---|
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 ''' |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 Test cases for pyclbr.py |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 Nick Mathewson |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 ''' |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
24223
diff
changeset
|
5 from test.test_support import run_unittest |
|
45468
1d84bf5f9478
Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents:
44824
diff
changeset
|
6 import sys |
|
33408
078455682875
Teach a test about the different kinds of functions.
Raymond Hettinger <python@rcn.com>
parents:
32949
diff
changeset
|
7 from types import ClassType, FunctionType, MethodType, BuiltinFunctionType |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 import pyclbr |
|
26495
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
9 from unittest import TestCase |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
11 StaticMethodType = type(staticmethod(lambda: None)) |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
12 ClassMethodType = type(classmethod(lambda c: None)) |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
13 |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 # This next line triggers an error on old versions of pyclbr. |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 |
|
19236
38b5906ff031
Repair Unix-specific assumptions that caused this to fail on Windows.
Tim Peters <tim.peters@gmail.com>
parents:
19234
diff
changeset
|
16 from commands import getstatus |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 |
|
19236
38b5906ff031
Repair Unix-specific assumptions that caused this to fail on Windows.
Tim Peters <tim.peters@gmail.com>
parents:
19234
diff
changeset
|
18 # Here we test the python class browser code. |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 # |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 # The main function in this suite, 'testModule', compares the output |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 # of pyclbr with the introspected members of a module. Because pyclbr |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 # is imperfect (as designed), testModule is called with a set of |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 # members to ignore. |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
24 |
|
26495
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
25 class PyclbrTest(TestCase): |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 def assertListEq(self, l1, l2, ignore): |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 ''' succeed iff {l1} - {ignore} == {l2} - {ignore} ''' |
|
30929
54ff68e973ee
* Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents:
28922
diff
changeset
|
29 missing = (set(l1) ^ set(l2)) - set(ignore) |
|
28922
114950ee9aa7
Used sets.Set() to compare unordered sequences.
Raymond Hettinger <python@rcn.com>
parents:
26844
diff
changeset
|
30 if missing: |
|
26508
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
31 print >>sys.stderr, "l1=%r\nl2=%r\nignore=%r" % (l1, l2, ignore) |
|
28922
114950ee9aa7
Used sets.Set() to compare unordered sequences.
Raymond Hettinger <python@rcn.com>
parents:
26844
diff
changeset
|
32 self.fail("%r missing" % missing.pop()) |
|
19236
38b5906ff031
Repair Unix-specific assumptions that caused this to fail on Windows.
Tim Peters <tim.peters@gmail.com>
parents:
19234
diff
changeset
|
33 |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
34 def assertHasattr(self, obj, attr, ignore): |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
35 ''' succeed iff hasattr(obj,attr) or attr in ignore. ''' |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
36 if attr in ignore: return |
|
20213
d053726fb01b
SF patch [#466616] Exclude imported items from doctest,
Tim Peters <tim.peters@gmail.com>
parents:
20013
diff
changeset
|
37 if not hasattr(obj, attr): print "???", attr |
|
24169
c31afea88934
assertHasattr(): Made failure msg better than useless.
Tim Peters <tim.peters@gmail.com>
parents:
23691
diff
changeset
|
38 self.failUnless(hasattr(obj, attr), |
|
c31afea88934
assertHasattr(): Made failure msg better than useless.
Tim Peters <tim.peters@gmail.com>
parents:
23691
diff
changeset
|
39 'expected hasattr(%r, %r)' % (obj, attr)) |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
41 |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
42 def assertHaskey(self, obj, key, ignore): |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
43 ''' succeed iff obj.has_key(key) or key in ignore. ''' |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
44 if key in ignore: return |
|
26495
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
45 if not obj.has_key(key): |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
46 print >>sys.stderr, "***",key |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
47 self.failUnless(obj.has_key(key)) |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
48 |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
49 def assertEqualsOrIgnored(self, a, b, ignore): |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
50 ''' succeed iff a == b or a in ignore or b in ignore ''' |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
51 if a not in ignore and b not in ignore: |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
52 self.assertEquals(a, b) |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
53 |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
54 def checkModule(self, moduleName, module=None, ignore=()): |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
55 ''' succeed iff pyclbr.readmodule_ex(modulename) corresponds |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
56 to the actual module object, module. Any identifiers in |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
57 ignore are ignored. If no module is provided, the appropriate |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
58 module is loaded with __import__.''' |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
59 |
|
46197
01a7e66525c2
#2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents:
45468
diff
changeset
|
60 if module is None: |
|
26495
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
61 # Import it. |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
62 # ('<silly>' is to work around an API silliness in __import__) |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
63 module = __import__(moduleName, globals(), {}, ['<silly>']) |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
64 |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
65 dict = pyclbr.readmodule_ex(moduleName) |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
66 |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
67 def ismethod(oclass, obj, name): |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
68 classdict = oclass.__dict__ |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
69 if isinstance(obj, FunctionType): |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
70 if not isinstance(classdict[name], StaticMethodType): |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
71 return False |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
72 else: |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
73 if not isinstance(obj, MethodType): |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
74 return False |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
75 if obj.im_self is not None: |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
76 if (not isinstance(classdict[name], ClassMethodType) or |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
77 obj.im_self is not oclass): |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
78 return False |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
79 else: |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
80 if not isinstance(classdict[name], FunctionType): |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
81 return False |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
82 |
|
26508
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
83 objname = obj.__name__ |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
84 if objname.startswith("__") and not objname.endswith("__"): |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
85 objname = "_%s%s" % (obj.im_class.__name__, objname) |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
86 return objname == name |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
87 |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
88 # Make sure the toplevel functions and classes are the same. |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
89 for name, value in dict.items(): |
|
19236
38b5906ff031
Repair Unix-specific assumptions that caused this to fail on Windows.
Tim Peters <tim.peters@gmail.com>
parents:
19234
diff
changeset
|
90 if name in ignore: |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
91 continue |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
92 self.assertHasattr(module, name, ignore) |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
93 py_item = getattr(module, name) |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
94 if isinstance(value, pyclbr.Function): |
|
33408
078455682875
Teach a test about the different kinds of functions.
Raymond Hettinger <python@rcn.com>
parents:
32949
diff
changeset
|
95 self.assert_(isinstance(py_item, (FunctionType, BuiltinFunctionType))) |
|
39932
d91826bac655
Bug #1560617: in pyclbr, return full module name not only for classes,
Georg Brandl <georg@python.org>
parents:
37830
diff
changeset
|
96 if py_item.__module__ != moduleName: |
|
d91826bac655
Bug #1560617: in pyclbr, return full module name not only for classes,
Georg Brandl <georg@python.org>
parents:
37830
diff
changeset
|
97 continue # skip functions that came from somewhere else |
|
d91826bac655
Bug #1560617: in pyclbr, return full module name not only for classes,
Georg Brandl <georg@python.org>
parents:
37830
diff
changeset
|
98 self.assertEquals(py_item.__module__, value.module) |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
99 else: |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
100 self.failUnless(isinstance(py_item, (ClassType, type))) |
|
37830
e892b5442835
Whitespace normalization
Neal Norwitz <nnorwitz@gmail.com>
parents:
37823
diff
changeset
|
101 if py_item.__module__ != moduleName: |
|
37823
a5e87987cae6
test_pyclbr goes nuts when a module contains code to try importing a class
Phillip J. Eby <pje@telecommunity.com>
parents:
37078
diff
changeset
|
102 continue # skip classes that came from somewhere else |
|
a5e87987cae6
test_pyclbr goes nuts when a module contains code to try importing a class
Phillip J. Eby <pje@telecommunity.com>
parents:
37078
diff
changeset
|
103 |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
104 real_bases = [base.__name__ for base in py_item.__bases__] |
|
19236
38b5906ff031
Repair Unix-specific assumptions that caused this to fail on Windows.
Tim Peters <tim.peters@gmail.com>
parents:
19234
diff
changeset
|
105 pyclbr_bases = [ getattr(base, 'name', base) |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
106 for base in value.super ] |
|
19236
38b5906ff031
Repair Unix-specific assumptions that caused this to fail on Windows.
Tim Peters <tim.peters@gmail.com>
parents:
19234
diff
changeset
|
107 |
|
26495
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
108 try: |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
109 self.assertListEq(real_bases, pyclbr_bases, ignore) |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
110 except: |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
111 print >>sys.stderr, "class=%s" % py_item |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
112 raise |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
113 |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
114 actualMethods = [] |
|
19670
78cfb993f274
builtin_dir(): Treat classic classes like types. Use PyDict_Keys instead
Tim Peters <tim.peters@gmail.com>
parents:
19236
diff
changeset
|
115 for m in py_item.__dict__.keys(): |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
116 if ismethod(py_item, getattr(py_item, m), m): |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
117 actualMethods.append(m) |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
118 foundMethods = [] |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
119 for m in value.methods.keys(): |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
120 if m[:2] == '__' and m[-2:] != '__': |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
121 foundMethods.append('_'+name+m) |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
122 else: |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
123 foundMethods.append(m) |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
124 |
|
26508
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
125 try: |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
126 self.assertListEq(foundMethods, actualMethods, ignore) |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
127 self.assertEquals(py_item.__module__, value.module) |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
128 |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
129 self.assertEqualsOrIgnored(py_item.__name__, value.name, |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
130 ignore) |
|
26508
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
131 # can't check file or lineno |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
132 except: |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
133 print >>sys.stderr, "class=%s" % py_item |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
134 raise |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
135 |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
136 # Now check for missing stuff. |
|
26495
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
137 def defined_in(item, module): |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
138 if isinstance(item, ClassType): |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
139 return item.__module__ == module.__name__ |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
140 if isinstance(item, FunctionType): |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
141 return item.func_globals is module.__dict__ |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
142 return False |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
143 for name in dir(module): |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
144 item = getattr(module, name) |
|
26495
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
145 if isinstance(item, (ClassType, FunctionType)): |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
146 if defined_in(item, module): |
|
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
147 self.assertHaskey(dict, name, ignore) |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
148 |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
149 def test_easy(self): |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
150 self.checkModule('pyclbr') |
|
26508
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
151 self.checkModule('doctest') |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
152 self.checkModule('rfc822') |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
153 self.checkModule('difflib') |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
154 |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
155 def test_decorators(self): |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
156 # XXX: See comment in pyclbr_input.py for a test that would fail |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
157 # if it were not commented out. |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
158 # |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32726
diff
changeset
|
159 self.checkModule('test.pyclbr_input') |
|
32949
9ebd405683cd
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
32888
diff
changeset
|
160 |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
161 def test_others(self): |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
162 cm = self.checkModule |
|
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
163 |
|
26508
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
164 # These were once about the 10 longest modules |
|
26844
5419ef4a4d70
Last checkin was missing the tuple comma.
Raymond Hettinger <python@rcn.com>
parents:
26843
diff
changeset
|
165 cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator |
|
26508
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
166 cm('cgi', ignore=('log',)) # set with = in module |
|
46969
62658b0aca08
Adapt test_pyclbr to the new version of urllib.py:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46858
diff
changeset
|
167 cm('urllib', ignore=('_CFNumberToInt32', |
|
62658b0aca08
Adapt test_pyclbr to the new version of urllib.py:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46858
diff
changeset
|
168 '_CStringFromCFString', |
|
47167
4ecce8fed6e1
Fix test_pyclbr after another platform-dependent function was added to urllib.
Georg Brandl <georg@python.org>
parents:
46969
diff
changeset
|
169 '_CFSetup', |
|
46969
62658b0aca08
Adapt test_pyclbr to the new version of urllib.py:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46858
diff
changeset
|
170 'getproxies_registry', |
|
44824
84f1a658b231
Fix test_pyclbr after urllib change.
Georg Brandl <georg@python.org>
parents:
39932
diff
changeset
|
171 'proxy_bypass_registry', |
|
46969
62658b0aca08
Adapt test_pyclbr to the new version of urllib.py:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46858
diff
changeset
|
172 'proxy_bypass_macosx_sysconf', |
|
32725
7559c7eb4780
The Darwin-specific getproxies_internetconfig() was added to urllib,
Tim Peters <tim.peters@gmail.com>
parents:
30929
diff
changeset
|
173 'open_https', |
|
46969
62658b0aca08
Adapt test_pyclbr to the new version of urllib.py:
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46858
diff
changeset
|
174 'getproxies_macosx_sysconf', |
|
32725
7559c7eb4780
The Darwin-specific getproxies_internetconfig() was added to urllib,
Tim Peters <tim.peters@gmail.com>
parents:
30929
diff
changeset
|
175 'getproxies_internetconfig',)) # not on all platforms |
|
32726
e4cc78884fc4
Oops! Restored the pickle test to test_pyclbr, but changed types.py so
Tim Peters <tim.peters@gmail.com>
parents:
32725
diff
changeset
|
176 cm('pickle') |
|
26508
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
177 cm('aifc', ignore=('openfp',)) # set with = in module |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
178 cm('Cookie') |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
179 cm('sre_parse', ignore=('dump',)) # from sre_constants import * |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
180 cm('pdb') |
|
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
181 cm('pydoc') |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
182 |
|
26495
5467c6e1f541
Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
183 # Tests for modules inside packages |
|
37078
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
33408
diff
changeset
|
184 cm('email.parser') |
|
26508
e923f6d3b4a3
Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents:
26495
diff
changeset
|
185 cm('test.test_pyclbr') |
|
19234
c3363e4d6d1d
Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
186 |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19670
diff
changeset
|
187 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19670
diff
changeset
|
188 def test_main(): |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19670
diff
changeset
|
189 run_unittest(PyclbrTest) |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19670
diff
changeset
|
190 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19670
diff
changeset
|
191 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19670
diff
changeset
|
192 if __name__ == "__main__": |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
19670
diff
changeset
|
193 test_main() |
