Skip to content

Commit

Permalink
Merge pull request #2596 from nicoddemus/autopep-tox
Browse files Browse the repository at this point in the history
Add "fix-lint" tox environment
  • Loading branch information
RonnyPfannschmidt authored Jul 21, 2017
2 parents da12c52 + 3c28a8e commit ccc4b3a
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 49 deletions.
7 changes: 6 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ but here is a simple overview:
$ tox -e linting,py27,py36

This command will run tests via the "tox" tool against Python 2.7 and 3.6
and also perform "lint" coding-style checks.
and also perform "lint" coding-style checks. If you have too much linting errors,
try running::

$ tox -e fix-lint

To fix pep8 related errors.

#. You can now edit your local working copy.

Expand Down
1 change: 1 addition & 0 deletions changelog/2375.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing ``encoding`` attribute to ``sys.std*`` streams when using ``capsys`` capture mode.
1 change: 0 additions & 1 deletion changelog/2375.trivial

This file was deleted.

2 changes: 1 addition & 1 deletion changelog/2533.trivial
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Renamed the utility function `_pytest.compat._escape_strings` to `_ascii_escaped` to better communicate the function's purpose.
Renamed the utility function ``_pytest.compat._escape_strings`` to ``_ascii_escaped`` to better communicate the function's purpose.
2 changes: 1 addition & 1 deletion changelog/2562.trivial
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Emit yield test warning only once per generator
Emit warning about ``yield`` tests being deprecated only once per generator.
2 changes: 1 addition & 1 deletion changelog/2574.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The options --fixtures and --fixtures-per-test will now keep indentation within docstrings.
The options ```--fixtures`` and ```--fixtures-per-test`` will now keep indentation within docstrings.
2 changes: 1 addition & 1 deletion changelog/2581.trivial
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fixed all flake8 errors and warnings
Fixed all flake8 errors and warnings.
1 change: 1 addition & 0 deletions changelog/2582.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``fix-lint`` tox environment to run automatic pep8 fixes on the code.
16 changes: 8 additions & 8 deletions testing/code/test_excinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def xyz():
xyz()
""")
try:
exec (source.compile())
exec(source.compile())
except NameError:
tb = _pytest._code.ExceptionInfo().traceback
print (tb[-1].getsource())
print(tb[-1].getsource())
s = str(tb[-1].getsource())
assert s.startswith("def xyz():\n try:")
assert s.strip().endswith("except somenoname:")
Expand Down Expand Up @@ -341,7 +341,7 @@ def test_excinfo_errisinstance():

def test_excinfo_no_sourcecode():
try:
exec ("raise ValueError()")
exec("raise ValueError()")
except ValueError:
excinfo = _pytest._code.ExceptionInfo()
s = str(excinfo.traceback[-1])
Expand Down Expand Up @@ -431,7 +431,7 @@ def importasmod(source):
def excinfo_from_exec(self, source):
source = _pytest._code.Source(source).strip()
try:
exec (source.compile())
exec(source.compile())
except KeyboardInterrupt:
raise
except:
Expand Down Expand Up @@ -471,7 +471,7 @@ def test_repr_source_not_existing(self):
pr = FormattedExcinfo()
co = compile("raise ValueError()", "", "exec")
try:
exec (co)
exec(co)
except ValueError:
excinfo = _pytest._code.ExceptionInfo()
repr = pr.repr_excinfo(excinfo)
Expand All @@ -486,7 +486,7 @@ def test_repr_many_line_source_not_existing(self):
raise ValueError()
""", "", "exec")
try:
exec (co)
exec(co)
except ValueError:
excinfo = _pytest._code.ExceptionInfo()
repr = pr.repr_excinfo(excinfo)
Expand Down Expand Up @@ -992,7 +992,7 @@ def i():
tw = TWMock()
r.toterminal(tw)
for line in tw.lines:
print (line)
print(line)
assert tw.lines[0] == ""
assert tw.lines[1] == " def f():"
assert tw.lines[2] == "> g()"
Expand Down Expand Up @@ -1040,7 +1040,7 @@ def h():
tw = TWMock()
r.toterminal(tw)
for line in tw.lines:
print (line)
print(line)
assert tw.lines[0] == ""
assert tw.lines[1] == " def f():"
assert tw.lines[2] == " try:"
Expand Down
19 changes: 2 additions & 17 deletions testing/code/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ def f(x):
def test_compile(self):
co = _pytest._code.compile("x=3")
d = {}
exec (co, d)
exec(co, d)
assert d['x'] == 3

def test_compile_and_getsource_simple(self):
co = _pytest._code.compile("x=3")
exec (co)
exec(co)
source = _pytest._code.Source(co)
assert str(source) == "x=3"

Expand Down Expand Up @@ -335,21 +335,6 @@ def __init__(self, *args):
assert len(l) == 1


def test_getstartingblock_multiline():
class A(object):
def __init__(self, *args):
frame = sys._getframe(1)
self.source = _pytest._code.Frame(frame).statement

x = A('x',
'y'
,
'z')

l = [i for i in x.source.lines if i.strip()]
assert len(l) == 4


def test_getline_finally():
def c(): pass
excinfo = pytest.raises(TypeError, """
Expand Down
26 changes: 26 additions & 0 deletions testing/code/test_source_multiline_block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# flake8: noqa
import sys

import _pytest._code


def test_getstartingblock_multiline():
"""
This test was originally found in test_source.py, but it depends on the weird
formatting of the ``x = A`` construct seen here and our autopep8 tool can only exclude entire
files (it does not support excluding lines/blocks using the traditional #noqa comment yet,
see hhatto/autopep8#307). It was considered better to just move this single test to its own
file and exclude it from autopep8 than try to complicate things.
"""
class A(object):
def __init__(self, *args):
frame = sys._getframe(1)
self.source = _pytest._code.Frame(frame).statement

x = A('x',
'y'
,
'z')

l = [i for i in x.source.lines if i.strip()]
assert len(l) == 4
28 changes: 14 additions & 14 deletions testing/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ def test_capturing_basic_api(self, method):
assert outerr == ("", "")
outerr = capman.suspendcapture()
assert outerr == ("", "")
print ("hello")
print("hello")
out, err = capman.suspendcapture()
if method == "no":
assert old == (sys.stdout, sys.stderr, sys.stdin)
else:
assert not out
capman.resumecapture()
print ("hello")
print("hello")
out, err = capman.suspendcapture()
if method != "no":
assert out == "hello\n"
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_logging():
stream.close() # to free memory/release resources
""")
result = testdir.runpytest_subprocess(p)
result.stderr.str().find("atexit") == -1
assert result.stderr.str().find("atexit") == -1

def test_logging_and_immediate_setupteardown(self, testdir):
p = testdir.makepyfile("""
Expand All @@ -305,7 +305,7 @@ def teardown_function(function):
assert 0
""")
for optargs in (('--capture=sys',), ('--capture=fd',)):
print (optargs)
print(optargs)
result = testdir.runpytest_subprocess(p, *optargs)
s = result.stdout.str()
result.stdout.fnmatch_lines([
Expand All @@ -331,7 +331,7 @@ def teardown_module(function):
assert 0
""")
for optargs in (('--capture=sys',), ('--capture=fd',)):
print (optargs)
print(optargs)
result = testdir.runpytest_subprocess(p, *optargs)
s = result.stdout.str()
result.stdout.fnmatch_lines([
Expand Down Expand Up @@ -879,7 +879,7 @@ def test_capturing_reset_simple(self):

def test_capturing_readouterr(self):
with self.getcapture() as cap:
print ("hello world")
print("hello world")
sys.stderr.write("hello error\n")
out, err = cap.readouterr()
assert out == "hello world\n"
Expand All @@ -890,7 +890,7 @@ def test_capturing_readouterr(self):

def test_capturing_readouterr_unicode(self):
with self.getcapture() as cap:
print ("hx\xc4\x85\xc4\x87")
print("hx\xc4\x85\xc4\x87")
out, err = cap.readouterr()
assert out == py.builtin._totext("hx\xc4\x85\xc4\x87\n", "utf8")

Expand All @@ -905,7 +905,7 @@ def test_capturing_readouterr_decode_error_handling(self):

def test_reset_twice_error(self):
with self.getcapture() as cap:
print ("hello")
print("hello")
out, err = cap.readouterr()
pytest.raises(ValueError, cap.stop_capturing)
assert out == "hello\n"
Expand All @@ -919,7 +919,7 @@ def test_capturing_modify_sysouterr_in_between(self):
sys.stderr.write("world")
sys.stdout = capture.CaptureIO()
sys.stderr = capture.CaptureIO()
print ("not seen")
print("not seen")
sys.stderr.write("not seen\n")
out, err = cap.readouterr()
assert out == "hello"
Expand All @@ -929,9 +929,9 @@ def test_capturing_modify_sysouterr_in_between(self):

def test_capturing_error_recursive(self):
with self.getcapture() as cap1:
print ("cap1")
print("cap1")
with self.getcapture() as cap2:
print ("cap2")
print("cap2")
out2, err2 = cap2.readouterr()
out1, err1 = cap1.readouterr()
assert out1 == "cap1\n"
Expand Down Expand Up @@ -961,9 +961,9 @@ def test_stdin_restored(self):
assert sys.stdin is old

def test_stdin_nulled_by_default(self):
print ("XXX this test may well hang instead of crashing")
print ("XXX which indicates an error in the underlying capturing")
print ("XXX mechanisms")
print("XXX this test may well hang instead of crashing")
print("XXX which indicates an error in the underlying capturing")
print("XXX mechanisms")
with self.getcapture():
pytest.raises(IOError, "sys.stdin.read()")

Expand Down
4 changes: 2 additions & 2 deletions testing/test_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ def test_no_conftest(fxtr):
# use value from parent dir's
"""))
print ("created directory structure:")
print("created directory structure:")
for x in testdir.tmpdir.visit():
print (" " + x.relto(testdir.tmpdir))
print(" " + x.relto(testdir.tmpdir))

return {
"runner": runner,
Expand Down
4 changes: 2 additions & 2 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def teardown_function(func):
raise ValueError(42)
""")
reps = rec.getreports("pytest_runtest_logreport")
print (reps)
print(reps)
for i in range(2):
assert reps[i].nodeid.endswith("test_method")
assert reps[i].passed
Expand All @@ -253,7 +253,7 @@ def test_method(self):
assert True
""")
reps = rec.getreports("pytest_runtest_logreport")
print (reps)
print(reps)
assert len(reps) == 3
#
assert reps[0].nodeid.endswith("test_method")
Expand Down
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ commands =
rm -rf /tmp/doc-exec*
make regen

[testenv:fix-lint]
skipsdist = True
usedevelop = True
deps =
autopep8
commands =
autopep8 --in-place -r --max-line-length=120 --exclude=vendored_packages,test_source_multiline_block.py _pytest testing

[testenv:jython]
changedir = testing
commands =
Expand Down

0 comments on commit ccc4b3a

Please sign in to comment.