diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-06-20 22:55:16 +0100 |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-06-20 22:55:16 +0100 |
commit | 58a658b26d1c95b31d02050dcccd648d2e4ce27b (patch) | |
tree | b9d3e7de6f6d23b91a7afecde3491e99d8cc7069 /setuptools/tests/doctest.py | |
parent | e63f3e7d864b26529d6b197e053b4084be20decf (diff) | |
download | external_python_setuptools-58a658b26d1c95b31d02050dcccd648d2e4ce27b.tar.gz external_python_setuptools-58a658b26d1c95b31d02050dcccd648d2e4ce27b.tar.bz2 external_python_setuptools-58a658b26d1c95b31d02050dcccd648d2e4ce27b.zip |
Changes to support 2.x and 3.x in the same codebase.
--HG--
branch : distribute
extra : rebase_source : 7d3608edee54a43789f0574d702fb839628b5071
Diffstat (limited to 'setuptools/tests/doctest.py')
-rw-r--r-- | setuptools/tests/doctest.py | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/setuptools/tests/doctest.py b/setuptools/tests/doctest.py index be399a9d..1f23fd8e 100644 --- a/setuptools/tests/doctest.py +++ b/setuptools/tests/doctest.py @@ -9,7 +9,7 @@ try: basestring except NameError: - basestring = str,unicode + basestring = str try: enumerate @@ -109,7 +109,7 @@ import __future__ import sys, traceback, inspect, linecache, os, re, types import unittest, difflib, pdb, tempfile import warnings -from StringIO import StringIO +from setuptools.compat import StringIO, execfile, exec_, func_code, im_func # Don't whine about the deprecated is_private function in this # module's tests. @@ -240,7 +240,7 @@ def _normalize_module(module, depth=2): """ if inspect.ismodule(module): return module - elif isinstance(module, (str, unicode)): + elif isinstance(module, basestring): return __import__(module, globals(), locals(), ["*"]) elif module is None: return sys.modules[sys._getframe(depth).f_globals['__name__']] @@ -367,9 +367,9 @@ class _OutputRedirectingPdb(pdb.Pdb): # [XX] Normalize with respect to os.path.pardir? def _module_relative_path(module, path): if not inspect.ismodule(module): - raise TypeError, 'Expected a module: %r' % module + raise TypeError('Expected a module: %r' % module) if path.startswith('/'): - raise ValueError, 'Module-relative files may not have absolute paths' + raise ValueError('Module-relative files may not have absolute paths') # Find the base directory for the path. if hasattr(module, '__file__'): @@ -877,7 +877,7 @@ class DocTestFinder: if module is None: return True elif inspect.isfunction(object): - return module.__dict__ is object.func_globals + return module.__dict__ is func_globals(object) elif inspect.isclass(object): return module.__name__ == object.__module__ elif inspect.getmodule(object) is not None: @@ -895,7 +895,7 @@ class DocTestFinder: add them to `tests`. """ if self._verbose: - print 'Finding tests in %s' % name + print('Finding tests in %s' % name) # If we've already processed this object, then ignore it. if id(obj) in seen: @@ -948,7 +948,7 @@ class DocTestFinder: if isinstance(val, staticmethod): val = getattr(obj, valname) if isinstance(val, classmethod): - val = getattr(obj, valname).im_func + val = im_func(getattr(obj, valname)) # Recurse to methods, properties, and nested classes. if ((inspect.isfunction(val) or inspect.isclass(val) or @@ -1020,8 +1020,8 @@ class DocTestFinder: break # Find the line number for functions & methods. - if inspect.ismethod(obj): obj = obj.im_func - if inspect.isfunction(obj): obj = obj.func_code + if inspect.ismethod(obj): obj = im_func(obj) + if inspect.isfunction(obj): obj = func_code(obj) if inspect.istraceback(obj): obj = obj.tb_frame if inspect.isframe(obj): obj = obj.f_code if inspect.iscode(obj): @@ -1250,8 +1250,8 @@ class DocTestRunner: # keyboard interrupts.) try: # Don't blink! This is where the user's code gets run. - exec compile(example.source, filename, "single", - compileflags, 1) in test.globs + exec_(compile(example.source, filename, "single", + compileflags, 1), test.globs) self.debugger.set_continue() # ==== Example Finished ==== exception = None except KeyboardInterrupt: @@ -1335,7 +1335,7 @@ class DocTestRunner: if m and m.group('name') == self.test.name: example = self.test.examples[int(m.group('examplenum'))] return example.source.splitlines(True) - elif self.save_linecache_getlines.func_code.co_argcount>1: + elif func_code(self.save_linecache_getlines).co_argcount > 1: return self.save_linecache_getlines(filename, module_globals) else: return self.save_linecache_getlines(filename) @@ -1427,28 +1427,28 @@ class DocTestRunner: failed.append(x) if verbose: if notests: - print len(notests), "items had no tests:" + print(len(notests), "items had no tests:") notests.sort() for thing in notests: - print " ", thing + print(" ", thing) if passed: - print len(passed), "items passed all tests:" + print(len(passed), "items passed all tests:") passed.sort() for thing, count in passed: - print " %3d tests in %s" % (count, thing) + print(" %3d tests in %s" % (count, thing)) if failed: - print self.DIVIDER - print len(failed), "items had failures:" + print(self.DIVIDER) + print(len(failed), "items had failures:") failed.sort() for thing, (f, t) in failed: - print " %3d of %3d in %s" % (f, t, thing) + print(" %3d of %3d in %s" % (f, t, thing)) if verbose: - print totalt, "tests in", len(self._name2ft), "items." - print totalt - totalf, "passed and", totalf, "failed." + print(totalt, "tests in", len(self._name2ft), "items.") + print(totalt - totalf, "passed and", totalf, "failed.") if totalf: - print "***Test Failed***", totalf, "failures." + print("***Test Failed***", totalf, "failures.") elif verbose: - print "Test passed." + print("Test passed.") return totalf, totalt #///////////////////////////////////////////////////////////////// @@ -1458,8 +1458,8 @@ class DocTestRunner: d = self._name2ft for name, (f, t) in other._name2ft.items(): if name in d: - print "*** DocTestRunner.merge: '" + name + "' in both" \ - " testers; summing outcomes." + print("*** DocTestRunner.merge: '" + name + "' in both" \ + " testers; summing outcomes.") f2, t2 = d[name] f = f + f2 t = t + t2 @@ -2037,10 +2037,10 @@ class Tester: def runstring(self, s, name): test = DocTestParser().get_doctest(s, self.globs, name, None, None) if self.verbose: - print "Running string", name + print("Running string", name) (f,t) = self.testrunner.run(test) if self.verbose: - print f, "of", t, "examples failed in string", name + print(f, "of", t, "examples failed in string", name) return (f,t) def rundoc(self, object, name=None, module=None): @@ -2552,7 +2552,7 @@ def debug_script(src, pm=False, globs=None): try: execfile(srcfilename, globs, globs) except: - print sys.exc_info()[1] + print(sys.exc_info()[1]) pdb.post_mortem(sys.exc_info()[2]) else: # Note that %r is vital here. '%s' instead can, e.g., cause |