diff options
author | 2011-04-28 17:36:28 +0200 | |
---|---|---|
committer | 2011-04-28 17:36:28 +0200 | |
commit | 5be2e48cfd19937177b8967fca4864d4aa14b6e2 (patch) | |
tree | ab4eeae369b009a1e010d78e9cdc562234fc7637 /_pytest | |
parent | add the possibility to ignore the matching of arguments (diff) | |
download | pypy-5be2e48cfd19937177b8967fca4864d4aa14b6e2.tar.gz pypy-5be2e48cfd19937177b8967fca4864d4aa14b6e2.tar.bz2 pypy-5be2e48cfd19937177b8967fca4864d4aa14b6e2.zip |
use actually released pytest-2.0.3 / py-1.4.3 versions
(minor fixes compared to the versions pypy already used)
Diffstat (limited to '_pytest')
-rw-r--r-- | _pytest/__init__.py | 2 | ||||
-rw-r--r-- | _pytest/assertion.py | 6 | ||||
-rw-r--r-- | _pytest/config.py | 7 | ||||
-rw-r--r-- | _pytest/core.py | 11 | ||||
-rw-r--r-- | _pytest/junitxml.py | 44 | ||||
-rw-r--r-- | _pytest/main.py | 2 | ||||
-rw-r--r-- | _pytest/pytester.py | 5 | ||||
-rw-r--r-- | _pytest/resultlog.py | 2 | ||||
-rw-r--r-- | _pytest/tmpdir.py | 7 |
9 files changed, 68 insertions, 18 deletions
diff --git a/_pytest/__init__.py b/_pytest/__init__.py index c6d7f1f945..9d797be039 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.0.3.dev3' +__version__ = '2.0.3' diff --git a/_pytest/assertion.py b/_pytest/assertion.py index e2578242a9..d40981c32b 100644 --- a/_pytest/assertion.py +++ b/_pytest/assertion.py @@ -16,7 +16,8 @@ def pytest_configure(config): # py._code._assertionnew to detect this plugin was loaded and in # turn call the hooks defined here as part of the # DebugInterpreter. - config._monkeypatch = m = monkeypatch() + m = monkeypatch() + config._cleanup.append(m.undo) warn_about_missing_assertion() if not config.getvalue("noassert") and not config.getvalue("nomagic"): def callbinrepr(op, left, right): @@ -29,9 +30,6 @@ def pytest_configure(config): 'AssertionError', py.code._AssertionError) m.setattr(py.code, '_reprcompare', callbinrepr) -def pytest_unconfigure(config): - config._monkeypatch.undo() - def warn_about_missing_assertion(): try: assert False diff --git a/_pytest/config.py b/_pytest/config.py index 79a26afb4a..6e0cfea1a3 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -12,6 +12,10 @@ def pytest_cmdline_parse(pluginmanager, args): config.trace.root.setwriter(sys.stderr.write) return config +def pytest_unconfigure(config): + for func in config._cleanup: + func() + class Parser: """ Parser for command line arguments. """ @@ -251,7 +255,8 @@ class Config(object): self._conftest = Conftest(onimport=self._onimportconftest) self.hook = self.pluginmanager.hook self._inicache = {} - + self._cleanup = [] + @classmethod def fromdictargs(cls, option_dict, args): """ constructor useable for subprocesses. """ diff --git a/_pytest/core.py b/_pytest/core.py index abe7a26de6..2087a84015 100644 --- a/_pytest/core.py +++ b/_pytest/core.py @@ -265,8 +265,15 @@ class PluginManager(object): config.hook.pytest_unconfigure(config=config) config.pluginmanager.unregister(self) - def notify_exception(self, excinfo): - excrepr = excinfo.getrepr(funcargs=True, showlocals=True) + def notify_exception(self, excinfo, option=None): + if option and option.fulltrace: + style = "long" + else: + style = "native" + excrepr = excinfo.getrepr(funcargs=True, + showlocals=getattr(option, 'showlocals', False), + style=style, + ) res = self.hook.pytest_internalerror(excrepr=excrepr) if not py.builtin.any(res): for line in str(excrepr).split("\n"): diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index d28b19efb3..d92842db0e 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -5,8 +5,42 @@ Based on initial code from Ross Lawley. import py import os +import re +import sys import time + +# Python 2.X and 3.X compatibility +try: + unichr(65) +except NameError: + unichr = chr +try: + unicode('A') +except NameError: + unicode = str +try: + long(1) +except NameError: + long = int + + +# We need to get the subset of the invalid unicode ranges according to +# XML 1.0 which are valid in this python build. Hence we calculate +# this dynamically instead of hardcoding it. The spec range of valid +# chars is: Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] +# | [#x10000-#x10FFFF] +_illegal_unichrs = [(0x00, 0x08), (0x0B, 0x0C), (0x0E, 0x19), + (0xD800, 0xDFFF), (0xFDD0, 0xFFFF)] +_illegal_ranges = [unicode("%s-%s") % (unichr(low), unichr(high)) + for (low, high) in _illegal_unichrs + if low < sys.maxunicode] +illegal_xml_re = re.compile(unicode('[%s]') % + unicode('').join(_illegal_ranges)) +del _illegal_unichrs +del _illegal_ranges + + def pytest_addoption(parser): group = parser.getgroup("terminal reporting") group.addoption('--junitxml', action="store", dest="xmlpath", @@ -28,6 +62,7 @@ def pytest_unconfigure(config): del config._xml config.pluginmanager.unregister(xml) + class LogXML(object): def __init__(self, logfile, prefix): self.logfile = logfile @@ -55,7 +90,14 @@ class LogXML(object): self.test_logs.append("</testcase>") def appendlog(self, fmt, *args): - args = tuple([py.xml.escape(arg) for arg in args]) + def repl(matchobj): + i = ord(matchobj.group()) + if i <= 0xFF: + return unicode('#x%02X') % i + else: + return unicode('#x%04X') % i + args = tuple([illegal_xml_re.sub(repl, py.xml.escape(arg)) + for arg in args]) self.test_logs.append(fmt % args) def append_pass(self, report): diff --git a/_pytest/main.py b/_pytest/main.py index d7948c6faf..f73ff597a0 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -71,7 +71,7 @@ def pytest_cmdline_main(config): session.exitstatus = EXIT_INTERRUPTED except: excinfo = py.code.ExceptionInfo() - config.pluginmanager.notify_exception(excinfo) + config.pluginmanager.notify_exception(excinfo, config.option) session.exitstatus = EXIT_INTERNALERROR if excinfo.errisinstance(SystemExit): sys.stderr.write("mainloop: caught Spurious SystemExit!\n") diff --git a/_pytest/pytester.py b/_pytest/pytester.py index f9da97b188..619bba9886 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -236,13 +236,14 @@ class TmpTestdir: def _makefile(self, ext, args, kwargs): items = list(kwargs.items()) if args: - source = "\n".join(map(str, args)) + "\n" + source = py.builtin._totext("\n").join( + map(py.builtin._totext, args)) + py.builtin._totext("\n") basename = self.request.function.__name__ items.insert(0, (basename, source)) ret = None for name, value in items: p = self.tmpdir.join(name).new(ext=ext) - source = str(py.code.Source(value)).lstrip() + source = py.builtin._totext(py.code.Source(value)).lstrip() p.write(source.encode("utf-8"), "wb") if ret is None: ret = p diff --git a/_pytest/resultlog.py b/_pytest/resultlog.py index 2606ff48ab..7f879cce59 100644 --- a/_pytest/resultlog.py +++ b/_pytest/resultlog.py @@ -74,7 +74,7 @@ class ResultLog(object): elif report.failed: longrepr = str(report.longrepr) elif report.skipped: - longrepr = str(report.longrepr) + longrepr = str(report.longrepr[2]) self.log_outcome(report, code, longrepr) def pytest_collectreport(self, report): diff --git a/_pytest/tmpdir.py b/_pytest/tmpdir.py index 2fd9992ccf..e46c713eb0 100644 --- a/_pytest/tmpdir.py +++ b/_pytest/tmpdir.py @@ -48,15 +48,12 @@ class TempdirHandler: self.trace("finish") def pytest_configure(config): - config._mp = mp = monkeypatch() + mp = monkeypatch() t = TempdirHandler(config) + config._cleanup.extend([mp.undo, t.finish]) mp.setattr(config, '_tmpdirhandler', t, raising=False) mp.setattr(pytest, 'ensuretemp', t.ensuretemp, raising=False) -def pytest_unconfigure(config): - config._tmpdirhandler.finish() - config._mp.undo() - def pytest_funcarg__tmpdir(request): """return a temporary directory path object which is unique to each test function invocation, |