mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 05:26:53 +00:00
Fix --output-file regression
This commit is contained in:
parent
b4d2850192
commit
4888eb65c5
5 changed files with 29 additions and 25 deletions
|
|
@ -246,3 +246,17 @@ def test_file_not_found(tmpdir, capsys):
|
|||
out, err = capsys.readouterr()
|
||||
assert out.startswith("i-do-not-exist:0:1: E902")
|
||||
assert err == ""
|
||||
|
||||
|
||||
def test_output_file(tmpdir, capsys):
|
||||
"""Ensure that --output-file is honored."""
|
||||
tmpdir.join('t.py').write('import os\n')
|
||||
|
||||
with tmpdir.as_cwd():
|
||||
_call_main(['t.py', '--output-file=f'], retv=1)
|
||||
|
||||
out, err = capsys.readouterr()
|
||||
assert out == err == ""
|
||||
|
||||
expected = "t.py:1:1: F401 'os' imported but unused\n"
|
||||
assert tmpdir.join('f').read() == expected
|
||||
|
|
|
|||
|
|
@ -79,28 +79,22 @@ def test_returns_specified_plugin(application):
|
|||
|
||||
def test_prelim_opts_args(application):
|
||||
"""Verify we get sensible prelim opts and args."""
|
||||
opts, args = application.parse_preliminary_options(
|
||||
opts = application.parse_preliminary_options(
|
||||
['--foo', '--verbose', 'src', 'setup.py', '--statistics', '--version'])
|
||||
|
||||
assert opts.verbose
|
||||
assert args == ['--foo', 'src', 'setup.py', '--statistics', '--version']
|
||||
|
||||
|
||||
def test_prelim_opts_ignore_help(application):
|
||||
"""Verify -h/--help is not handled."""
|
||||
# GIVEN
|
||||
|
||||
# WHEN
|
||||
_, args = application.parse_preliminary_options(['--help', '-h'])
|
||||
|
||||
# THEN
|
||||
assert args == ['--help', '-h']
|
||||
# normally argparse would `SystemExit` on `--help`
|
||||
application.parse_preliminary_options(['--help', '-h'])
|
||||
|
||||
|
||||
def test_prelim_opts_handles_empty(application):
|
||||
"""Verify empty argv lists are handled correctly."""
|
||||
irrelevant_args = ['myexe', '/path/to/foo']
|
||||
# this would set `.verbose` but we validate that it does not
|
||||
irrelevant_args = ['--verbose']
|
||||
with mock.patch.object(sys, 'argv', irrelevant_args):
|
||||
opts, args = application.parse_preliminary_options([])
|
||||
|
||||
assert args == []
|
||||
opts = application.parse_preliminary_options([])
|
||||
assert not opts.verbose
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ def test_get_style_guide():
|
|||
verbose=0,
|
||||
)
|
||||
mockedapp = mock.Mock()
|
||||
mockedapp.parse_preliminary_options.return_value = (prelim_opts, [])
|
||||
mockedapp.parse_preliminary_options.return_value = prelim_opts
|
||||
mockedapp.program = 'flake8'
|
||||
with mock.patch('flake8.api.legacy.config.ConfigFileFinder') as mock_config_finder: # noqa: E501
|
||||
config_finder = ConfigFileFinder(mockedapp.program)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue