Skip to content

Commit

Permalink
Merge 7f0ae98 into c3c9608
Browse files Browse the repository at this point in the history
  • Loading branch information
carsongee committed Mar 20, 2020
2 parents c3c9608 + 7f0ae98 commit 325369f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 58 deletions.
1 change: 1 addition & 0 deletions .#tox.ini
143 changes: 86 additions & 57 deletions pytest_pylint/tests/test_pytest_pylint.py
Expand Up @@ -3,6 +3,7 @@
Unit testing module for pytest-pylint plugin
"""
import os
from textwrap import dedent

import mock
import pytest
Expand All @@ -13,7 +14,7 @@

def test_basic(testdir):
"""Verify basic pylint checks"""
testdir.makepyfile("""import sys""")
testdir.makepyfile('import sys')
result = testdir.runpytest('--pylint')
assert 'Missing module docstring' in result.stdout.str()
assert 'Unused import sys' in result.stdout.str()
Expand All @@ -27,7 +28,7 @@ def test_subdirectories(testdir):
"""Verify pylint checks files in subdirectories"""
subdir = testdir.mkpydir('mymodule')
testfile = subdir.join("test_file.py")
testfile.write("""import sys""")
testfile.write('import sys')
result = testdir.runpytest('--pylint')
assert '[pylint] mymodule/test_file.py' in result.stdout.str()
assert 'Missing module docstring' in result.stdout.str()
Expand All @@ -39,27 +40,30 @@ def test_subdirectories(testdir):

def test_disable(testdir):
"""Verify basic pylint checks"""
testdir.makepyfile("""import sys""")
result = testdir.runpytest('--pylint', '--no-pylint')
testdir.makepyfile('import sys')
result = testdir.runpytest('--pylint --no-pylint')
assert 'Final newline missing' not in result.stdout.str()
assert 'Linting files' not in result.stdout.str()


def test_error_control(testdir):
"""Verify that error types are configurable"""
testdir.makepyfile("""import sys""")
testdir.makepyfile('import sys')
result = testdir.runpytest('--pylint', '--pylint-error-types=EF')
assert '1 passed' in result.stdout.str()


def test_pylintrc_file(testdir):
"""Verify that a specified pylint rc file will work."""
rcfile = testdir.makefile('rc', """
[FORMAT]
rcfile = testdir.makefile(
'rc',
"""
[FORMAT]
max-line-length=3
""")
testdir.makepyfile("""import sys""")
max-line-length=3
"""
)
testdir.makepyfile('import sys')
result = testdir.runpytest(
'--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
)
Expand All @@ -68,11 +72,14 @@ def test_pylintrc_file(testdir):

def test_pylintrc_file_toml(testdir):
"""Verify that pyproject.toml can be used as a pylint rc file."""
rcfile = testdir.makefile('.toml', """
[tool.pylint.FORMAT]
max-line-length = "3"
""")
testdir.makepyfile("""import sys""")
rcfile = testdir.makefile(
'.toml',
"""
[tool.pylint.FORMAT]
max-line-length = 3
"""
)
testdir.makepyfile('import sys')
result = testdir.runpytest(
'--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
)
Expand All @@ -87,19 +94,21 @@ def test_pylintrc_file_beside_ini(testdir):
non_cwd_dir = testdir.mkdir('non_cwd_dir')

rcfile = non_cwd_dir.join('foo.rc')
rcfile.write("""
[FORMAT]
max-line-length=3
""")
rcfile.write(
"""
[FORMAT]
max-line-length=3
""")
inifile = non_cwd_dir.join('foo.ini')
inifile.write("""
[pytest]
addopts = --pylint --pylint-rcfile={0}
""".format(rcfile.basename))
inifile.write(dedent(
"""
[pytest]
addopts = --pylint --pylint-rcfile={0}
""".format(rcfile.basename)
))

pyfile = testdir.makepyfile("""import sys""")
pyfile = testdir.makepyfile('import sys')

result = testdir.runpytest(
pyfile.strpath
Expand All @@ -116,22 +125,31 @@ def test_pylintrc_file_beside_ini(testdir):
def test_pylintrc_ignore(testdir, rcformat):
"""Verify that a pylintrc file with ignores will work."""
if rcformat == "toml":
rcfile = testdir.makefile('toml', """
[tool.pylint.master]
ignore = ["test_pylintrc_ignore.py", "foo.py"]
""")
rcfile = testdir.makefile(
'toml',
"""
[tool.pylint.master]
ignore = ["test_pylintrc_ignore.py", "foo.py"]
"""
)
elif rcformat == "simple_toml":
rcfile = testdir.makefile('toml', """
[tool.pylint.MASTER]
ignore = "test_pylintrc_ignore.py,foo.py"
""")
rcfile = testdir.makefile(
'toml',
"""
[tool.pylint.MASTER]
ignore = "test_pylintrc_ignore.py,foo.py"
"""
)
else:
rcfile = testdir.makefile('rc', """
[MASTER]
rcfile = testdir.makefile(
'rc',
"""
[MASTER]
ignore = test_pylintrc_ignore.py
""")
testdir.makepyfile("""import sys""")
ignore = test_pylintrc_ignore.py
"""
)
testdir.makepyfile('import sys')
result = testdir.runpytest(
'--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
)
Expand All @@ -142,17 +160,23 @@ def test_pylintrc_ignore(testdir, rcformat):
def test_pylintrc_msg_template(testdir, rcformat):
"""Verify that msg-template from pylintrc file is handled."""
if rcformat == "toml":
rcfile = testdir.makefile('toml', """
[tool.pylint.REPORTS]
msg-template = "start {msg_id} end"
""")
rcfile = testdir.makefile(
'toml',
"""
[tool.pylint.REPORTS]
msg-template = "start {msg_id} end"
"""
)
else:
rcfile = testdir.makefile('rc', """
[REPORTS]
rcfile = testdir.makefile(
'rc',
"""
[REPORTS]
msg-template=start {msg_id} end
""")
testdir.makepyfile("""import sys""")
msg-template=start {msg_id} end
"""
)
testdir.makepyfile('import sys')
result = testdir.runpytest(
'--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
)
Expand All @@ -163,7 +187,7 @@ def test_multiple_jobs(testdir):
"""
Assert that the jobs argument is passed through to pylint if provided
"""
testdir.makepyfile("""import sys""")
testdir.makepyfile('import sys')
with mock.patch('pytest_pylint.plugin.lint.Run') as run_mock:
jobs = 0
testdir.runpytest(
Expand All @@ -177,7 +201,7 @@ def test_no_multiple_jobs(testdir):
"""
If no jobs argument is specified it should not appear in pylint arguments
"""
testdir.makepyfile("""import sys""")
testdir.makepyfile('import sys')
with mock.patch('pytest_pylint.plugin.lint.Run') as run_mock:
testdir.runpytest('--pylint')
assert run_mock.call_count == 1
Expand Down Expand Up @@ -212,7 +236,7 @@ def test_skip_checked_files(testdir):

def test_output_file(testdir):
"""Verify basic pylint checks"""
testdir.makepyfile("""import sys""")
testdir.makepyfile('import sys')
testdir.runpytest('--pylint', '--pylint-output-file=pylint.report')
output_file = os.path.join(testdir.tmpdir.strpath, 'pylint.report')
assert os.path.isfile(output_file)
Expand Down Expand Up @@ -242,7 +266,7 @@ def test_output_file(testdir):
], ids=['ignore', 'ignore-patterns'])
def test_cmd_line_ignore(testdir, arg_opt_name, arg_opt_value):
"""Verify that cmd line args ignores will work."""
testdir.makepyfile(test_cmd_line_ignore="""import sys""")
testdir.makepyfile(test_cmd_line_ignore='import sys')
result = testdir.runpytest(
'--pylint', '--pylint-{0}={1}'.format(arg_opt_name, arg_opt_value)
)
Expand All @@ -255,17 +279,22 @@ def test_cmd_line_ignore(testdir, arg_opt_name, arg_opt_value):
('ignore-patterns', '.*arg.py$'),
], ids=['ignore', 'ignore-patterns'])
def test_cmd_line_ignore_pri(testdir, arg_opt_name, arg_opt_value):
"""Verify that command line ignores and patterns take priority over
rcfile ignores."""
"""
Verify that command line ignores and patterns take priority over
rcfile ignores.
"""
file_ignore = 'test_cmd_line_ignore_pri_file.py'
cmd_arg_ignore = 'test_cmd_line_ignore_pri_arg.py'
cmd_line_ignore = arg_opt_value

rcfile = testdir.makefile('rc', """
[MASTER]
rcfile = testdir.makefile(
'rc',
"""
[MASTER]
{0} = {1},foo
""".format(arg_opt_name, file_ignore))
{0} = {1},foo
""".format(arg_opt_name, file_ignore)
)
testdir.makepyfile(**{
file_ignore: 'import sys',
cmd_arg_ignore: 'import os',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -5,11 +5,11 @@ skip_missing_interpreters =
[testenv]
usedevelop = true
deps =
pylint
pytest
pytest-pep8
coverage
mock
https://github.com/PyCQA/pylint/archive/master.tar.gz
commands =
coverage erase
coverage run -m py.test {posargs}
Expand Down

0 comments on commit 325369f

Please sign in to comment.