annotate Lib/test/test_pyclbr.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 2d2079593212
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 '''
63531
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
5 from test.test_support import run_unittest, import_module
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
63531
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
14 # Silence Py3k warning
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
15 import_module('commands', deprecated=True)
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
16
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 # This next line triggers an error on old versions of pyclbr.
19236
38b5906ff031 Repair Unix-specific assumptions that caused this to fail on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 19234
diff changeset
18 from commands import getstatus
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19
19236
38b5906ff031 Repair Unix-specific assumptions that caused this to fail on Windows.
Tim Peters <tim.peters@gmail.com>
parents: 19234
diff changeset
20 # 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
21 #
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 # 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
23 # 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
24 # 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
25 # members to ignore.
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26
26495
5467c6e1f541 Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
27 class PyclbrTest(TestCase):
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 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
30 ''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
30929
54ff68e973ee * Migrate set() and frozenset() from the sandbox.
Raymond Hettinger <python@rcn.com>
parents: 28922
diff changeset
31 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
32 if missing:
26508
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
33 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
34 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
35
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 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
37 ''' 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
38 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
39 if not hasattr(obj, attr): print "???", attr
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 47167
diff changeset
40 self.assertTrue(hasattr(obj, attr),
24169
c31afea88934 assertHasattr(): Made failure msg better than useless.
Tim Peters <tim.peters@gmail.com>
parents: 23691
diff changeset
41 '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
42
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44 def assertHaskey(self, obj, key, ignore):
63531
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
45 ''' succeed iff key in obj or key in ignore. '''
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46 if key in ignore: return
63531
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
47 if key not in obj:
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
48 print >>sys.stderr, "***", key
58580
bfc13ce62fab #7092: silence py3k warnings for deprecated modules
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58472
diff changeset
49 self.assertIn(key, obj)
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
51 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
52 ''' 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
53 if a not in ignore and b not in ignore:
63531
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
54 self.assertEqual(a, b)
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
55
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
56 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
57 ''' 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
58 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
59 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
60 module is loaded with __import__.'''
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
61
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 45468
diff changeset
62 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
63 # Import it.
5467c6e1f541 Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
64 # ('<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
65 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
66
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67 dict = pyclbr.readmodule_ex(moduleName)
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
69 def ismethod(oclass, obj, name):
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
70 classdict = oclass.__dict__
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
71 if isinstance(obj, FunctionType):
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
72 if not isinstance(classdict[name], StaticMethodType):
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
73 return False
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
74 else:
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
75 if not isinstance(obj, MethodType):
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
76 return False
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
77 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
78 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
79 obj.im_self is not oclass):
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
80 return False
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
81 else:
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
82 if not isinstance(classdict[name], FunctionType):
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
83 return False
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
84
26508
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
85 objname = obj.__name__
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
86 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
87 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
88 return objname == name
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
89
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
90 # 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
91 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
92 if name in ignore:
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
93 continue
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
94 self.assertHasattr(module, name, ignore)
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
95 py_item = getattr(module, name)
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
96 if isinstance(value, pyclbr.Function):
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
97 self.assertIsInstance(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
98 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
99 continue # skip functions that came from somewhere else
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58580
diff changeset
100 self.assertEqual(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
101 else:
58472
6ffcdafa0118 use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58198
diff changeset
102 self.assertIsInstance(py_item, (ClassType, type))
37830
e892b5442835 Whitespace normalization
Neal Norwitz <nnorwitz@gmail.com>
parents: 37823
diff changeset
103 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
104 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
105
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
106 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
107 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
108 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
109
26495
5467c6e1f541 Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
110 try:
5467c6e1f541 Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
111 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
112 except:
5467c6e1f541 Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
113 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
114 raise
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
115
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
116 actualMethods = []
19670
78cfb993f274 builtin_dir(): Treat classic classes like types. Use PyDict_Keys instead
Tim Peters <tim.peters@gmail.com>
parents: 19236
diff changeset
117 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
118 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
119 actualMethods.append(m)
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
120 foundMethods = []
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
121 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
122 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
123 foundMethods.append('_'+name+m)
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
124 else:
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
125 foundMethods.append(m)
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
126
26508
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
127 try:
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
128 self.assertListEq(foundMethods, actualMethods, ignore)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58580
diff changeset
129 self.assertEqual(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
130
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
131 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
132 ignore)
26508
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
133 # 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
134 except:
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
135 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
136 raise
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
137
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
138 # 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
139 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
140 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
141 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
142 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
143 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
144 return False
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
145 for name in dir(module):
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
146 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
147 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
148 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
149 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
150
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
151 def test_easy(self):
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
152 self.checkModule('pyclbr')
55340
f311395487c9 split unittest.py into a package
Benjamin Peterson <benjamin@python.org>
parents: 55002
diff changeset
153 self.checkModule('doctest', ignore=("DocTestCase",))
63531
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
154 # Silence Py3k warning
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
155 rfc822 = import_module('rfc822', deprecated=True)
30086aa33123 Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 47167
diff changeset
156 self.checkModule('rfc822', rfc822)
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
157 self.checkModule('difflib')
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
158
32888
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
159 def test_decorators(self):
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
160 # 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
161 # if it were not commented out.
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
162 #
c7e03cf8333e PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents: 32726
diff changeset
163 self.checkModule('test.pyclbr_input')
32949
9ebd405683cd Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 32888
diff changeset
164
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
165 def test_others(self):
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
166 cm = self.checkModule
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
167
26508
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
168 # 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
169 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
170 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
171 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
172 '_CStringFromCFString',
47167
4ecce8fed6e1 Fix test_pyclbr after another platform-dependent function was added to urllib.
Georg Brandl <georg@python.org>
parents: 46969
diff changeset
173 '_CFSetup',
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_registry',
44824
84f1a658b231 Fix test_pyclbr after urllib change.
Georg Brandl <georg@python.org>
parents: 39932
diff changeset
175 '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
176 '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
177 '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
178 'getproxies_macosx_sysconf',
32725
7559c7eb4780 The Darwin-specific getproxies_internetconfig() was added to urllib,
Tim Peters <tim.peters@gmail.com>
parents: 30929
diff changeset
179 '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
180 cm('pickle')
26508
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
181 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
182 cm('Cookie')
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
183 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
184 cm('pdb')
e923f6d3b4a3 Add more sophistication to the comparison between pyclbr output and
Guido van Rossum <guido@python.org>
parents: 26495
diff changeset
185 cm('pydoc')
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
186
26495
5467c6e1f541 Moderately heavy reorganization of pyclbr to fix package-related bugs.
Guido van Rossum <guido@python.org>
parents: 24364
diff changeset
187 # 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
188 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
189 cm('test.test_pyclbr')
19234
c3363e4d6d1d Nick Mathewson: test suite for the class browser support module.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
190
77041
2d2079593212 #14798: pyclbr now raises ImportError instead of KeyError for missing packages
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
191 def test_issue_14798(self):
2d2079593212 #14798: pyclbr now raises ImportError instead of KeyError for missing packages
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
192 # test ImportError is raised when the first part of a dotted name is
2d2079593212 #14798: pyclbr now raises ImportError instead of KeyError for missing packages
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
193 # not a package
2d2079593212 #14798: pyclbr now raises ImportError instead of KeyError for missing packages
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
194 self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo')
2d2079593212 #14798: pyclbr now raises ImportError instead of KeyError for missing packages
Petri Lehtinen <petri@digip.org>
parents: 68256
diff changeset
195
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19670
diff changeset
196
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19670
diff changeset
197 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
198 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
199
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19670
diff changeset
200
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19670
diff changeset
201 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
202 test_main()