mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 05:26:53 +00:00
Merge branch 'separate-prelim-options' into 'master'
Separate pre-configuration CLI parsing See merge request pycqa/flake8!364
This commit is contained in:
commit
836147087e
7 changed files with 118 additions and 81 deletions
|
|
@ -1,4 +1,5 @@
|
|||
"""Test aggregation of config files and command-line options."""
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
|
@ -14,9 +15,12 @@ CLI_SPECIFIED_CONFIG = 'tests/fixtures/config_files/cli-specified.ini'
|
|||
@pytest.fixture
|
||||
def optmanager():
|
||||
"""Create a new OptionManager."""
|
||||
prelim_parser = argparse.ArgumentParser(add_help=False)
|
||||
options.register_preliminary_options(prelim_parser)
|
||||
option_manager = manager.OptionManager(
|
||||
prog='flake8',
|
||||
version='3.0.0',
|
||||
parents=[prelim_parser],
|
||||
)
|
||||
options.register_default_options(option_manager)
|
||||
return option_manager
|
||||
|
|
|
|||
|
|
@ -93,11 +93,24 @@ 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_and_args(
|
||||
['flake8', '--foo', '--verbose', 'src', 'setup.py', '--statistics'])
|
||||
['--foo', '--verbose', 'src', 'setup.py', '--statistics', '--version'])
|
||||
|
||||
assert opts.statistics
|
||||
assert opts.verbose
|
||||
assert args == ['src', 'setup.py']
|
||||
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_and_args([
|
||||
'--help',
|
||||
'-h',
|
||||
])
|
||||
|
||||
# THEN
|
||||
assert args == ['--help', '-h']
|
||||
|
||||
|
||||
def test_prelim_opts_handles_empty(application):
|
||||
|
|
|
|||
|
|
@ -22,6 +22,23 @@ def test_option_manager_creates_option_parser(optmanager):
|
|||
assert isinstance(optmanager.parser, argparse.ArgumentParser)
|
||||
|
||||
|
||||
def test_option_manager_including_parent_options():
|
||||
"""Verify parent options are included in the parsed options."""
|
||||
# GIVEN
|
||||
parent_parser = argparse.ArgumentParser(add_help=False)
|
||||
parent_parser.add_argument('--parent')
|
||||
|
||||
# WHEN
|
||||
optmanager = manager.OptionManager(
|
||||
prog='flake8',
|
||||
version=TEST_VERSION,
|
||||
parents=[parent_parser])
|
||||
option, _ = optmanager.parse_args(['--parent', 'foo'])
|
||||
|
||||
# THEN
|
||||
assert option.parent == 'foo'
|
||||
|
||||
|
||||
def test_parse_args_forwarding_default_values(optmanager):
|
||||
"""Verify default provided values are present in the final result."""
|
||||
namespace = argparse.Namespace(foo='bar')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue