[py-svn] r61757 - py/branch/pytestplugin/py/test/plugin
hpk at codespeak.net
hpk at codespeak.net
Wed Feb 11 22:58:26 CET 2009
Author: hpk
Date: Wed Feb 11 22:58:23 2009
New Revision: 61757
Modified:
py/branch/pytestplugin/py/test/plugin/pytest_pytester.py
py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py
py/branch/pytestplugin/py/test/plugin/pytest_terminal.py
Log:
simplify internal test args and assertions
Modified: py/branch/pytestplugin/py/test/plugin/pytest_pytester.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_pytester.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_pytester.py Wed Feb 11 22:58:23 2009
@@ -13,22 +13,7 @@
self.stdout = LineMatcher(outlines)
self.stderr = LineMatcher(errlines)
-class FileCreation(object):
- def makepyfile(self, **kwargs):
- return self._makefile('.py', **kwargs)
- def maketxtfile(self, **kwargs):
- return self._makefile('.txt', **kwargs)
- def _makefile(self, ext, **kwargs):
- ret = None
- for name, value in kwargs.iteritems():
- p = self.tmpdir.join(name).new(ext=ext)
- source = py.code.Source(value)
- p.write(str(py.code.Source(value)).lstrip())
- if ret is None:
- ret = p
- return ret
-
-class FSTester(FileCreation):
+class FSTester:
def __init__(self, pyfuncitem):
self.pyfuncitem = pyfuncitem
self.tmpdir = py.test.ensuretemp("_".join(pyfuncitem.listnames()))
@@ -119,26 +104,6 @@
def runpytest(self, *args):
return self.runpybin("py.test", *args)
-class LineComp:
-
- def __init__(self):
- self.stringio = py.std.StringIO.StringIO()
-
- def assert_contains_lines(self, lines1=None, lines2=None):
- """ assert that lines2 are contained (linearly) in lines1.
- return a list of extralines found.
- """
- from fnmatch import fnmatch
- __tracebackhide__ = True
- if lines2 is None:
- lines2 = lines1
- lines1 = self.stringio
- if hasattr(lines1, "getvalue"):
- val = lines1.getvalue()
- lines1.truncate(0) # remove what we got
- lines1 = val.split("\n")
- return LineMatcher(lines1).fnmatch_lines(lines2)
-
class TSession:
def __init__(self, pyfuncitem):
self.pyfuncitem = pyfuncitem
@@ -173,6 +138,8 @@
def pytest_itemexecute_arg(self, pyfuncitem, argname):
if argname == "linecomp":
return LineComp(), None
+ elif argname == "LineMatcher":
+ return LineMatcher, None
elif argname == "tsession":
tsession = TSession(pyfuncitem)
return tsession, None
@@ -238,6 +205,20 @@
raise ValueError("found more than one testreport matching %r: %s" %(
inamepart, l))
return l[0]
+
+class LineComp:
+ def __init__(self):
+ self.stringio = py.std.StringIO.StringIO()
+
+ def assert_contains_lines(self, lines2):
+ """ assert that lines2 are contained (linearly) in lines1.
+ return a list of extralines found.
+ """
+ __tracebackhide__ = True
+ val = self.stringio.getvalue()
+ self.stringio.truncate(0) # remove what we got
+ lines1 = val.split("\n")
+ return LineMatcher(lines1).fnmatch_lines(lines2)
class LineMatcher:
def __init__(self, lines):
Modified: py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py Wed Feb 11 22:58:23 2009
@@ -240,10 +240,10 @@
assert entry_lines[-1][0] == ' '
assert 'ValueError' in entry
-def test_generic(plugintester, linecomp):
+def test_generic(plugintester, LineMatcher):
plugintester.apicheck(Resultlog)
fstester = plugintester.fstester()
- fstester.makepyfile(test_one="""
+ fstester.makepyfile("""
import py
def test_pass():
pass
@@ -253,9 +253,8 @@
py.test.skip("")
""")
fstester.runpytest("--resultlog=result.log")
- s = fstester.tmpdir.join("result.log").readlines(cr=0)
-
- linecomp.assert_contains_lines(s, [
+ lines = fstester.tmpdir.join("result.log").readlines(cr=0)
+ LineMatcher(lines).fnmatch_lines([
". *:test_pass",
"F *:test_fail",
"s *:test_skip",
Modified: py/branch/pytestplugin/py/test/plugin/pytest_terminal.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_terminal.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_terminal.py Wed Feb 11 22:58:23 2009
@@ -574,16 +574,16 @@
def test_func():
pass
""")
- stringio = py.std.cStringIO.StringIO()
- rep = CollectonlyReporter(modcol._config, out=stringio)
+ #stringio = py.std.cStringIO.StringIO()
+ rep = CollectonlyReporter(modcol._config, out=linecomp.stringio)
indent = rep.indent
rep.processevent(event.CollectionStart(modcol))
- linecomp.assert_contains_lines(stringio, [
+ linecomp.assert_contains_lines([
"<Module 'test_collectonly_basic.py'>"
])
item = modcol.join("test_func")
rep.processevent(event.ItemStart(item))
- linecomp.assert_contains_lines(stringio, [
+ linecomp.assert_contains_lines([
" <Function 'test_func'>",
])
rep.processevent(event.CollectionReport(modcol, [], excinfo=None))
@@ -594,12 +594,11 @@
import py
py.test.skip("nomod")
""")
- stringio = py.std.cStringIO.StringIO()
- rep = CollectonlyReporter(modcol._config, out=stringio)
+ rep = CollectonlyReporter(modcol._config, out=linecomp.stringio)
tsession.session.bus.subscribe(rep.processevent)
cols = list(tsession.genitems([modcol]))
assert len(cols) == 0
- linecomp.assert_contains_lines(stringio, """
+ linecomp.assert_contains_lines("""
<Module 'test_collectonly_skipped_module.py'>
!!! Skipped: 'nomod' !!!
""")
@@ -608,12 +607,11 @@
modcol = tsession.getmodulecol(configargs=['--collectonly'], source="""
raise ValueError(0)
""")
- stringio = py.std.cStringIO.StringIO()
- rep = CollectonlyReporter(modcol._config, out=stringio)
+ rep = CollectonlyReporter(modcol._config, out=linecomp.stringio)
tsession.session.bus.subscribe(rep.processevent)
cols = list(tsession.genitems([modcol]))
assert len(cols) == 0
- linecomp.assert_contains_lines(stringio, """
+ linecomp.assert_contains_lines("""
<Module 'test_collectonly_failed_module.py'>
!!! ValueError: 0 !!!
""")
More information about the pytest-commit
mailing list