diff options
author | Jason Pellerin <jpellerin@gmail.com> | 2008-03-26 16:45:14 +0000 |
---|---|---|
committer | Jason Pellerin <jpellerin@gmail.com> | 2008-03-26 16:45:14 +0000 |
commit | eb24eab03f96db508c52833df20c83320958cdfc (patch) | |
tree | 95116230b958017cdf25c8e8b4ad0974367f883a | |
parent | b570a203b505ecc3e2e35c3be2f80f2ccf7be607 (diff) | |
download | nose-eb24eab03f96db508c52833df20c83320958cdfc.tar.gz |
Merged 160-jython. Add test.sh shell script to run selftest under python2.3-2.5 and jython. Updated ls_tree and svn:ignore to ignore $py.class files.
-rw-r--r-- | functional_tests/test_program.py | 6 | ||||
-rw-r--r-- | nose/ext/dtcompat.py | 7 | ||||
-rw-r--r-- | nose/plugins/cover.py | 6 | ||||
-rw-r--r-- | nose/plugins/doctests.py | 6 | ||||
-rw-r--r-- | nose/plugins/prof.py | 34 | ||||
-rw-r--r-- | nose/plugins/testid.py | 5 | ||||
-rw-r--r-- | nose/twistedtools.py | 9 | ||||
-rw-r--r-- | nose/util.py | 14 | ||||
-rwxr-xr-x | test.sh | 26 | ||||
-rw-r--r-- | unit_tests/test_plugins.py | 6 | ||||
-rw-r--r-- | unit_tests/test_twisted.py | 7 | ||||
-rw-r--r-- | unit_tests/test_twisted_testcase.py | 6 |
12 files changed, 103 insertions, 29 deletions
diff --git a/functional_tests/test_program.py b/functional_tests/test_program.py index afa72fe..aacdf95 100644 --- a/functional_tests/test_program.py +++ b/functional_tests/test_program.py @@ -1,6 +1,7 @@ import os import unittest from cStringIO import StringIO +from nose import SkipTest from nose.core import TestProgram from nose.config import Config from nose.plugins.manager import DefaultPluginManager @@ -94,6 +95,10 @@ class TestTestProgram(unittest.TestCase): This should collect and run 4 tests with 2 fails and an error. """ + try: + from twisted.trial.unittest import TestCase + except ImportError: + raise SkipTest('twisted not available; skipping') stream = StringIO() runner = TestRunner(stream=stream, verbosity=2) @@ -108,7 +113,6 @@ class TestTestProgram(unittest.TestCase): # some versions of twisted.trial.unittest.TestCase have # runTest in the base class -- this is wrong! But we have # to deal with it - from twisted.trial.unittest import TestCase if hasattr(TestCase, 'runTest'): expect = 5 else: diff --git a/nose/ext/dtcompat.py b/nose/ext/dtcompat.py index 97686d6..831c1a2 100644 --- a/nose/ext/dtcompat.py +++ b/nose/ext/dtcompat.py @@ -10,6 +10,7 @@ # python 2.3: # # - all doctests removed from module (they fail under 2.3 and 2.5) +# - now handles the $py.class extension when ran under Jython r"""Module doctest -- a framework for running examples in docstrings. @@ -970,6 +971,9 @@ class DocTestFinder: filename = getattr(module, '__file__', module.__name__) if filename[-4:] in (".pyc", ".pyo"): filename = filename[:-1] + elif sys.platform.startswith('java') and \ + filename.endswith('$py.class'): + filename = '%s.py' % filename[:-9] return self._parser.get_doctest(docstring, globs, name, filename, lineno) @@ -2060,6 +2064,9 @@ def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None, filename = module.__file__ if filename[-4:] in (".pyc", ".pyo"): filename = filename[:-1] + elif sys.platform.startswith('java') and \ + filename.endswith('$py.class'): + filename = '%s.py' % filename[:-9] test.filename = filename suite.addTest(DocTestCase(test, **options)) diff --git a/nose/plugins/cover.py b/nose/plugins/cover.py index fd9e578..34bfc52 100644 --- a/nose/plugins/cover.py +++ b/nose/plugins/cover.py @@ -14,7 +14,7 @@ import logging import os import sys from nose.plugins.base import Plugin -from nose.util import tolist +from nose.util import src, tolist log = logging.getLogger(__name__) @@ -105,8 +105,8 @@ class Coverage(Plugin): if not hasattr(module, '__file__'): log.debug("no coverage of %s: no __file__", name) return False - root, ext = os.path.splitext(module.__file__) - if not ext in ('.py', '.pyc', '.pyo'): + module_file = src(module.__file__) + if not module_file or not module_file.endswith('.py'): log.debug("no coverage of %s: not a python file", name) return False if self.coverPackages: diff --git a/nose/plugins/doctests.py b/nose/plugins/doctests.py index f282203..f497aea 100644 --- a/nose/plugins/doctests.py +++ b/nose/plugins/doctests.py @@ -23,7 +23,7 @@ import logging import os from inspect import getmodule from nose.plugins.base import Plugin -from nose.util import anyp, getpackage, test_address, resolve_name, tolist +from nose.util import anyp, getpackage, test_address, resolve_name, src, tolist try: from cStringIO import StringIO except ImportError: @@ -113,9 +113,7 @@ class Doctest(Plugin): if not tests: return tests.sort() - module_file = module.__file__ - if module_file[-4:] in ('.pyc', '.pyo'): - module_file = module_file[:-1] + module_file = src(module.__file__) for test in tests: if not test.examples: continue diff --git a/nose/plugins/prof.py b/nose/plugins/prof.py index b272ade..03b5528 100644 --- a/nose/plugins/prof.py +++ b/nose/plugins/prof.py @@ -7,7 +7,11 @@ See the hotshot documentation in the standard library documentation for more details on the various output options. """ -import hotshot, hotshot.stats +try: + import hotshot + from hotshot import stats +except ImportError: + hotshot, stats = None, None import logging import os import sys @@ -24,6 +28,8 @@ class Profile(Plugin): pfile = None clean_stats_file = False def options(self, parser, env=os.environ): + if not self.available(): + return Plugin.options(self, parser, env) parser.add_option('--profile-sort', action='store', dest='profile_sort', default=env.get('NOSE_PROFILE_SORT', 'cumulative'), @@ -38,16 +44,24 @@ class Profile(Plugin): default=env.get('NOSE_PROFILE_RESTRICT'), help="Restrict profiler output. See help for " "pstats.Stats for details") - + + def available(cls): + return hotshot is not None + available = classmethod(available) + def begin(self): + if not self.available(): + return self._create_pfile() self.prof = hotshot.Profile(self.pfile) def configure(self, options, conf): + if not self.available(): + self.enabled = False + return Plugin.configure(self, options, conf) self.options = options self.conf = conf - if options.profile_stats_file: self.pfile = options.profile_stats_file self.clean_stats_file = False @@ -59,6 +73,8 @@ class Profile(Plugin): self.restrict = tolist(options.profile_restrict) def prepareTest(self, test): + if not self.available(): + return log.debug('preparing test %s' % test) def run_and_profile(result, prof=self.prof, test=test): self._create_pfile() @@ -68,15 +84,15 @@ class Profile(Plugin): def report(self, stream): log.debug('printing profiler report') self.prof.close() - stats = hotshot.stats.load(self.pfile) - stats.sort_stats(self.sort) + prof_stats = stats.load(self.pfile) + prof_stats.sort_stats(self.sort) # 2.5 has completely different stream handling from 2.4 and earlier. # Before 2.5, stats objects have no stream attribute; in 2.5 and later # a reference sys.stdout is stored before we can tweak it. compat_25 = hasattr(stats, 'stream') if compat_25: - tmp = stats.stream + tmp = prof_stats.stream stats.stream = stream else: tmp = sys.stdout @@ -84,9 +100,9 @@ class Profile(Plugin): try: if self.restrict: log.debug('setting profiler restriction to %s', self.restrict) - stats.print_stats(*self.restrict) + prof_stats.print_stats(*self.restrict) else: - stats.print_stats() + prof_stats.print_stats() finally: if compat_25: stats.stream = tmp @@ -94,6 +110,8 @@ class Profile(Plugin): sys.stdout = tmp def finalize(self, result): + if not self.available(): + return try: self.prof.close() except AttributeError: diff --git a/nose/plugins/testid.py b/nose/plugins/testid.py index a26a752..c992004 100644 --- a/nose/plugins/testid.py +++ b/nose/plugins/testid.py @@ -37,6 +37,7 @@ __test__ = False import logging import os from nose.plugins import Plugin +from nose.util import src try: from cPickle import dump, load @@ -114,9 +115,7 @@ class TestId(Plugin): log.debug("Make name %s", addr) filename, module, call = addr if filename is not None: - if filename[-4:] in ('.pyc', '.pyo'): - filename = filename[:-1] - head = filename + head = src(filename) else: head = module if call is not None: diff --git a/nose/twistedtools.py b/nose/twistedtools.py index b3c8979..4418bec 100644 --- a/nose/twistedtools.py +++ b/nose/twistedtools.py @@ -28,7 +28,6 @@ Or, more realistically:: import sys from Queue import Queue, Empty - from nose.tools import make_decorator, TimeExpired __all__ = [ @@ -45,7 +44,10 @@ def threaded_reactor(): The thread will automatically be destroyed when all the tests are done. """ global _twisted_thread - from twisted.internet import reactor + try: + from twisted.internet import reactor + except ImportError: + return None, None if not _twisted_thread: from twisted.python import threadable from threading import Thread @@ -110,7 +112,8 @@ def deferred(timeout=None): return reactor.resolve("xxxjhjhj.biz") """ reactor, reactor_thread = threaded_reactor() - + if reactor is None: + raise ImportError("twisted is not available or could not be imported") # Check for common syntax mistake # (otherwise, tests can be silently ignored # if one writes "@deferred" instead of "@deferred()") diff --git a/nose/util.py b/nose/util.py index cb3b376..81f53f8 100644 --- a/nose/util.py +++ b/nose/util.py @@ -15,10 +15,10 @@ log = logging.getLogger('nose') ident_re = re.compile(r'^[A-Za-z_][A-Za-z0-9_.]*$') class_types = (ClassType, TypeType) - +skip_pattern = r"(?:\.svn)|(?:[^.]+\.py[co])|(?:.*~)|(?:.*\$py\.class)" def ls_tree(dir_path="", - skip_pattern=r"(?:\.svn)|(?:[^.]+\.py[co])|(?:.*~)", + skip_pattern=skip_pattern, indent="|-- ", branch_indent="| ", last_indent="`-- ", last_branch_indent=" "): # TODO: empty directories look like non-directory files @@ -196,6 +196,9 @@ def ispackage(path): for init in ('__init__.py', '__init__.pyc', '__init__.pyo'): if os.path.isfile(os.path.join(path, init)): return True + if sys.platform.startswith('java') and \ + os.path.isfile(os.path.join(path, '__init__$py.class')): + return True return False @@ -451,11 +454,14 @@ def try_run(obj, names): def src(filename): - """Find the python source file for a .pyc or .pyo file. Returns the - filename provided if it is not a python source file. + """Find the python source file for a .pyc, .pyo or $py.class file on + jython. Returns the filename provided if it is not a python source + file. """ if filename is None: return filename + if sys.platform.startswith('java') and filename.endswith('$py.class'): + return '.'.join((filename[:-9], 'py')) base, ext = os.path.splitext(filename) if ext in ('.pyc', '.pyo', '.py'): return '.'.join((base, 'py')) @@ -0,0 +1,26 @@ +#!/bin/sh + +echo "python 2.3..." +python2.3 selftest.py + +echo +echo "python 2.4..." +python2.4 selftest.py + +echo +echo "python 2.5..." +python2.5 selftest.py + +if [ "$JYTHONx" != "x" ] +then + echo + echo "jython..." + $JYTHON selftest.py +else + echo + echo '$JYTHON not set' + echo 'set $JYTHON to run selftest under jython' + echo 'example: ' + echo " export JYTHON='java -Dpython.home=<path>/dist/ -jar <path>/dist/jython.jar'" + echo 'see http://wiki.python.org/jython/JythonDeveloperGuide' +fi diff --git a/unit_tests/test_plugins.py b/unit_tests/test_plugins.py index c41f14e..0f2cb0f 100644 --- a/unit_tests/test_plugins.py +++ b/unit_tests/test_plugins.py @@ -7,6 +7,7 @@ from optparse import OptionParser import tempfile from warnings import warn, filterwarnings, resetwarnings +from nose import SkipTest from nose.config import Config from nose.plugins.attrib import AttributeSelector from nose.plugins.base import Plugin @@ -345,6 +346,11 @@ class TestAttribPlugin(unittest.TestCase): class TestProfPlugin(unittest.TestCase): + + def setUp(self): + if not Profile.available(): + raise SkipTest('profile plugin not available; skipping') + def test_options(self): parser = OptionParser() conf = Config() diff --git a/unit_tests/test_twisted.py b/unit_tests/test_twisted.py index e693374..48ca8cd 100644 --- a/unit_tests/test_twisted.py +++ b/unit_tests/test_twisted.py @@ -1,9 +1,12 @@ from nose.exc import SkipTest from nose.tools import * from nose.twistedtools import * +try: + from twisted.internet.defer import Deferred + from twisted.internet.error import DNSLookupError +except ImportError: + raise SkipTest('twisted not available; skipping') -from twisted.internet.defer import Deferred -from twisted.internet.error import DNSLookupError def teardown(): diff --git a/unit_tests/test_twisted_testcase.py b/unit_tests/test_twisted_testcase.py index b389073..850d6e7 100644 --- a/unit_tests/test_twisted_testcase.py +++ b/unit_tests/test_twisted_testcase.py @@ -1,4 +1,8 @@ -from twisted.trial import unittest +try: + from twisted.trial import unittest +except ImportError: + from nose import SkipTest + raise SkipTest('twisted not available; skipping') class TestTwisted(unittest.TestCase): |