first round of fixing jython compatibility issues, marking some tests as xfail-on-jython

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-10-27 21:34:11 +01:00
parent 33bd39053f
commit d2e6cd0523
11 changed files with 46 additions and 8 deletions

View File

@ -37,7 +37,7 @@ def _format_explanation(explanation):
return '\n'.join(result) return '\n'.join(result)
if sys.version_info >= (2, 6): if sys.version_info >= (2, 6) or (sys.platform.startswith("java")):
from _py.code._assertionnew import interpret from _py.code._assertionnew import interpret
else: else:
from _py.code._assertionold import interpret from _py.code._assertionold import interpret

View File

@ -28,6 +28,9 @@ class Code(object):
if rec-cursive is true then dive into code if rec-cursive is true then dive into code
objects contained in co_consts. objects contained in co_consts.
""" """
if sys.platform.startswith("java"):
# XXX jython does not support the below co_filename hack
return self.raw
names = [x for x in dir(self.raw) if x[:3] == 'co_'] names = [x for x in dir(self.raw) if x[:3] == 'co_']
for name in kwargs: for name in kwargs:
if name not in names: if name not in names:

View File

@ -50,6 +50,8 @@ def warn(msg, stacklevel=1, function=None):
fnl = filename.lower() fnl = filename.lower()
if fnl.endswith(".pyc") or fnl.endswith(".pyo"): if fnl.endswith(".pyc") or fnl.endswith(".pyo"):
filename = filename[:-1] filename = filename[:-1]
elif fnl.endswith("$py.class"):
filename = filename.replace('$py.class', '.py')
else: else:
if module == "__main__": if module == "__main__":
try: try:

View File

@ -8,6 +8,9 @@ def pytest_addoption(parser):
help="disable python assert expression reinterpretation."), help="disable python assert expression reinterpretation."),
def pytest_configure(config): def pytest_configure(config):
if sys.platform.startswith("java"):
return # XXX assertions don't work yet with jython 2.5.1
if not config.getvalue("noassert") and not config.getvalue("nomagic"): if not config.getvalue("noassert") and not config.getvalue("nomagic"):
warn_about_missing_assertion() warn_about_missing_assertion()
config._oldassertion = py.builtin.builtins.AssertionError config._oldassertion = py.builtin.builtins.AssertionError

View File

@ -1,5 +1,7 @@
import py import py
pytestmark = py.test.mark.skipif("sys.platform.startswith('java')")
def exvalue(): def exvalue():
return py.std.sys.exc_info()[1] return py.std.sys.exc_info()[1]

View File

@ -3,6 +3,8 @@ import py
import sys import sys
from _py.code.code import safe_repr from _py.code.code import safe_repr
failsonjython = py.test.mark.xfail("sys.platform.startswith('java')")
def test_newcode(): def test_newcode():
source = "i = 3" source = "i = 3"
co = compile(source, '', 'exec') co = compile(source, '', 'exec')
@ -16,10 +18,12 @@ def test_ne():
code2 = py.code.Code(compile('foo = "baz"', '', 'exec')) code2 = py.code.Code(compile('foo = "baz"', '', 'exec'))
assert code2 != code1 assert code2 != code1
@failsonjython
def test_newcode_unknown_args(): def test_newcode_unknown_args():
code = py.code.Code(compile("", '', 'exec')) code = py.code.Code(compile("", '', 'exec'))
py.test.raises(TypeError, 'code.new(filename="hello")') py.test.raises(TypeError, 'code.new(filename="hello")')
@failsonjython
def test_newcode_withfilename(): def test_newcode_withfilename():
source = py.code.Source(""" source = py.code.Source("""
def f(): def f():
@ -44,6 +48,7 @@ def test_newcode_withfilename():
assert 'f' in names assert 'f' in names
assert 'g' in names assert 'g' in names
@failsonjython
def test_newcode_with_filename(): def test_newcode_with_filename():
source = "i = 3" source = "i = 3"
co = compile(source, '', 'exec') co = compile(source, '', 'exec')
@ -58,6 +63,7 @@ def test_newcode_with_filename():
assert str(s) == source assert str(s) == source
@failsonjython
def test_new_code_object_carries_filename_through(): def test_new_code_object_carries_filename_through():
class mystr(str): class mystr(str):
pass pass

View File

@ -384,7 +384,7 @@ raise ValueError()
def test_repr_local(self): def test_repr_local(self):
p = FormattedExcinfo(showlocals=True) p = FormattedExcinfo(showlocals=True)
loc = {'y': 5, 'z': 7, 'x': 3, '__builtins__': __builtins__} loc = {'y': 5, 'z': 7, 'x': 3, '__builtins__': {}} # __builtins__}
reprlocals = p.repr_locals(loc) reprlocals = p.repr_locals(loc)
assert reprlocals.lines assert reprlocals.lines
assert reprlocals.lines[0] == '__builtins__ = <builtins>' assert reprlocals.lines[0] == '__builtins__ = <builtins>'

View File

@ -132,6 +132,7 @@ class CommonFSTests(object):
assert not l1.relto(l2) assert not l1.relto(l2)
assert not l2.relto(l1) assert not l2.relto(l1)
@py.test.mark.xfail("sys.platform.startswith('java')")
def test_listdir(self, path1): def test_listdir(self, path1):
l = path1.listdir() l = path1.listdir()
assert path1.join('sampledir') in l assert path1.join('sampledir') in l
@ -177,6 +178,7 @@ class CommonFSTests(object):
assert "sampledir" in l assert "sampledir" in l
assert "otherdir" in l assert "otherdir" in l
@py.test.mark.xfail("sys.platform.startswith('java')")
def test_visit_ignore(self, path1): def test_visit_ignore(self, path1):
p = path1.join('nonexisting') p = path1.join('nonexisting')
assert list(p.visit(ignore=py.error.ENOENT)) == [] assert list(p.visit(ignore=py.error.ENOENT)) == []

View File

@ -3,6 +3,8 @@ import sys
from py.path import local from py.path import local
from testing.path import common from testing.path import common
failsonjython = py.test.mark.xfail("sys.platform.startswith('java')")
def pytest_funcarg__path1(request): def pytest_funcarg__path1(request):
def setup(): def setup():
path1 = request.config.mktemp("path1") path1 = request.config.mktemp("path1")
@ -545,11 +547,13 @@ class TestPOSIXLocalPath:
for x,y in oldmodes.items(): for x,y in oldmodes.items():
x.chmod(y) x.chmod(y)
@failsonjython
def test_chown_identity(self, path1): def test_chown_identity(self, path1):
owner = path1.stat().owner owner = path1.stat().owner
group = path1.stat().group group = path1.stat().group
path1.chown(owner, group) path1.chown(owner, group)
@failsonjython
def test_chown_dangling_link(self, path1): def test_chown_dangling_link(self, path1):
owner = path1.stat().owner owner = path1.stat().owner
group = path1.stat().group group = path1.stat().group
@ -560,6 +564,7 @@ class TestPOSIXLocalPath:
finally: finally:
x.remove(rec=0) x.remove(rec=0)
@failsonjython
def test_chown_identity_rec_mayfail(self, path1): def test_chown_identity_rec_mayfail(self, path1):
owner = path1.stat().owner owner = path1.stat().owner
group = path1.stat().group group = path1.stat().group

View File

@ -1,12 +1,14 @@
import py, os, sys import py, os, sys
from _py.test.plugin.pytest_capture import CaptureManager from _py.test.plugin.pytest_capture import CaptureManager
needsosdup = py.test.mark.xfail("not hasattr(os, 'dup')")
class TestCaptureManager: class TestCaptureManager:
def test_getmethod_default_no_fd(self, testdir, monkeypatch): def test_getmethod_default_no_fd(self, testdir, monkeypatch):
config = testdir.parseconfig(testdir.tmpdir) config = testdir.parseconfig(testdir.tmpdir)
assert config.getvalue("capture") is None assert config.getvalue("capture") is None
capman = CaptureManager() capman = CaptureManager()
monkeypatch.delattr(os, 'dup') monkeypatch.delattr(os, 'dup', raising=False)
try: try:
assert capman._getmethod(config, None) == "sys" assert capman._getmethod(config, None) == "sys"
finally: finally:
@ -16,14 +18,21 @@ class TestCaptureManager:
config = testdir.parseconfig(testdir.tmpdir) config = testdir.parseconfig(testdir.tmpdir)
assert config.getvalue("capture") is None assert config.getvalue("capture") is None
capman = CaptureManager() capman = CaptureManager()
assert capman._getmethod(config, None) == "fd" # default hasfd = hasattr(os, 'dup')
if hasfd:
assert capman._getmethod(config, None) == "fd"
else:
assert capman._getmethod(config, None) == "sys"
for name in ('no', 'fd', 'sys'): for name in ('no', 'fd', 'sys'):
if not hasfd and name == 'fd':
continue
sub = testdir.tmpdir.mkdir("dir" + name) sub = testdir.tmpdir.mkdir("dir" + name)
sub.ensure("__init__.py") sub.ensure("__init__.py")
sub.join("conftest.py").write('option_capture = %r' % name) sub.join("conftest.py").write('option_capture = %r' % name)
assert capman._getmethod(config, sub.join("test_hello.py")) == name assert capman._getmethod(config, sub.join("test_hello.py")) == name
@needsosdup
@py.test.mark.multi(method=['no', 'fd', 'sys']) @py.test.mark.multi(method=['no', 'fd', 'sys'])
def test_capturing_basic_api(self, method): def test_capturing_basic_api(self, method):
capouter = py.io.StdCaptureFD() capouter = py.io.StdCaptureFD()
@ -43,6 +52,7 @@ class TestCaptureManager:
finally: finally:
capouter.reset() capouter.reset()
@needsosdup
def test_juggle_capturings(self, testdir): def test_juggle_capturings(self, testdir):
capouter = py.io.StdCaptureFD() capouter = py.io.StdCaptureFD()
try: try:
@ -242,10 +252,13 @@ class TestLoggingInteraction:
# here we check a fundamental feature # here we check a fundamental feature
rootdir = str(py.path.local(py.__file__).dirpath().dirpath()) rootdir = str(py.path.local(py.__file__).dirpath().dirpath())
p = testdir.makepyfile(""" p = testdir.makepyfile("""
import sys import sys, os
sys.path.insert(0, %r) sys.path.insert(0, %r)
import py, logging import py, logging
cap = py.io.StdCaptureFD(out=False, in_=False) if hasattr(os, 'dup'):
cap = py.io.StdCaptureFD(out=False, in_=False)
else:
cap = py.io.StdCapture(out=False, in_=False)
logging.warn("hello1") logging.warn("hello1")
outerr = cap.suspend() outerr = cap.suspend()
@ -328,7 +341,8 @@ class TestCaptureFuncarg:
assert out.startswith("42") assert out.startswith("42")
""") """)
reprec.assertoutcome(passed=1) reprec.assertoutcome(passed=1)
@needsosdup
def test_stdfd_functional(self, testdir): def test_stdfd_functional(self, testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
def test_hello(capfd): def test_hello(capfd):
@ -351,6 +365,7 @@ class TestCaptureFuncarg:
"*1 error*", "*1 error*",
]) ])
@needsosdup
def test_keyboardinterrupt_disables_capturing(self, testdir): def test_keyboardinterrupt_disables_capturing(self, testdir):
p = testdir.makepyfile(""" p = testdir.makepyfile("""
def test_hello(capfd): def test_hello(capfd):

View File

@ -189,7 +189,7 @@ class TestPrunetraceback:
assert "__import__" not in result.stdout.str(), "too long traceback" assert "__import__" not in result.stdout.str(), "too long traceback"
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*ERROR during collection*", "*ERROR during collection*",
">*import not_exists*" "*mport*not_exists*"
]) ])
class TestCustomConftests: class TestCustomConftests: