[svn r57321] merging the event branch:
* moving in test, misc, code, io directories and py/__init__.py * py/bin/_find.py does not print to stderr anymore * a few fixes to conftest files in other dirs some more fixes and adjustments pending --HG-- branch : trunk
This commit is contained in:
1
py/test/report/testing/__init__.py
Normal file
1
py/test/report/testing/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
#
|
||||
118
py/test/report/testing/test_basereporter.py
Normal file
118
py/test/report/testing/test_basereporter.py
Normal file
@@ -0,0 +1,118 @@
|
||||
import py
|
||||
from py.__.test.report.base import BaseReporter
|
||||
from py.__.test.event import EventBus
|
||||
from py.__.test import event
|
||||
from py.__.test.runner import OutcomeRepr
|
||||
from py.__.test.report.base import getrelpath, getmodpath, repr_pythonversion
|
||||
from py.__.test.testing import setupdata
|
||||
import sys
|
||||
|
||||
class TestBaseReporter:
|
||||
def test_activate(self):
|
||||
bus = EventBus()
|
||||
rep = BaseReporter(bus=bus)
|
||||
assert bus._subscribers
|
||||
assert rep.processevent in bus._subscribers
|
||||
rep.deactivate()
|
||||
assert not bus._subscribers
|
||||
|
||||
def test_dispatch_to_matching_method(self):
|
||||
l = []
|
||||
class MyReporter(BaseReporter):
|
||||
def rep_TestrunStart(self, ev):
|
||||
l.append(ev)
|
||||
rep = MyReporter()
|
||||
ev = event.TestrunStart()
|
||||
rep.processevent(ev)
|
||||
assert len(l) == 1
|
||||
assert l[0] is ev
|
||||
|
||||
def test_dispatch_to_default(self):
|
||||
l = []
|
||||
class MyReporter(BaseReporter):
|
||||
def rep(self, ev):
|
||||
l.append(ev)
|
||||
rep = MyReporter()
|
||||
ev = event.NOP()
|
||||
rep.processevent(ev)
|
||||
assert len(l) == 1
|
||||
assert l[0] is ev
|
||||
|
||||
def test_TestItemReport_one(self):
|
||||
for outcome in 'passed skipped failed'.split():
|
||||
rep = BaseReporter()
|
||||
ev = event.ItemTestReport(None, **{outcome:True})
|
||||
rep.processevent(ev)
|
||||
assert getattr(rep, '_' + outcome) == [ev]
|
||||
|
||||
def test_CollectionReport(self):
|
||||
for outcome in 'skipped failed'.split():
|
||||
rep = BaseReporter()
|
||||
ev = event.CollectionReport(None, None, **{outcome:True})
|
||||
rep.processevent(ev)
|
||||
assert getattr(rep, '_' + outcome) == [ev]
|
||||
|
||||
def test_skip_reasons(self):
|
||||
rep = BaseReporter()
|
||||
class longrepr:
|
||||
path = 'xyz'
|
||||
lineno = 3
|
||||
message = "justso"
|
||||
out1 = OutcomeRepr(None, None, longrepr)
|
||||
out2 = OutcomeRepr(None, None, longrepr)
|
||||
ev1 = event.CollectionReport(None, None, skipped=out1)
|
||||
ev2 = event.ItemTestReport(None, skipped=out2)
|
||||
rep.processevent(ev1)
|
||||
rep.processevent(ev2)
|
||||
assert len(rep._skipped) == 2
|
||||
l = rep._folded_skips()
|
||||
assert len(l) == 1
|
||||
num, fspath, lineno, reason = l[0]
|
||||
assert num == 2
|
||||
assert fspath == longrepr.path
|
||||
assert lineno == longrepr.lineno
|
||||
assert reason == longrepr.message
|
||||
|
||||
def test_getmodpath_cases():
|
||||
tmpdir = py.test.ensuretemp("test_getmodpath_cases")
|
||||
pkgdir = tmpdir.join("test_getmodpath")
|
||||
pkgdir.ensure("__init__.py")
|
||||
nopkgdir = tmpdir.ensure("nopkg", dir=1)
|
||||
def checkpkg(names, expected):
|
||||
fcol = setupdata.getexamplecollector(names, tmpdir=pkgdir)
|
||||
assert getmodpath(fcol) == pkgdir.basename + "." + expected
|
||||
def checknopkg(names, expected):
|
||||
fcol = setupdata.getexamplecollector(names, tmpdir=nopkgdir)
|
||||
assert getmodpath(fcol) == expected
|
||||
|
||||
for names in (
|
||||
'mod.py test_f1 mod.test_f1',
|
||||
'mod.py TestA () test_m1 mod.TestA().test_m1',
|
||||
'mod.py test_g1 mod.test_g1',
|
||||
'mod.py test_g1 [0] mod.test_g1[0]',
|
||||
):
|
||||
names = names.split()
|
||||
expected = names.pop()
|
||||
yield checkpkg, names, expected
|
||||
yield checknopkg, names, expected
|
||||
|
||||
def test_repr_python_version():
|
||||
py.magic.patch(sys, 'version_info', (2, 5, 1, 'final', 0))
|
||||
try:
|
||||
assert repr_pythonversion() == "2.5.1-final-0"
|
||||
py.std.sys.version_info = x = (2,3)
|
||||
assert repr_pythonversion() == str(x)
|
||||
finally:
|
||||
py.magic.revert(sys, 'version_info')
|
||||
|
||||
def test_getrelpath():
|
||||
curdir = py.path.local()
|
||||
sep = curdir.sep
|
||||
s = getrelpath(curdir, curdir.join("hello", "world"))
|
||||
assert s == "hello" + sep + "world"
|
||||
|
||||
s = getrelpath(curdir, curdir.dirpath().join("sister"))
|
||||
assert s == ".." + sep + "sister"
|
||||
assert getrelpath(curdir, curdir.dirpath()) == ".."
|
||||
|
||||
assert getrelpath(curdir, "hello") == "hello"
|
||||
53
py/test/report/testing/test_collectonly.py
Normal file
53
py/test/report/testing/test_collectonly.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import py
|
||||
from py.__.test.report.collectonly import CollectonlyReporter
|
||||
from py.__.test import event
|
||||
from py.__.test.testing.suptest import InlineCollection, popvalue
|
||||
from py.__.test.testing.suptest import assert_stringio_contains_lines
|
||||
|
||||
class TestCollectonly(InlineCollection):
|
||||
def test_collectonly_basic(self):
|
||||
modcol = self.getmodulecol(configargs=['--collectonly'], source="""
|
||||
def test_func():
|
||||
pass
|
||||
""")
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = CollectonlyReporter(modcol._config, out=stringio)
|
||||
indent = rep.indent
|
||||
rep.processevent(event.CollectionStart(modcol))
|
||||
s = popvalue(stringio)
|
||||
assert s == "<Module 'TestCollectonly_test_collectonly_basic.py'>"
|
||||
|
||||
item = modcol.join("test_func")
|
||||
rep.processevent(event.ItemStart(item))
|
||||
s = popvalue(stringio)
|
||||
assert s.find("Function 'test_func'") != -1
|
||||
rep.processevent(event.CollectionReport(modcol, [], passed=""))
|
||||
assert rep.indent == indent
|
||||
|
||||
def test_collectonly_skipped_module(self):
|
||||
modcol = self.getmodulecol(configargs=['--collectonly'], source="""
|
||||
import py
|
||||
py.test.skip("nomod")
|
||||
""", withsession=True)
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = CollectonlyReporter(modcol._config, bus=self.session.bus, out=stringio)
|
||||
cols = list(self.session.genitems([modcol]))
|
||||
assert len(cols) == 0
|
||||
assert_stringio_contains_lines(stringio, """
|
||||
<Module 'TestCollectonly_test_collectonly_skipped_module.py'>
|
||||
!!! Skipped: 'nomod' !!!
|
||||
""")
|
||||
|
||||
def test_collectonly_failed_module(self):
|
||||
modcol = self.getmodulecol(configargs=['--collectonly'], source="""
|
||||
raise ValueError(0)
|
||||
""", withsession=True)
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = CollectonlyReporter(modcol._config, bus=self.session.bus, out=stringio)
|
||||
cols = list(self.session.genitems([modcol]))
|
||||
assert len(cols) == 0
|
||||
assert_stringio_contains_lines(stringio, """
|
||||
<Module 'TestCollectonly_test_collectonly_failed_module.py'>
|
||||
!!! ValueError: 0 !!!
|
||||
""")
|
||||
|
||||
356
py/test/report/testing/test_rest.py
Normal file
356
py/test/report/testing/test_rest.py
Normal file
@@ -0,0 +1,356 @@
|
||||
|
||||
""" tests of rest reporter backend
|
||||
"""
|
||||
|
||||
import py
|
||||
|
||||
py.test.skip("refactor ReST reporter tests")
|
||||
|
||||
from py.__.test.testing.test_reporter import AbstractTestReporter,\
|
||||
DummyChannel
|
||||
from py.__.test import event
|
||||
from py.__.test.dsession.rest import RestReporter, NoLinkWriter
|
||||
from py.__.rest.rst import *
|
||||
from py.__.test.dsession.hostmanage import Host
|
||||
from py.__.test.outcome import SerializableOutcome
|
||||
|
||||
class Container(object):
|
||||
def __init__(self, **args):
|
||||
for arg, val in args.items():
|
||||
setattr(self, arg, val)
|
||||
|
||||
class RestTestReporter(RestReporter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if args:
|
||||
super(RestReporter, self).__init__(*args, **kwargs)
|
||||
|
||||
class TestRestUnits(object):
|
||||
def setup_method(self, method):
|
||||
config = py.test.config._reparse(["some_sub"])
|
||||
config.option.verbose = False
|
||||
self.config = config
|
||||
hosts = [Host('localhost')]
|
||||
method.im_func.func_globals['ch'] = DummyChannel(hosts[0])
|
||||
method.im_func.func_globals['reporter'] = r = RestReporter(config,
|
||||
hosts)
|
||||
method.im_func.func_globals['stdout'] = s = py.std.StringIO.StringIO()
|
||||
r.out = s # XXX will need to become a real reporter some time perhaps?
|
||||
r.linkwriter = NoLinkWriter()
|
||||
|
||||
def test_report_unknown(self):
|
||||
self.config.option.verbose = True
|
||||
reporter.report_unknown('foo')
|
||||
assert stdout.getvalue() == 'Unknown report\\: foo\n\n'
|
||||
self.config.option.verbose = False
|
||||
|
||||
def test_report_SendItem(self):
|
||||
event = event.SendItem(item='foo/bar.py', channel=ch)
|
||||
reporter.report(event)
|
||||
assert stdout.getvalue() == ''
|
||||
stdout.seek(0)
|
||||
stdout.truncate()
|
||||
reporter.config.option.verbose = True
|
||||
reporter.report(event)
|
||||
assert stdout.getvalue() == ('sending item foo/bar.py to '
|
||||
'localhost\n\n')
|
||||
|
||||
def test_report_HostRSyncing(self):
|
||||
event = event.HostRSyncing(Host('localhost:/foo/bar'), "a",
|
||||
"b", False)
|
||||
reporter.report(event)
|
||||
assert stdout.getvalue() == ('::\n\n localhost: RSYNC ==> '
|
||||
'/foo/bar\n\n')
|
||||
|
||||
def test_report_HostRSyncRootReady(self):
|
||||
h = Host('localhost')
|
||||
reporter.hosts_to_rsync = 1
|
||||
reporter.report(event.HostGatewayReady(h, ["a"]))
|
||||
event = event.HostRSyncRootReady(h, "a")
|
||||
reporter.report(event)
|
||||
assert stdout.getvalue() == '::\n\n localhost: READY\n\n'
|
||||
|
||||
def test_report_TestStarted(self):
|
||||
event = event.TestStarted([Host('localhost'),
|
||||
Host('foo.com')],
|
||||
"aa", ["a", "b"])
|
||||
reporter.report(event)
|
||||
assert stdout.getvalue() == """\
|
||||
===========================================
|
||||
Running tests on hosts\: localhost, foo.com
|
||||
===========================================
|
||||
|
||||
"""
|
||||
|
||||
def test_report_ItemStart(self):
|
||||
class FakeModule(py.test.collect.Module):
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.fspath = py.path.local('.')
|
||||
def _tryiter(self):
|
||||
return ['test_foo', 'test_bar']
|
||||
def listnames(self):
|
||||
return ['package', 'foo', 'bar.py']
|
||||
|
||||
parent = Container(parent=None, fspath=py.path.local('.'))
|
||||
event = event.ItemStart(item=FakeModule(parent))
|
||||
reporter.report(event)
|
||||
assert stdout.getvalue() == """\
|
||||
Testing module foo/bar.py (2 items)
|
||||
-----------------------------------
|
||||
|
||||
"""
|
||||
|
||||
def test_print_summary(self):
|
||||
reporter.timestart = 10
|
||||
reporter.timeend = 20
|
||||
reporter.timersync = 15
|
||||
reporter.print_summary(10, '', '')
|
||||
assert stdout.getvalue() == """\
|
||||
10 tests run in 10.00s (rsync\: 5.00)
|
||||
-------------------------------------
|
||||
|
||||
"""
|
||||
|
||||
def test_ItemFinish_PASSED(self):
|
||||
outcome = SerializableOutcome()
|
||||
item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
|
||||
event = event.ItemFinish(channel=ch, outcome=outcome, item=item)
|
||||
reporter.report(event)
|
||||
assert stdout.getvalue() == ('* localhost\\: **PASSED** '
|
||||
'foo.py/bar()/baz\n\n')
|
||||
|
||||
def test_ItemFinish_SKIPPED(self):
|
||||
outcome = SerializableOutcome(skipped="reason")
|
||||
item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
|
||||
event = event.ItemFinish(channel=ch, outcome=outcome, item=item)
|
||||
reporter.report(event)
|
||||
assert stdout.getvalue() == ('* localhost\\: **SKIPPED** '
|
||||
'foo.py/bar()/baz\n\n')
|
||||
|
||||
def test_ItemFinish_FAILED(self):
|
||||
outcome = SerializableOutcome(excinfo="xxx")
|
||||
item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
|
||||
event = event.ItemFinish(channel=ch, outcome=outcome, item=item)
|
||||
reporter.report(event)
|
||||
assert stdout.getvalue() == """\
|
||||
* localhost\: **FAILED** `traceback0`_ foo.py/bar()/baz
|
||||
|
||||
"""
|
||||
|
||||
def test_ItemFinish_FAILED_stdout(self):
|
||||
excinfo = Container(
|
||||
typename='FooError',
|
||||
value='A foo has occurred',
|
||||
traceback=[
|
||||
Container(
|
||||
path='foo/bar.py',
|
||||
lineno=1,
|
||||
relline=1,
|
||||
source='foo()',
|
||||
),
|
||||
Container(
|
||||
path='foo/baz.py',
|
||||
lineno=4,
|
||||
relline=1,
|
||||
source='raise FooError("A foo has occurred")',
|
||||
),
|
||||
]
|
||||
)
|
||||
outcome = SerializableOutcome(excinfo=excinfo)
|
||||
outcome.stdout = '<printed>'
|
||||
outcome.stderr = ''
|
||||
parent = Container(parent=None, fspath=py.path.local('.'))
|
||||
item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'],
|
||||
parent=parent, fspath=py.path.local('foo'))
|
||||
event = event.ItemFinish(channel=ch, outcome=outcome,
|
||||
item=item)
|
||||
reporter.report(event)
|
||||
reporter.timestart = 10
|
||||
reporter.timeend = 20
|
||||
reporter.timersync = 15
|
||||
reporter.print_summary(10, '', '')
|
||||
|
||||
reporter.print_summary(1, 'skipped', 'failed')
|
||||
out = stdout.getvalue()
|
||||
assert out.find('<printed>') > -1
|
||||
|
||||
def test_skips(self):
|
||||
class FakeOutcome(Container, event.ItemFinish):
|
||||
pass
|
||||
|
||||
class FakeTryiter(Container, event.DeselectedItem):
|
||||
pass
|
||||
|
||||
reporter.skips()
|
||||
assert stdout.getvalue() == ''
|
||||
reporter.skipped_tests_outcome = [
|
||||
FakeOutcome(outcome=Container(skipped='problem X'),
|
||||
item=Container(listnames=lambda: ['foo', 'bar.py'])),
|
||||
FakeTryiter(excinfo=Container(value='problem Y'),
|
||||
item=Container(listnames=lambda: ['foo', 'baz.py']))]
|
||||
reporter.skips()
|
||||
assert stdout.getvalue() == """\
|
||||
Reasons for skipped tests\:
|
||||
+++++++++++++++++++++++++++
|
||||
|
||||
* foo/bar.py\: problem X
|
||||
|
||||
* foo/baz.py\: problem Y
|
||||
|
||||
"""
|
||||
|
||||
def test_failures(self):
|
||||
class FakeOutcome(Container, event.ItemFinish):
|
||||
pass
|
||||
|
||||
parent = Container(parent=None, fspath=py.path.local('.'))
|
||||
reporter.failed_tests_outcome = [
|
||||
FakeOutcome(
|
||||
outcome=Container(
|
||||
signal=False,
|
||||
excinfo=Container(
|
||||
typename='FooError',
|
||||
value='A foo has occurred',
|
||||
traceback=[
|
||||
Container(
|
||||
path='foo/bar.py',
|
||||
lineno=1,
|
||||
relline=1,
|
||||
source='foo()',
|
||||
),
|
||||
Container(
|
||||
path='foo/baz.py',
|
||||
lineno=4,
|
||||
relline=1,
|
||||
source='raise FooError("A foo has occurred")',
|
||||
),
|
||||
]
|
||||
),
|
||||
stdout='',
|
||||
stderr='',
|
||||
),
|
||||
item=Container(
|
||||
listnames=lambda: ['package', 'foo', 'bar.py',
|
||||
'baz', '()'],
|
||||
parent=parent,
|
||||
fspath=py.path.local('.'),
|
||||
),
|
||||
channel=ch,
|
||||
),
|
||||
]
|
||||
reporter.config.option.tbstyle = 'no'
|
||||
reporter.failures()
|
||||
expected = """\
|
||||
Exceptions\:
|
||||
++++++++++++
|
||||
|
||||
foo/bar.py/baz() on localhost
|
||||
+++++++++++++++++++++++++++++
|
||||
|
||||
.. _`traceback0`:
|
||||
|
||||
|
||||
FooError
|
||||
++++++++
|
||||
|
||||
::
|
||||
|
||||
A foo has occurred
|
||||
|
||||
"""
|
||||
assert stdout.getvalue() == expected
|
||||
|
||||
reporter.config.option.tbstyle = 'short'
|
||||
stdout.seek(0)
|
||||
stdout.truncate()
|
||||
reporter.failures()
|
||||
expected = """\
|
||||
Exceptions\:
|
||||
++++++++++++
|
||||
|
||||
foo/bar.py/baz() on localhost
|
||||
+++++++++++++++++++++++++++++
|
||||
|
||||
.. _`traceback0`:
|
||||
|
||||
|
||||
::
|
||||
|
||||
foo/bar.py line 1
|
||||
foo()
|
||||
foo/baz.py line 4
|
||||
raise FooError("A foo has occurred")
|
||||
|
||||
FooError
|
||||
++++++++
|
||||
|
||||
::
|
||||
|
||||
A foo has occurred
|
||||
|
||||
"""
|
||||
assert stdout.getvalue() == expected
|
||||
|
||||
reporter.config.option.tbstyle = 'long'
|
||||
stdout.seek(0)
|
||||
stdout.truncate()
|
||||
reporter.failures()
|
||||
expected = """\
|
||||
Exceptions\:
|
||||
++++++++++++
|
||||
|
||||
foo/bar.py/baz() on localhost
|
||||
+++++++++++++++++++++++++++++
|
||||
|
||||
.. _`traceback0`:
|
||||
|
||||
|
||||
+++++++++++++++++
|
||||
foo/bar.py line 1
|
||||
+++++++++++++++++
|
||||
|
||||
::
|
||||
|
||||
foo()
|
||||
|
||||
+++++++++++++++++
|
||||
foo/baz.py line 4
|
||||
+++++++++++++++++
|
||||
|
||||
::
|
||||
|
||||
raise FooError("A foo has occurred")
|
||||
|
||||
FooError
|
||||
++++++++
|
||||
|
||||
::
|
||||
|
||||
A foo has occurred
|
||||
|
||||
"""
|
||||
assert stdout.getvalue() == expected
|
||||
|
||||
|
||||
class TestRestReporter(AbstractTestReporter):
|
||||
reporter = RestReporter
|
||||
|
||||
def get_hosts(self):
|
||||
return [Host('localhost')]
|
||||
|
||||
def test_failed_to_load(self):
|
||||
py.test.skip("Not implemented")
|
||||
|
||||
def test_report_received_item_outcome(self):
|
||||
val = self.report_received_item_outcome()
|
||||
expected_list = [
|
||||
"**FAILED**",
|
||||
"**SKIPPED**",
|
||||
"**PASSED**",
|
||||
"* localhost\:",
|
||||
"`traceback0`_ test\_one.py/funcpass",
|
||||
"test\_one.py/funcpass"]
|
||||
for expected in expected_list:
|
||||
assert val.find(expected) != -1
|
||||
|
||||
|
||||
164
py/test/report/testing/test_terminal.py
Normal file
164
py/test/report/testing/test_terminal.py
Normal file
@@ -0,0 +1,164 @@
|
||||
import py
|
||||
import sys
|
||||
from py.__.test.report.terminal import TerminalReporter
|
||||
from py.__.test import event
|
||||
#from py.__.test.testing import suptest
|
||||
from py.__.test.runner import basic_run_report
|
||||
from py.__.test.testing.suptest import InlineCollection, popvalue
|
||||
from py.__.test.testing.suptest import assert_stringio_contains_lines
|
||||
from py.__.test.dsession.hostmanage import Host, makehostup
|
||||
from py.__.test.report.base import repr_pythonversion
|
||||
|
||||
class TestTerminal(InlineCollection):
|
||||
def test_session_reporter_subscription(self):
|
||||
config = py.test.config._reparse(['xxx'])
|
||||
session = config.initsession()
|
||||
session.sessionstarts()
|
||||
rep = session.reporter
|
||||
assert isinstance(rep, TerminalReporter)
|
||||
assert rep.processevent in session.bus._subscribers
|
||||
session.sessionfinishes()
|
||||
#assert rep.processevent not in session.bus._subscribers
|
||||
|
||||
def test_hostup(self):
|
||||
item = self.getitem("def test_func(): pass")
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = TerminalReporter(item._config, file=stringio)
|
||||
rep.processevent(event.TestrunStart())
|
||||
host = Host("localhost")
|
||||
rep.processevent(makehostup(host))
|
||||
s = popvalue(stringio)
|
||||
expect = "%s %s %s - Python %s" %(host.hostid, sys.platform,
|
||||
sys.executable, repr_pythonversion(sys.version_info))
|
||||
assert s.find(expect) != -1
|
||||
|
||||
def test_pass_skip_fail(self):
|
||||
modcol = self.getmodulecol("""
|
||||
import py
|
||||
def test_ok():
|
||||
pass
|
||||
def test_skip():
|
||||
py.test.skip("xx")
|
||||
def test_func():
|
||||
assert 0
|
||||
""", withsession=True)
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = TerminalReporter(modcol._config, file=stringio)
|
||||
rep.processevent(event.TestrunStart())
|
||||
for item in self.session.genitems([modcol]):
|
||||
ev = basic_run_report(item)
|
||||
rep.processevent(ev)
|
||||
s = popvalue(stringio)
|
||||
assert s.find("test_pass_skip_fail.py .sF") != -1
|
||||
rep.processevent(event.TestrunFinish())
|
||||
assert_stringio_contains_lines(stringio, [
|
||||
" def test_func():",
|
||||
"> assert 0",
|
||||
"E assert 0",
|
||||
])
|
||||
|
||||
def test_pass_skip_fail_verbose(self):
|
||||
modcol = self.getmodulecol("""
|
||||
import py
|
||||
def test_ok():
|
||||
pass
|
||||
def test_skip():
|
||||
py.test.skip("xx")
|
||||
def test_func():
|
||||
assert 0
|
||||
""", configargs=("-v",), withsession=True)
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = TerminalReporter(modcol._config, file=stringio)
|
||||
rep.processevent(event.TestrunStart())
|
||||
items = [modcol.join(x) for x in modcol.listdir()]
|
||||
for item in items:
|
||||
rep.processevent(event.ItemStart(item))
|
||||
s = stringio.getvalue().strip()
|
||||
assert s.endswith(item.name)
|
||||
ev = basic_run_report(item)
|
||||
rep.processevent(ev)
|
||||
|
||||
assert_stringio_contains_lines(stringio, [
|
||||
"*test_pass_skip_fail_verbose.py:2: *test_ok*PASS",
|
||||
"*test_pass_skip_fail_verbose.py:4: *test_skip*SKIP",
|
||||
"*test_pass_skip_fail_verbose.py:6: *test_func*FAIL",
|
||||
])
|
||||
rep.processevent(event.TestrunFinish())
|
||||
assert_stringio_contains_lines(stringio, [
|
||||
" def test_func():",
|
||||
"> assert 0",
|
||||
"E assert 0",
|
||||
])
|
||||
|
||||
def test_collect_fail(self):
|
||||
modcol = self.getmodulecol("""
|
||||
import xyz
|
||||
""", withsession=True)
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = TerminalReporter(modcol._config, bus=self.session.bus, file=stringio)
|
||||
rep.processevent(event.TestrunStart())
|
||||
l = list(self.session.genitems([modcol]))
|
||||
assert len(l) == 0
|
||||
s = popvalue(stringio)
|
||||
print s
|
||||
assert s.find("test_collect_fail.py - ImportError: No module named") != -1
|
||||
rep.processevent(event.TestrunFinish())
|
||||
assert_stringio_contains_lines(stringio, [
|
||||
"> import xyz",
|
||||
"E ImportError: No module named xyz"
|
||||
])
|
||||
|
||||
def test_internal_exception(self):
|
||||
modcol = self.getmodulecol("def test_one(): pass")
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = TerminalReporter(modcol._config, file=stringio)
|
||||
excinfo = py.test.raises(ValueError, "raise ValueError('hello')")
|
||||
rep.processevent(event.InternalException(excinfo))
|
||||
s = popvalue(stringio)
|
||||
assert s.find("InternalException:") != -1
|
||||
|
||||
def test_hostready_crash(self):
|
||||
modcol = self.getmodulecol("""
|
||||
def test_one():
|
||||
pass
|
||||
""", configargs=("-v",))
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
host1 = Host("localhost")
|
||||
rep = TerminalReporter(modcol._config, file=stringio)
|
||||
rep.processevent(event.HostGatewayReady(host1, None))
|
||||
s = popvalue(stringio)
|
||||
assert s.find("HostGatewayReady") != -1
|
||||
rep.processevent(event.HostDown(host1, "myerror"))
|
||||
s = popvalue(stringio)
|
||||
assert s.find("HostDown") != -1
|
||||
assert s.find("myerror") != -1
|
||||
|
||||
def test_writeline(self):
|
||||
modcol = self.getmodulecol("def test_one(): pass")
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = TerminalReporter(modcol._config, file=stringio)
|
||||
rep.write_fspath_result(py.path.local("xy.py"), '.')
|
||||
rep.write_line("hello world")
|
||||
lines = popvalue(stringio).split('\n')
|
||||
assert not lines[0]
|
||||
assert lines[1].endswith("xy.py .")
|
||||
assert lines[2] == "hello world"
|
||||
|
||||
def test_looponfailingreport(self):
|
||||
modcol = self.getmodulecol("""
|
||||
def test_fail():
|
||||
assert 0
|
||||
def test_fail2():
|
||||
raise ValueError()
|
||||
""")
|
||||
stringio = py.std.cStringIO.StringIO()
|
||||
rep = TerminalReporter(modcol._config, file=stringio)
|
||||
reports = [basic_run_report(modcol.join(x))
|
||||
for x in modcol.listdir()]
|
||||
rep.processevent(event.LooponfailingInfo(reports, [modcol._config.topdir]))
|
||||
assert_stringio_contains_lines(stringio, [
|
||||
"*test_looponfailingreport.py:2: assert 0",
|
||||
"*test_looponfailingreport.py:4: ValueError*",
|
||||
"*waiting*",
|
||||
"*%s*" % (modcol._config.topdir),
|
||||
])
|
||||
90
py/test/report/testing/test_web.py
Normal file
90
py/test/report/testing/test_web.py
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
""" webtest
|
||||
"""
|
||||
|
||||
import py
|
||||
|
||||
def setup_module(mod):
|
||||
try:
|
||||
from pypy.translator.js.main import rpython2javascript
|
||||
from pypy.translator.js import commproxy
|
||||
mod.commproxy = commproxy
|
||||
mod.rpython2javascript = rpython2javascript
|
||||
except ImportError:
|
||||
py.test.skip("PyPy not found")
|
||||
mod.commproxy.USE_MOCHIKIT = False
|
||||
mod.rpython2javascript = rpython2javascript
|
||||
mod.commproxy = mod.commproxy
|
||||
from py.__.test.dsession.web import TestHandler as _TestHandler
|
||||
from py.__.test.dsession.web import MultiQueue
|
||||
mod._TestHandler = _TestHandler
|
||||
mod.MultiQueue = MultiQueue
|
||||
|
||||
def test_js_generate():
|
||||
from py.__.test.dsession import webjs
|
||||
from py.__.test.dsession.web import FUNCTION_LIST, IMPORTED_PYPY
|
||||
|
||||
source = rpython2javascript(webjs, FUNCTION_LIST, use_pdb=False)
|
||||
assert source
|
||||
|
||||
def test_parse_args():
|
||||
class TestTestHandler(_TestHandler):
|
||||
def __init__(self):
|
||||
pass
|
||||
h = TestTestHandler()
|
||||
assert h.parse_args('foo=bar') == {'foo': 'bar'}
|
||||
assert h.parse_args('foo=bar%20baz') == {'foo': 'bar baz'}
|
||||
assert h.parse_args('foo%20bar=baz') == {'foo bar': 'baz'}
|
||||
assert h.parse_args('foo=bar%baz') == {'foo': 'bar\xbaz'}
|
||||
py.test.raises(ValueError, 'h.parse_args("foo")')
|
||||
|
||||
class TestMultiQueue(object):
|
||||
def test_get_one_sessid(self):
|
||||
mq = MultiQueue()
|
||||
mq.put(1)
|
||||
result = mq.get(1234)
|
||||
assert result == 1
|
||||
|
||||
def test_get_two_sessid(self):
|
||||
mq = MultiQueue()
|
||||
mq.put(1)
|
||||
result = mq.get(1234)
|
||||
assert result == 1
|
||||
mq.put(2)
|
||||
result = mq.get(1234)
|
||||
assert result == 2
|
||||
result = mq.get(5678)
|
||||
assert result == 1
|
||||
result = mq.get(5678)
|
||||
assert result == 2
|
||||
|
||||
def test_get_blocking(self):
|
||||
import thread
|
||||
result = []
|
||||
def getitem(mq, sessid):
|
||||
result.append(mq.get(sessid))
|
||||
mq = MultiQueue()
|
||||
thread.start_new_thread(getitem, (mq, 1234))
|
||||
assert not result
|
||||
mq.put(1)
|
||||
py.std.time.sleep(0.1)
|
||||
assert result == [1]
|
||||
|
||||
def test_empty(self):
|
||||
mq = MultiQueue()
|
||||
assert mq.empty()
|
||||
mq.put(1)
|
||||
assert not mq.empty()
|
||||
result = mq.get(1234)
|
||||
result == 1
|
||||
assert mq.empty()
|
||||
mq.put(2)
|
||||
result = mq.get(4567)
|
||||
assert result == 1
|
||||
result = mq.get(1234)
|
||||
assert result == 2
|
||||
assert not mq.empty()
|
||||
result = mq.get(4567)
|
||||
assert result == 2
|
||||
assert mq.empty()
|
||||
|
||||
143
py/test/report/testing/test_webjs.py
Normal file
143
py/test/report/testing/test_webjs.py
Normal file
@@ -0,0 +1,143 @@
|
||||
import py
|
||||
|
||||
def check(mod):
|
||||
try:
|
||||
import pypy
|
||||
from pypy.translator.js.modules import dom
|
||||
from pypy.translator.js.tester import schedule_callbacks
|
||||
dom.Window # check whether dom was properly imported or is just a
|
||||
# leftover in sys.modules
|
||||
except (ImportError, AttributeError):
|
||||
py.test.skip('PyPy not found')
|
||||
mod.dom = dom
|
||||
mod.schedule_callbacks = schedule_callbacks
|
||||
|
||||
from py.__.test.dsession import webjs
|
||||
from py.__.test.dsession.web import exported_methods
|
||||
mod.webjs = webjs
|
||||
mod.exported_methods = exported_methods
|
||||
mod.here = py.magic.autopath().dirpath()
|
||||
|
||||
def setup_module(mod):
|
||||
check(mod)
|
||||
|
||||
# load HTML into window object
|
||||
html = here.join('../webdata/index.html').read()
|
||||
mod.html = html
|
||||
from pypy.translator.js.modules import dom
|
||||
mod.dom = dom
|
||||
dom.window = dom.Window(html)
|
||||
dom.document = dom.window.document
|
||||
from py.__.test.dsession import webjs
|
||||
from py.__.test.dsession.web import exported_methods
|
||||
mod.webjs = webjs
|
||||
mod.exported_methods = exported_methods
|
||||
|
||||
def setup_function(f):
|
||||
dom.window = dom.Window(html)
|
||||
dom.document = dom.window.document
|
||||
|
||||
def test_html_loaded():
|
||||
body = dom.window.document.getElementsByTagName('body')[0]
|
||||
assert len(body.childNodes) > 0
|
||||
assert str(body.childNodes[1].nodeName) == 'A'
|
||||
|
||||
def test_set_msgbox():
|
||||
py.test.skip("not implemented in genjs")
|
||||
msgbox = dom.window.document.getElementById('messagebox')
|
||||
assert len(msgbox.childNodes) == 0
|
||||
webjs.set_msgbox('foo', 'bar')
|
||||
assert len(msgbox.childNodes) == 1
|
||||
assert msgbox.childNodes[0].nodeName == 'PRE'
|
||||
assert msgbox.childNodes[0].childNodes[0].nodeValue == 'foo\nbar'
|
||||
|
||||
def test_show_info():
|
||||
info = dom.window.document.getElementById('info')
|
||||
info.style.visibility = 'hidden'
|
||||
info.innerHTML = ''
|
||||
webjs.show_info('foobar')
|
||||
content = info.innerHTML
|
||||
assert content == 'foobar'
|
||||
bgcolor = info.style.backgroundColor
|
||||
assert bgcolor == 'beige'
|
||||
|
||||
def test_hide_info():
|
||||
info = dom.window.document.getElementById('info')
|
||||
info.style.visibility = 'visible'
|
||||
webjs.hide_info()
|
||||
assert info.style.visibility == 'hidden'
|
||||
|
||||
def test_process():
|
||||
main_t = dom.window.document.getElementById('main_table')
|
||||
assert len(main_t.getElementsByTagName('tr')) == 0
|
||||
assert not webjs.process({})
|
||||
|
||||
msg = {'type': 'ItemStart',
|
||||
'itemtype': 'Module',
|
||||
'itemname': 'foo.py',
|
||||
'fullitemname': 'modules/foo.py',
|
||||
'length': 10,
|
||||
}
|
||||
assert webjs.process(msg)
|
||||
trs = main_t.getElementsByTagName('tr')
|
||||
assert len(trs) == 1
|
||||
tr = trs[0]
|
||||
assert len(tr.childNodes) == 2
|
||||
assert tr.childNodes[0].nodeName == 'TD'
|
||||
assert tr.childNodes[0].innerHTML == 'foo.py[0/10]'
|
||||
assert tr.childNodes[1].nodeName == 'TD'
|
||||
assert tr.childNodes[1].childNodes[0].nodeName == 'TABLE'
|
||||
assert len(tr.childNodes[1].getElementsByTagName('tr')) == 0
|
||||
|
||||
def test_process_two():
|
||||
main_t = dom.window.document.getElementById('main_table')
|
||||
msg = {'type': 'ItemStart',
|
||||
'itemtype': 'Module',
|
||||
'itemname': 'foo.py',
|
||||
'fullitemname': 'modules/foo.py',
|
||||
'length': 10,
|
||||
}
|
||||
webjs.process(msg)
|
||||
msg = {'type': 'ItemFinish',
|
||||
'fullmodulename': 'modules/foo.py',
|
||||
'passed' : 'True',
|
||||
'fullitemname' : 'modules/foo.py/test_item',
|
||||
'hostkey': None,
|
||||
}
|
||||
webjs.process(msg)
|
||||
trs = main_t.getElementsByTagName('tr')
|
||||
tds = trs[0].getElementsByTagName('td')
|
||||
# two cells in the row, one in the table inside one of the cells
|
||||
assert len(tds) == 3
|
||||
html = tds[0].innerHTML
|
||||
assert html == 'foo.py[1/10]'
|
||||
assert tds[2].innerHTML == '.'
|
||||
|
||||
def test_signal():
|
||||
main_t = dom.window.document.getElementById('main_table')
|
||||
msg = {'type': 'ItemStart',
|
||||
'itemtype': 'Module',
|
||||
'itemname': 'foo.py',
|
||||
'fullitemname': 'modules/foo.py',
|
||||
'length': 10,
|
||||
}
|
||||
webjs.process(msg)
|
||||
msg = {'type': 'ItemFinish',
|
||||
'fullmodulename': 'modules/foo.py',
|
||||
'passed' : 'False',
|
||||
'fullitemname' : 'modules/foo.py/test_item',
|
||||
'hostkey': None,
|
||||
'signal': '10',
|
||||
'skipped': 'False',
|
||||
}
|
||||
exported_methods.fail_reasons['modules/foo.py/test_item'] = 'Received signal 10'
|
||||
exported_methods.stdout['modules/foo.py/test_item'] = ''
|
||||
exported_methods.stderr['modules/foo.py/test_item'] = ''
|
||||
webjs.process(msg)
|
||||
schedule_callbacks(exported_methods)
|
||||
# ouch
|
||||
assert dom.document.getElementById('modules/foo.py').childNodes[0].\
|
||||
childNodes[0].childNodes[0].childNodes[0].nodeValue == 'F'
|
||||
|
||||
# XXX: Write down test for full run
|
||||
|
||||
Reference in New Issue
Block a user