[py-svn] commit/pytest-codecheckers: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Thu Jun 21 12:57:57 CEST 2012
2 new commits in pytest-codecheckers:
https://bitbucket.org/RonnyPfannschmidt/pytest-codecheckers/changeset/4a027892c04e/
changeset: 4a027892c04e
user: RonnyPfannschmidt
date: 2012-06-21 12:42:42
summary: complete cleanup
affected #: 4 files
diff -r d40bf6cb8f5b3b832755cdfa5b94622529696140 -r 4a027892c04e4dc49954f81ccc13d5fb9e563100 codecheckers/flakes.py
--- a/codecheckers/flakes.py
+++ b/codecheckers/flakes.py
@@ -2,6 +2,7 @@
from pyflakes.checker import Binding, Assignment
+
def assignment_monkeypatched_init(self, name, source):
Binding.__init__(self, name, source)
if name == '__tracebackhide__':
@@ -9,6 +10,6 @@
Assignment.__init__ = assignment_monkeypatched_init
-def check_file(path, filename, io):
- return pyflakes_check(path.read(), filename, io)
+def check_file(path, filename):
+ return pyflakes_check(path.read(), filename)
diff -r d40bf6cb8f5b3b832755cdfa5b94622529696140 -r 4a027892c04e4dc49954f81ccc13d5fb9e563100 codecheckers/pep.py
--- a/codecheckers/pep.py
+++ b/codecheckers/pep.py
@@ -1,29 +1,8 @@
-import sys
import pep8
-class PyTestChecker(pep8.Checker):
- ignored_errors = 0
- def report_error(self, line_number, offset, text, check):
- #XXX: pep8 is a retarded module!
- if pep8.ignore_code(text[:4]):
- self.ignored_errors += 1
- pep8.Checker.report_error(self, line_number, offset, text, check)
-def check_file(path, filename, io):
- oldio = sys.stdout, sys.stderr
- try:
- sys.stdout = sys.stderr = io
- pep8.process_options(['pep8',
- # ignore list taken from moin
- '--ignore=E202,E221,E222,E241,E301,E302,E401,E501,E701,W391,W601,W602',
- '--show-source',
- '--repeat',
- 'dummy file',
- ])
- checker = PyTestChecker(filename, path.readlines())
- #XXX: bails out on death
- error_count = checker.check_all()
- ignored = checker.ignored_errors
- return max(error_count - ignored, 0)
- finally:
- sys.stdout , sys.stderr = oldio
+def check_file(path, filename):
+ checker = pep8.Checker(filename, path.readlines(),
+ show_source=True,
+ repeat=True)
+ return checker.check_all()
diff -r d40bf6cb8f5b3b832755cdfa5b94622529696140 -r 4a027892c04e4dc49954f81ccc13d5fb9e563100 codecheckers/plugin.py
--- a/codecheckers/plugin.py
+++ b/codecheckers/plugin.py
@@ -3,6 +3,13 @@
import pkg_resources
+class FoundErrors(Exception):
+ def __init__(self, count, out, err):
+ self.count = count
+ self.out = out
+ self.err = err
+
+
class PyCodeCheckItem(py.test.collect.Item):
def __init__(self, ep, parent):
py.test.collect.Item.__init__(self, ep.name, parent)
@@ -11,29 +18,20 @@
self._ep = ep
def runtest(self):
- mod = self._ep.load()
- io = py.io.BytesIO()
+ check = self._ep.load().check_file
+ call = py.io.StdCapture.call
- try:
- found_errors = mod.check_file(self.fspath, self.filename, io)
- self.out = io.getvalue()
- except:
- found_errors = True
- self.info = py.code.ExceptionInfo()
- assert not found_errors
+ found_errors, out, err = call(check, self.fspath, self.filename)
+ if found_errors:
+ raise FoundErrors(FoundErrors, out, err)
- def repr_failure(self, exc_info):
- try:
- return self.out
- except AttributeError:
- #XXX: internal error ?!
- self.info = py.code.ExceptionInfo()
- info = getattr(self, 'info', exc_info)
- return super(PyCodeCheckItem, self).repr_failure(info)
+ def repr_failure(self, excinfo):
+ if excinfo.errisinstance(FoundErrors):
+ return excinfo.value.out
+ return super(PyCodeCheckItem, self).repr_failure(excinfo)
def reportinfo(self):
- return (self.fspath, -1, "codecheck %s %s" % (
- self._ep.name, self.filename))
+ return (self.fspath, -1, "codecheck " + self._ep.name)
class PyCheckerCollector(py.test.collect.File):
@@ -46,9 +44,8 @@
return []
checkers = self.config.getini('codechecks')
entrypoints = pkg_resources.iter_entry_points('codechecker')
-
- items = [PyCodeCheckItem(ep, self) for ep in entrypoints if ep.name in checkers]
- return items
+ wanted = (ep for ep in entrypoints if ep.name in checkers)
+ return [PyCodeCheckItem(wep, self) for wep in wanted]
def pytest_collect_file(path, parent):
@@ -57,5 +54,7 @@
def pytest_addoption(parser):
- parser.addini('codechecks', type='args', help='listings of the codechecks to use')
+ parser.addini('codechecks', type='args',
+ help='listings of the codechecks to use',
+ default=['pep8', 'pyflakes'])
parser.addoption('--no-codechecks', action='store_true')
diff -r d40bf6cb8f5b3b832755cdfa5b94622529696140 -r 4a027892c04e4dc49954f81ccc13d5fb9e563100 tests/test_pyflakes.py
--- a/tests/test_pyflakes.py
+++ b/tests/test_pyflakes.py
@@ -16,7 +16,7 @@
out.stdout.fnmatch_lines([
'*abc*',
'*1 failed*',
- ])
+ ])
def test_reportinfo_verbose(testdir):
@@ -27,4 +27,4 @@
out = testdir.runpytest('-v')
out.stdout.fnmatch_lines([
'*test_reportinfo_verbose.py:0: codecheck pyflakes PASSED',
- ])
+ ])
https://bitbucket.org/RonnyPfannschmidt/pytest-codecheckers/changeset/069dd9d1aead/
changeset: 069dd9d1aead
user: RonnyPfannschmidt
date: 2012-06-21 12:43:16
summary: add .cache to hgignore
affected #: 1 file
diff -r 4a027892c04e4dc49954f81ccc13d5fb9e563100 -r 069dd9d1aead5de036a5c315be204e774272bbb4 .hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -2,4 +2,5 @@
build
dist
.*\.pyc
+.cache
\.tox
Repository URL: https://bitbucket.org/RonnyPfannschmidt/pytest-codecheckers/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the pytest-commit
mailing list