a couple of more mostly jython-related fixes

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-04-23 13:29:28 +02:00
parent 2ee6653ff7
commit 221ac3e466
6 changed files with 20 additions and 6 deletions

View File

@ -353,6 +353,8 @@ def parse_time_with_missing_year(timestr):
day = time.strptime(tparts.pop(0), '%d')[2] day = time.strptime(tparts.pop(0), '%d')[2]
last = tparts.pop(0) # year or hour:minute last = tparts.pop(0) # year or hour:minute
try: try:
if ":" in last:
raise ValueError()
year = time.strptime(last, '%Y')[0] year = time.strptime(last, '%Y')[0]
hour = minute = 0 hour = minute = 0
except ValueError: except ValueError:

View File

@ -3,6 +3,8 @@ import py
from py._code.code import FormattedExcinfo, ReprExceptionInfo from py._code.code import FormattedExcinfo, ReprExceptionInfo
queue = py.builtin._tryimport('queue', 'Queue') queue = py.builtin._tryimport('queue', 'Queue')
failsonjython = py.test.mark.xfail("sys.platform.startswith('java')")
class TWMock: class TWMock:
def __init__(self): def __init__(self):
self.lines = [] self.lines = []
@ -82,6 +84,7 @@ class TestTraceback_f_g_h:
assert s.startswith("def f():") assert s.startswith("def f():")
assert s.endswith("raise ValueError") assert s.endswith("raise ValueError")
@failsonjython
def test_traceback_entry_getsource_in_construct(self): def test_traceback_entry_getsource_in_construct(self):
source = py.code.Source("""\ source = py.code.Source("""\
def xyz(): def xyz():
@ -216,7 +219,7 @@ def test_excinfo_repr():
def test_excinfo_str(): def test_excinfo_str():
excinfo = py.test.raises(ValueError, h) excinfo = py.test.raises(ValueError, h)
s = str(excinfo) s = str(excinfo)
assert s.startswith(__file__[:-1]) # pyc file assert s.startswith(__file__[:-9]) # pyc file and $py.class
assert s.endswith("ValueError") assert s.endswith("ValueError")
assert len(s.split(":")) >= 3 # on windows it's 4 assert len(s.split(":")) >= 3 # on windows it's 4
@ -290,6 +293,7 @@ class TestFormattedExcinfo:
assert lines[0] == "| def f(x):" assert lines[0] == "| def f(x):"
assert lines[1] == " pass" assert lines[1] == " pass"
@failsonjython
def test_repr_source_excinfo(self): def test_repr_source_excinfo(self):
""" check if indentation is right """ """ check if indentation is right """
pr = FormattedExcinfo() pr = FormattedExcinfo()

View File

@ -1,2 +0,0 @@
import sys
import py

View File

@ -2,6 +2,8 @@ from py.code import Source
import py import py
import sys import sys
failsonjython = py.test.mark.xfail("sys.platform.startswith('java')")
def test_source_str_function(): def test_source_str_function():
x = Source("3") x = Source("3")
assert str(x) == "3" assert str(x) == "3"
@ -78,6 +80,7 @@ def test_source_strip_multiline():
source2 = source.strip() source2 = source.strip()
assert source2.lines == [" hello"] assert source2.lines == [" hello"]
@failsonjython
def test_syntaxerror_rerepresentation(): def test_syntaxerror_rerepresentation():
ex = py.test.raises(SyntaxError, py.code.compile, 'x x') ex = py.test.raises(SyntaxError, py.code.compile, 'x x')
assert ex.value.lineno == 1 assert ex.value.lineno == 1
@ -129,6 +132,7 @@ class TestSourceParsingAndCompiling:
exec (co, d) exec (co, d)
assert d['x'] == 3 assert d['x'] == 3
@failsonjython
def test_compile_and_getsource_simple(self): def test_compile_and_getsource_simple(self):
co = py.code.compile("x=3") co = py.code.compile("x=3")
exec (co) exec (co)
@ -199,6 +203,7 @@ class TestSourceParsingAndCompiling:
assert isinstance(mod, ast.Module) assert isinstance(mod, ast.Module)
compile(mod, "<filename>", "exec") compile(mod, "<filename>", "exec")
@failsonjython
def test_compile_and_getsource(self): def test_compile_and_getsource(self):
co = self.source.compile() co = self.source.compile()
py.builtin.exec_(co, globals()) py.builtin.exec_(co, globals())
@ -255,6 +260,7 @@ def test_getstartingblock_multiline():
l = [i for i in x.source.lines if i.strip()] l = [i for i in x.source.lines if i.strip()]
assert len(l) == 4 assert len(l) == 4
@failsonjython
def test_getline_finally(): def test_getline_finally():
def c(): pass def c(): pass
excinfo = py.test.raises(TypeError, """ excinfo = py.test.raises(TypeError, """
@ -268,6 +274,7 @@ def test_getline_finally():
source = excinfo.traceback[-1].statement source = excinfo.traceback[-1].statement
assert str(source).strip() == 'c(1)' assert str(source).strip() == 'c(1)'
@failsonjython
def test_getfuncsource_dynamic(): def test_getfuncsource_dynamic():
source = """ source = """
def f(): def f():
@ -334,6 +341,7 @@ def test_getsource_fallback():
src = getsource(x) src = getsource(x)
assert src == expected assert src == expected
@failsonjython
def test_idem_compile_and_getsource(): def test_idem_compile_and_getsource():
from py._code.source import getsource from py._code.source import getsource
expected = "def x(): pass" expected = "def x(): pass"
@ -347,6 +355,7 @@ def test_findsource_fallback():
assert 'test_findsource_simple' in str(src) assert 'test_findsource_simple' in str(src)
assert src[lineno] == ' def x():' assert src[lineno] == ' def x():'
@failsonjython
def test_findsource___source__(): def test_findsource___source__():
from py._code.source import findsource from py._code.source import findsource
co = py.code.compile("""if 1: co = py.code.compile("""if 1:
@ -364,6 +373,7 @@ def test_findsource___source__():
assert src[lineno] == " def x():" assert src[lineno] == " def x():"
@failsonjython
def test_getfslineno(): def test_getfslineno():
from py.code import getfslineno from py.code import getfslineno

View File

@ -117,7 +117,7 @@ class TestLogConsumer:
def test_log_file(self, tmpdir): def test_log_file(self, tmpdir):
customlog = tmpdir.join('log.out') customlog = tmpdir.join('log.out')
py.log.setconsumer("default", open(str(customlog), 'w', buffering=1)) py.log.setconsumer("default", open(str(customlog), 'w', 1))
py.log.Producer("default")("hello world #1") py.log.Producer("default")("hello world #1")
assert customlog.readlines() == ['[default] hello world #1\n'] assert customlog.readlines() == ['[default] hello world #1\n']

View File

@ -132,7 +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')") #@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
@ -178,7 +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')") #@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)) == []