diff --git a/py/_cmdline/pyconvert_unittest.py b/py/_cmdline/pyconvert_unittest.py index a975a478e..a50233638 100644 --- a/py/_cmdline/pyconvert_unittest.py +++ b/py/_cmdline/pyconvert_unittest.py @@ -1,6 +1,10 @@ import re import sys -import parser + +try: + import parser +except ImportError: + parser = None d={} # d is the dictionary of unittest changes, keyed to the old name diff --git a/py/_code/code.py b/py/_code/code.py index 397398029..ee054fc2e 100644 --- a/py/_code/code.py +++ b/py/_code/code.py @@ -523,7 +523,8 @@ class FormattedExcinfo(object): source = py.code.Source("???") line_index = 0 else: - line_index = entry.lineno - entry.getfirstlinesource() + # entry.getfirstlinesource() can be -1, should be 0 on jython + line_index = entry.lineno - max(entry.getfirstlinesource(), 0) lines = [] if self.style == "long": diff --git a/testing/cmdline/test_convert_unittest.py b/testing/cmdline/test_convert_unittest.py index 48280c7c1..2bfcd9c2b 100644 --- a/testing/cmdline/test_convert_unittest.py +++ b/testing/cmdline/test_convert_unittest.py @@ -1,3 +1,5 @@ +import py +py.test.importorskip("parser") from py._cmdline.pyconvert_unittest import rewrite_utest diff --git a/testing/path/common.py b/testing/path/common.py index 3b0d48c19..8e83e45f6 100644 --- a/testing/path/common.py +++ b/testing/path/common.py @@ -132,7 +132,7 @@ class CommonFSTests(object): assert not l1.relto(l2) assert not l2.relto(l1) - #@py.test.mark.xfail("sys.platform.startswith('java')") + @py.test.mark.xfail("sys.platform.startswith('java')") def test_listdir(self, path1): l = path1.listdir() assert path1.join('sampledir') in l @@ -178,7 +178,7 @@ class CommonFSTests(object): assert "sampledir" in l assert "otherdir" in l - #@py.test.mark.xfail("sys.platform.startswith('java')") + @py.test.mark.xfail("sys.platform.startswith('java')") def test_visit_ignore(self, path1): p = path1.join('nonexisting') assert list(p.visit(ignore=py.error.ENOENT)) == [] diff --git a/testing/path/test_svnurl.py b/testing/path/test_svnurl.py index 82dce22d4..e6e226661 100644 --- a/testing/path/test_svnurl.py +++ b/testing/path/test_svnurl.py @@ -13,6 +13,12 @@ class TestSvnURLCommandPath(CommonSvnTests): def test_load(self, path1): super(TestSvnURLCommandPath, self).test_load(path1) + # the following two work on jython but not in local/svnwc + def test_listdir(self, path1): + super(TestSvnURLCommandPath, self).test_listdir(path1) + def test_visit_ignore(self, path1): + super(TestSvnURLCommandPath, self).test_visit_ignore(path1) + def test_svnurl_needs_arg(self, path1): py.test.raises(TypeError, "py.path.svnurl()") diff --git a/testing/plugin/test_pytest__pytest.py b/testing/plugin/test_pytest__pytest.py index 182efe564..4eb7beac1 100644 --- a/testing/plugin/test_pytest__pytest.py +++ b/testing/plugin/test_pytest__pytest.py @@ -1,5 +1,5 @@ import py -import sys +import os, sys from py._plugin.pytest__pytest import HookRecorder from py._test.pluginmanager import Registry @@ -17,7 +17,7 @@ def test_hookrecorder_basic(): def test_hookrecorder_basic_no_args_hook(): rec = HookRecorder(Registry()) - apimod = type(sys)('api') + apimod = type(os)('api') def xyz(): pass apimod.xyz = xyz diff --git a/testing/plugin/test_pytest_terminal.py b/testing/plugin/test_pytest_terminal.py index 98b367d88..7180927b2 100644 --- a/testing/plugin/test_pytest_terminal.py +++ b/testing/plugin/test_pytest_terminal.py @@ -82,7 +82,7 @@ class TestTerminal: ]) def test_collect_fail(self, testdir, option): - p = testdir.makepyfile("import xyz") + p = testdir.makepyfile("import xyz\n") result = testdir.runpytest(*option._getcmdargs()) result.stdout.fnmatch_lines([ "*test_collect_fail.py E*", diff --git a/testing/root/test_oldmagic.py b/testing/root/test_oldmagic.py index e6f608578..92accc699 100644 --- a/testing/root/test_oldmagic.py +++ b/testing/root/test_oldmagic.py @@ -1,8 +1,10 @@ import py import sys, os +def fass(): + assert 1 == 2 def check_assertion(): - excinfo = py.test.raises(AssertionError, "assert 1 == 2") + excinfo = py.test.raises(AssertionError, fass) s = excinfo.exconly(tryshort=True) if not s == "assert 1 == 2": raise ValueError("assertion not enabled: got %s" % s) @@ -16,6 +18,7 @@ def test_invoke_assertion(recwarn, monkeypatch): py.magic.revoke(assertion=True) recwarn.pop(DeprecationWarning) +@py.test.mark.skipif("sys.platform.startswith('java')") def test_invoke_compile(recwarn, monkeypatch): monkeypatch.setattr(py.builtin.builtins, 'compile', None) py.magic.invoke(compile=True) diff --git a/testing/root/test_py_imports.py b/testing/root/test_py_imports.py index 81b1a1975..901b304bd 100644 --- a/testing/root/test_py_imports.py +++ b/testing/root/test_py_imports.py @@ -9,7 +9,7 @@ def checksubpackage(name): keys = dir(obj) assert len(keys) > 0 print (obj.__map__) - for name in obj.__map__: + for name in list(obj.__map__): assert hasattr(obj, name), (obj, name) def test_dir():