temporary checking towards 3.1 compatibility

introduced some helpers to py.builtin namespace which need some review
after things begin to work more nicely

--HG--
branch : trunk
This commit is contained in:
holger krekel
2009-08-28 19:16:15 +02:00
parent 5e95feaf90
commit 783e6aeb4d
33 changed files with 218 additions and 164 deletions

View File

@@ -64,11 +64,11 @@ class HookRecorder:
# errors on wrong input arguments, using
# *args/**kwargs delays this and gives errors
# elsewhere
exec py.code.compile("""
exec (py.code.compile("""
def %(name)s%(fspec)s:
self._recorder.calls.append(
ParsedCall(%(name)r, locals()))
""" % locals())
""" % locals()))
return locals()[name]
def getcalls(self, names):

View File

@@ -1,4 +1,5 @@
import py
import sys
def pytest_addoption(parser):
group = parser.getgroup("debugconfig")
@@ -7,14 +8,18 @@ def pytest_addoption(parser):
help="disable python assert expression reinterpretation."),
def pytest_configure(config):
# XXX
if sys.version_info >= (3,0):
return
if not config.getvalue("noassert"):
warn_about_missing_assertion()
config._oldassertion = py.std.__builtin__.AssertionError
py.std.__builtin__.AssertionError = py.code._AssertionError
config._oldassertion = py.builtin.builtins.AssertionError
py.builtin.builtins.AssertionError = py.code._AssertionError
def pytest_unconfigure(config):
if hasattr(config, '_oldassertion'):
py.std.__builtin__.AssertionError = config._oldassertion
py.builtin.builtins.AssertionError = config._oldassertion
del config._oldassertion
def warn_about_missing_assertion():

View File

@@ -275,12 +275,16 @@ class EncodedFile(object):
def __init__(self, _stream, encoding):
self._stream = _stream
self.encoding = encoding
def write(self, obj):
if isinstance(obj, unicode):
if py.std.sys.version_info < (3,0):
def write(self, obj):
if isinstance(obj, unicode):
self._stream.write(obj.encode(self.encoding))
else:
self._stream.write(obj)
else:
def write(self, obj):
self._stream.write(obj.encode(self.encoding))
else:
self._stream.write(obj)
def writelines(self, linelist):
data = ''.join(linelist)

View File

@@ -95,7 +95,6 @@ def pytest_addoption(parser):
def pytest_configure(config):
fixoptions(config)
setsession(config)
#xxxloadplugins(config)
def fixoptions(config):
if config.option.numprocesses:
@@ -104,11 +103,6 @@ def fixoptions(config):
if config.option.distload:
config.option.dist = "load"
def xxxloadplugins(config):
for name in config.getvalue("plugin"):
print "importing", name
config.pluginmanager.import_plugin(name)
def setsession(config):
val = config.getvalue
if val("collectonly"):
@@ -156,7 +150,7 @@ class TestDistOptions:
config = testdir.parseconfigure("--tx=popen", "--tx", "ssh=xyz")
xspecs = config.getxspecs()
assert len(xspecs) == 2
print xspecs
print(xspecs)
assert xspecs[0].popen
assert xspecs[1].ssh == "xyz"

View File

@@ -55,7 +55,7 @@ class MarkerDecorator:
self.kwargs = kwargs.copy()
return self
else:
if not len(args) == 1 or not hasattr(args[0], 'func_dict'):
if not len(args) == 1 or not hasattr(args[0], '__dict__'):
raise TypeError("need exactly one function to decorate, "
"got %r" %(args,))
func = args[0]

View File

@@ -52,7 +52,7 @@ class Pdb(py.std.pdb.Pdb):
else:
first = max(1, int(x) - 5)
except:
print '*** Error in argument:', repr(arg)
print ('*** Error in argument: %s' % repr(arg))
return
elif self.lineno is None:
first = max(1, self.curframe.f_lineno - 5)
@@ -68,7 +68,7 @@ class Pdb(py.std.pdb.Pdb):
line = self._getline(filename, lineno)
# end difference from normal do_line
if not line:
print '[EOF]'
print ('[EOF]')
break
else:
s = repr(lineno).rjust(3)
@@ -77,7 +77,7 @@ class Pdb(py.std.pdb.Pdb):
else: s = s + ' '
if lineno == self.curframe.f_lineno:
s = s + '->'
print s + '\t' + line,
sys.stdout.write(s + '\t' + line)
self.lineno = lineno
except KeyboardInterrupt:
pass

View File

@@ -6,8 +6,8 @@ import py
import sys, os
import inspect
from py.__.test.config import Config as pytestConfig
import hookspec
import subprocess
from py.__.test.plugin import hookspec
from py.builtin import print_
pytest_plugins = '_pytest'
@@ -94,7 +94,7 @@ class TmpTestdir:
self._olddir = old
def _makefile(self, ext, args, kwargs):
items = kwargs.items()
items = list(kwargs.items())
if args:
source = "\n".join(map(str, args))
basename = self.request.function.__name__
@@ -249,7 +249,7 @@ class TmpTestdir:
p.write("import py ; pytest_plugins = %r" % plugins)
else:
if self.plugins:
print "warning, ignoring reusing existing con", p
print ("warning, ignoring reusing existing %s" % p)
def popen(self, cmdargs, stdout, stderr, **kw):
if not hasattr(py.std, 'subprocess'):
@@ -274,7 +274,7 @@ class TmpTestdir:
cmdargs = map(str, cmdargs)
p1 = py.path.local("stdout")
p2 = py.path.local("stderr")
print "running", cmdargs, "curdir=", py.path.local()
print_("running", cmdargs, "curdir=", py.path.local())
f1 = p1.open("w")
f2 = p2.open("w")
popen = self.popen(cmdargs, stdout=f1, stderr=f2,
@@ -480,17 +480,17 @@ class LineMatcher:
while lines1:
nextline = lines1.pop(0)
if line == nextline:
print "exact match:", repr(line)
print_("exact match:", repr(line))
break
elif fnmatch(nextline, line):
print "fnmatch:", repr(line)
print " with:", repr(nextline)
print_("fnmatch:", repr(line))
print_(" with:", repr(nextline))
break
else:
if not nomatchprinted:
print "nomatch:", repr(line)
print_("nomatch:", repr(line))
nomatchprinted = True
print " and:", repr(nextline)
print_(" and:", repr(nextline))
extralines.append(nextline)
else:
if line != nextline:

View File

@@ -249,7 +249,7 @@ class SetupState(object):
if colitem is None, this will add a finalizer that
is called at the end of teardown_all().
"""
assert callable(finalizer)
assert hasattr(finalizer, '__call__')
#assert colitem in self.stack
self._finalizers.setdefault(colitem, []).append(finalizer)

View File

@@ -128,7 +128,6 @@ def test_teardown(testdir):
""")
reprec = testdir.inline_run(testpath)
passed, skipped, failed = reprec.countoutcomes()
print "COUNTS", passed, skipped, failed
assert failed == 0, failed
assert passed == 2
assert passed + skipped + failed == 2