From 9b62f2290cb39bd74fddfeb8a4ac43587d88f43a Mon Sep 17 00:00:00 2001 From: fijal Date: Sat, 3 Feb 2007 13:14:46 +0100 Subject: [PATCH] [svn r37862] Move Skipped/Failed/Passed out of public namespace --HG-- branch : trunk --- py/__init__.py | 5 ++-- py/doc/example/pytest/test_failures.py | 5 ++-- py/doc/test_conftest.py | 19 ++++++++------- py/test/collect.py | 21 ---------------- py/test/item.py | 5 ++-- py/test/outcome.py | 29 ++++++++++++++++++++++ py/test/raises.py | 2 +- py/test/rsession/executor.py | 3 ++- py/test/rsession/rsession.py | 3 ++- py/test/session.py | 11 +++++---- py/test/terminal/remote.py | 5 ++-- py/test/terminal/terminal.py | 25 +++++++++---------- py/test/testing/test_collect.py | 9 +++---- py/test/testing/test_doctest.py | 3 ++- py/test/testing/test_session.py | 33 +++++++++++++------------- 15 files changed, 99 insertions(+), 79 deletions(-) create mode 100644 py/test/outcome.py diff --git a/py/__init__.py b/py/__init__.py index c91791118..72ddf5c11 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -9,8 +9,8 @@ version = "0.8.80-alpha2" initpkg(__name__, description = "py.test and the py lib", - revision = int('$LastChangedRevision: 37741 $'.split(':')[1][:-1]), - lastchangedate = '$LastChangedDate: 2007-02-01 16:20:39 +0100 (Thu, 01 Feb 2007) $', + revision = int('$LastChangedRevision: 37862 $'.split(':')[1][:-1]), + lastchangedate = '$LastChangedDate: 2007-02-03 13:14:46 +0100 (Sat, 03 Feb 2007) $', version = version, url = "http://codespeak.net/py", download_url = "http://codespeak.net/download/py/%s.tar.gz" %(version,), @@ -27,6 +27,7 @@ initpkg(__name__, 'test.skip' : ('./test/item.py', 'skip'), 'test.fail' : ('./test/item.py', 'fail'), 'test.exit' : ('./test/session.py', 'exit'), + 'test.pdb' : ('./test/pdbplus.py', 'start_pdb'), # configuration/initialization related test api 'test.config' : ('./test/config.py', 'config_per_process'), diff --git a/py/doc/example/pytest/test_failures.py b/py/doc/example/pytest/test_failures.py index 4427af02b..870bb26bd 100644 --- a/py/doc/example/pytest/test_failures.py +++ b/py/doc/example/pytest/test_failures.py @@ -1,12 +1,13 @@ import py failure_demo = py.magic.autopath().dirpath('failure_demo.py') +from py.__.test.outcome import Failed, Passed def test_failure_demo_fails_properly(): config = py.test.config._reparse([failure_demo]) session = config.initsession() session.main() - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 21 - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert not l diff --git a/py/doc/test_conftest.py b/py/doc/test_conftest.py index 59a8f55cf..0bf8fcdec 100644 --- a/py/doc/test_conftest.py +++ b/py/doc/test_conftest.py @@ -1,5 +1,6 @@ import py +from py.__.test.outcome import Skipped, Failed, Passed def setup_module(mod): mod.tmpdir = py.test.ensuretemp('docdoctest') @@ -30,10 +31,10 @@ def test_doctest_basic(): config = py.test.config._reparse([xtxt]) session = config.initsession() session.main() - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 0 - l = session.getitemoutcomepairs(py.test.Item.Passed) - l2 = session.getitemoutcomepairs(py.test.Item.Skipped) + l = session.getitemoutcomepairs(Passed) + l2 = session.getitemoutcomepairs(Skipped) assert len(l+l2) == 2 def test_doctest_eol(): @@ -45,10 +46,10 @@ def test_doctest_eol(): config = py.test.config._reparse([ytxt]) session = config.initsession() session.main() - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 0 - l = session.getitemoutcomepairs(py.test.Item.Passed) - l2 = session.getitemoutcomepairs(py.test.Item.Skipped) + l = session.getitemoutcomepairs(Passed) + l2 = session.getitemoutcomepairs(Skipped) assert len(l+l2) == 2 def test_js_ignore(): @@ -63,10 +64,10 @@ def test_js_ignore(): config = py.test.config._reparse([xtxt]) session = config.initsession() session.main() - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 0 - l = session.getitemoutcomepairs(py.test.Item.Passed) - l2 = session.getitemoutcomepairs(py.test.Item.Skipped) + l = session.getitemoutcomepairs(Passed) + l2 = session.getitemoutcomepairs(Skipped) assert len(l+l2) == 3 def test_resolve_linkrole(): diff --git a/py/test/collect.py b/py/test/collect.py index aec5db841..74a0e69b1 100644 --- a/py/test/collect.py +++ b/py/test/collect.py @@ -56,27 +56,6 @@ class Collector(object): Generator = configproperty('Generator') _stickyfailure = None - class Outcome: - def __init__(self, msg=None, excinfo=None): - self.msg = msg - self.excinfo = excinfo - def __repr__(self): - if self.msg: - return self.msg - return "<%s instance>" %(self.__class__.__name__,) - __str__ = __repr__ - - class Passed(Outcome): - pass - class Failed(Outcome): - pass - class ExceptionFailure(Failed): - def __init__(self, expr, expected, msg=None, excinfo=None): - Collector.Failed.__init__(self, msg=msg, excinfo=excinfo) - self.expr = expr - self.expected = expected - class Skipped(Outcome): - pass def __repr__(self): return "<%s %r>" %(self.__class__.__name__, self.name) diff --git a/py/test/item.py b/py/test/item.py index 03a1e9029..2c2732100 100644 --- a/py/test/item.py +++ b/py/test/item.py @@ -1,6 +1,7 @@ import py from inspect import isclass, ismodule +from py.__.test.outcome import Skipped, Failed, Passed _dummy = object() @@ -101,10 +102,10 @@ class Function(Item): def skip(msg="unknown reason"): """ skip with the given Message. """ __tracebackhide__ = True - raise py.test.Item.Skipped(msg=msg) + raise Skipped(msg=msg) def fail(msg="unknown failure"): """ fail with the given Message. """ __tracebackhide__ = True - raise py.test.Item.Failed(msg=msg) + raise Failed(msg=msg) diff --git a/py/test/outcome.py b/py/test/outcome.py new file mode 100644 index 000000000..486064a5e --- /dev/null +++ b/py/test/outcome.py @@ -0,0 +1,29 @@ + +""" File defining possible outcomes of running +""" + +class Outcome: + def __init__(self, msg=None, excinfo=None): + self.msg = msg + self.excinfo = excinfo + + def __repr__(self): + if self.msg: + return self.msg + return "<%s instance>" %(self.__class__.__name__,) + __str__ = __repr__ + +class Passed(Outcome): + pass + +class Failed(Outcome): + pass + +class ExceptionFailure(Failed): + def __init__(self, expr, expected, msg=None, excinfo=None): + Failed.__init__(self, msg=msg, excinfo=excinfo) + self.expr = expr + self.expected = expected + +class Skipped(Outcome): + pass diff --git a/py/test/raises.py b/py/test/raises.py index b27e021d6..cca5c26af 100644 --- a/py/test/raises.py +++ b/py/test/raises.py @@ -1,6 +1,6 @@ import sys import py -ExceptionFailure = py.test.Item.ExceptionFailure +from py.__.test.outcome import ExceptionFailure def raises(ExpectedException, *args, **kwargs): """ raise AssertionError, if target code does not raise the expected diff --git a/py/test/rsession/executor.py b/py/test/rsession/executor.py index bdb493751..0e1e9dff6 100644 --- a/py/test/rsession/executor.py +++ b/py/test/rsession/executor.py @@ -6,6 +6,7 @@ import py, os from py.__.test.rsession.outcome import Outcome, ReprOutcome from py.__.test.rsession.box import Box from py.__.test.rsession import report +from py.__.test.outcome import Skipped, Failed class RunExecutor(object): """ Same as in executor, but just running run @@ -26,7 +27,7 @@ class RunExecutor(object): try: self.run() outcome = Outcome() - except py.test.Item.Skipped, e: + except Skipped, e: outcome = Outcome(skipped=str(e)) except (KeyboardInterrupt, SystemExit): raise diff --git a/py/test/rsession/rsession.py b/py/test/rsession/rsession.py index ca48b94cd..7b440b1b4 100644 --- a/py/test/rsession/rsession.py +++ b/py/test/rsession/rsession.py @@ -17,6 +17,7 @@ from py.__.test.rsession.local import local_loop, plain_runner, apigen_runner,\ box_runner from py.__.test.rsession.reporter import LocalReporter, RemoteReporter from py.__.test.session import Session +from py.__.test.outcome import Skipped, Failed class AbstractSession(Session): """ @@ -84,7 +85,7 @@ class AbstractSession(Session): excinfo, item = data if excinfo is None: reporter(report.ItemStart(item)) - elif excinfo.type is py.test.Item.Skipped: + elif excinfo.type is Skipped: reporter(report.SkippedTryiter(excinfo, item)) else: reporter(report.FailedTryiter(excinfo, item)) diff --git a/py/test/session.py b/py/test/session.py index 346c56bd3..cfea1ea83 100644 --- a/py/test/session.py +++ b/py/test/session.py @@ -1,4 +1,5 @@ import py +from py.__.test.outcome import Outcome, Failed, Passed, Skipped class Session(object): """ @@ -82,17 +83,17 @@ class Session(object): outcome = self.run(colitem) except (KeyboardInterrupt, Exit): raise - except colitem.Outcome, outcome: + except Outcome, outcome: if outcome.excinfo is None: outcome.excinfo = py.code.ExceptionInfo() except: excinfo = py.code.ExceptionInfo() - outcome = colitem.Failed(excinfo=excinfo) + outcome = Failed(excinfo=excinfo) assert (outcome is None or - isinstance(outcome, (list, colitem.Outcome))) + isinstance(outcome, (list, Outcome))) finally: self.finish(colitem, outcome) - if isinstance(outcome, colitem.Failed) and self.config.option.exitfirst: + if isinstance(outcome, Failed) and self.config.option.exitfirst: py.test.exit("exit on first problem configured.", item=colitem) finally: colitem.finishcapture() @@ -104,7 +105,7 @@ class Session(object): colitem.skipbykeyword(self.config.option.keyword) res = colitem.run() if res is None: - return py.test.Item.Passed() + return Passed() elif not isinstance(res, (list, tuple)): raise TypeError("%r.run() returned neither " "list, tuple nor None: %r" % (colitem, res)) diff --git a/py/test/terminal/remote.py b/py/test/terminal/remote.py index 9bf52414f..5d283adfc 100644 --- a/py/test/terminal/remote.py +++ b/py/test/terminal/remote.py @@ -1,7 +1,8 @@ from __future__ import generators import py from py.__.test.session import Session -from py.__.test.terminal.out import getout +from py.__.test.terminal.out import getout +from py.__.test.outcome import Failed, Passed, Skipped def checkpyfilechange(rootdir, statcache={}): """ wait until project files are changed. """ @@ -135,6 +136,6 @@ def slaverun_TerminalSession(channel): session.shouldclose = channel.isclosed print "SLAVE: starting session.main()" session.main() - failures = session.getitemoutcomepairs(py.test.Item.Failed) + failures = session.getitemoutcomepairs(Failed) failures = [config.get_collector_trail(item) for item,_ in failures] channel.send(failures) diff --git a/py/test/terminal/terminal.py b/py/test/terminal/terminal.py index 90708778c..430dc3200 100644 --- a/py/test/terminal/terminal.py +++ b/py/test/terminal/terminal.py @@ -4,6 +4,7 @@ from time import time as now Item = py.test.Item from py.__.test.terminal.out import getout from py.__.test.representation import Presenter +from py.__.test.outcome import Skipped, Passed, Failed def getrelpath(source, dest): base = source.common(dest) @@ -167,14 +168,14 @@ class TerminalSession(Session): # progress information # -------------------- typemap = { - Item.Passed: '.', - Item.Skipped: 's', - Item.Failed: 'F', + Passed: '.', + Skipped: 's', + Failed: 'F', } namemap = { - Item.Passed: 'ok', - Item.Skipped: 'SKIP', - Item.Failed: 'FAIL', + Passed: 'ok', + Skipped: 'SKIP', + Failed: 'FAIL', } def repr_progress_short_result(self, item, outcome): @@ -194,11 +195,11 @@ class TerminalSession(Session): return 'UNKNOWN' def repr_progress_module_result(self, item, outcome): - if isinstance(outcome, py.test.Item.Failed): + if isinstance(outcome, Failed): return "FAILED TO LOAD MODULE" - elif isinstance(outcome, py.test.Item.Skipped): + elif isinstance(outcome, Skipped): return "skipped" - elif not isinstance(outcome, (list, py.test.Item.Passed)): + elif not isinstance(outcome, (list, Passed)): return "?" # -------------------- @@ -207,7 +208,7 @@ class TerminalSession(Session): def summaryline(self): outlist = [] sum = 0 - for typ in Item.Passed, Item.Failed, Item.Skipped: + for typ in Passed, Failed, Skipped: l = self.getitemoutcomepairs(typ) if l: outlist.append('%d %s' % (len(l), typ.__name__.lower())) @@ -232,7 +233,7 @@ class TerminalSession(Session): def skippedreasons(self): texts = {} - for colitem, outcome in self.getitemoutcomepairs(Item.Skipped): + for colitem, outcome in self.getitemoutcomepairs(Skipped): raisingtb = self.getlastvisible(outcome.excinfo.traceback) fn = raisingtb.frame.code.path lineno = raisingtb.lineno @@ -251,7 +252,7 @@ class TerminalSession(Session): def failures(self): if self.config.option.tbstyle == 'no': return # skip the detailed failure reports altogether - l = self.getitemoutcomepairs(Item.Failed) + l = self.getitemoutcomepairs(Failed) if l: self.out.sep('_') for colitem, outcome in l: diff --git a/py/test/testing/test_collect.py b/py/test/testing/test_collect.py index f66ddbd9b..c2a2bf21d 100644 --- a/py/test/testing/test_collect.py +++ b/py/test/testing/test_collect.py @@ -1,6 +1,7 @@ from __future__ import generators import py from setupdata import setupdatadir +from py.__.test.outcome import Skipped, Failed, Passed, Outcome def setup_module(mod): mod.datadir = setupdatadir() @@ -205,7 +206,7 @@ def test_custom_python_collection_from_conftest(): out = py.std.cStringIO.StringIO() session = config._getsessionclass()(config, out) session.main() - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert len(l) == 2 finally: old.chdir() @@ -215,7 +216,7 @@ def test_custom_python_collection_from_conftest(): out = py.std.cStringIO.StringIO() session = config._getsessionclass()(config, out) session.main() - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert len(l) == 2 def test_custom_NONpython_collection_from_conftest(): @@ -252,7 +253,7 @@ def test_custom_NONpython_collection_from_conftest(): out = py.std.cStringIO.StringIO() session = config._getsessionclass()(config, out) session.main() - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert len(l) == 1 finally: old.chdir() @@ -262,7 +263,7 @@ def test_custom_NONpython_collection_from_conftest(): out = py.std.cStringIO.StringIO() session = config._getsessionclass()(config, out) session.main() - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert len(l) == 1 def test_order_of_execution_generator_same_codeline(): diff --git a/py/test/testing/test_doctest.py b/py/test/testing/test_doctest.py index 657556c41..bc75a3082 100644 --- a/py/test/testing/test_doctest.py +++ b/py/test/testing/test_doctest.py @@ -1,6 +1,7 @@ import py from py.__.test.doctest import DoctestText +from py.__.test.outcome import Skipped, Failed, Passed, Outcome def test_simple_docteststring(): testitem = DoctestText(name="dummy", parent=None) @@ -19,7 +20,7 @@ def test_simple_docteststring_failing(): >>> i + 1 2 """) - py.test.raises(py.test.Item.Failed, "testitem.run()") + py.test.raises(Failed, "testitem.run()") def test_collect_doctest_files_with_test_prefix(): diff --git a/py/test/testing/test_session.py b/py/test/testing/test_session.py index f931a0340..ce02980af 100644 --- a/py/test/testing/test_session.py +++ b/py/test/testing/test_session.py @@ -1,5 +1,6 @@ import py from setupdata import setup_module # sets up global 'tmpdir' +from py.__.test.outcome import Skipped, Failed, Passed, Outcome implied_options = { '--pdb': 'usepdb and nocapture', @@ -44,9 +45,9 @@ def runfiletest(opts): config = py.test.config._reparse(opts + [datadir/'filetest.py']) session = config.initsession() session.main() - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 2 - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert not l class TestKeywordSelection: @@ -56,11 +57,11 @@ class TestKeywordSelection: '-k', keyword]) session = config._getsessionclass()(config, py.std.sys.stdout) session.main() - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 1 item = l[0][0] assert item.name == 'test_one' - l = session.getitemoutcomepairs(py.test.Item.Skipped) + l = session.getitemoutcomepairs(Skipped) assert len(l) == 1 def test_select_extra_keywords(self): @@ -86,10 +87,10 @@ class TestKeywordSelection: session = config._getsessionclass()(config, f) session.main() print "keyword", repr(keyword) - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert len(l) == 1 assert l[0][0].name == 'test_2' - l = session.getitemoutcomepairs(py.test.Item.Skipped) + l = session.getitemoutcomepairs(Skipped) assert l[0][0].name == 'test_1' class TestTerminalSession: @@ -104,13 +105,13 @@ class TestTerminalSession: def test_terminal(self): session = self.mainsession(datadir / 'filetest.py') out = self.file.getvalue() - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 2 assert out.find('2 failed') != -1 def test_syntax_error_module(self): session = self.mainsession(datadir / 'syntax_error.py') - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 1 out = self.file.getvalue() assert out.find(str('syntax_error.py')) != -1 @@ -120,9 +121,9 @@ class TestTerminalSession: session = self.mainsession("--exitfirst", datadir / 'filetest.py') assert session.config.option.exitfirst - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 1 - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert not l def test_collectonly(self): @@ -131,7 +132,7 @@ class TestTerminalSession: assert session.config.option.collectonly out = self.file.getvalue() #print out - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) #if l: # x = l[0][1].excinfo # print x.exconly() @@ -195,7 +196,7 @@ class TestTerminalSession: self._testmycapture = self._mycapture.reset() """)) session = self.mainsession(o) - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert len(l) == 1 item = l[0][0] assert hasattr(item, '_testmycapture') @@ -250,9 +251,9 @@ class TestTerminalSession: """)) session = self.mainsession(o) - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 0 - l = session.getitemoutcomepairs(py.test.Item.Passed) + l = session.getitemoutcomepairs(Passed) assert len(l) == 7 # also test listnames() here ... item, result = l[-1] @@ -273,7 +274,7 @@ class TestTerminalSession: a = 1 """)) session = self.mainsession(o) - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 1 item, outcome = l[0] assert str(outcome.excinfo).find('does_not_work') != -1 @@ -284,7 +285,7 @@ class TestTerminalSession: print 'Output of simulated "py.test brokenrepr.py":' print out - l = session.getitemoutcomepairs(py.test.Item.Failed) + l = session.getitemoutcomepairs(Failed) assert len(l) == 2 assert out.find("""[Exception("Ha Ha fooled you, I'm a broken repr().") raised in repr()]""") != -1 #' assert out.find("[unknown exception raised in repr()]") != -1