flake8/tests/integration/test_aggregator.py
Eric N. Vander Weele 7f9f70064c aggregator: Forward --config and --isolated options during aggregation
This fixes a regression introduced in !346 to ensure that `--config` and
`--isolated` are recognized in `aggregate_options()`.

The regression manifested because `aggregate_options()` was relying on
re-parsing `argv` to obtain the option values.  However, !346 changed
the preliminary parsing logic to only parse and "eat" what is necessary
and forward along the options needed before all the configuration was
loaded.  This code path was overlooked because the tests in
`test_aggregator()` were passing but the call from the `Application`
object would never have these options in the remaining `argv` list to be
passed long.
2019-12-29 18:07:51 -05:00

55 lines
1.9 KiB
Python

"""Test aggregation of config files and command-line options."""
import argparse
import os
import pytest
from flake8.main import options
from flake8.options import aggregator
from flake8.options import config
from flake8.options import manager
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
def test_aggregate_options_with_config(optmanager):
"""Verify we aggregate options and config values appropriately."""
arguments = ['flake8', '--select',
'E11,E34,E402,W,F', '--exclude', 'tests/*']
config_finder = config.ConfigFileFinder('flake8', [])
options, args = aggregator.aggregate_options(
optmanager, config_finder, CLI_SPECIFIED_CONFIG, False, arguments)
assert options.select == ['E11', 'E34', 'E402', 'W', 'F']
assert options.ignore == ['E123', 'W234', 'E111']
assert options.exclude == [os.path.abspath('tests/*')]
def test_aggregate_options_when_isolated(optmanager):
"""Verify we aggregate options and config values appropriately."""
arguments = ['flake8', '--select', 'E11,E34,E402,W,F',
'--exclude', 'tests/*']
config_finder = config.ConfigFileFinder('flake8', [])
optmanager.extend_default_ignore(['E8'])
options, args = aggregator.aggregate_options(
optmanager, config_finder, None, True, arguments)
assert options.select == ['E11', 'E34', 'E402', 'W', 'F']
assert sorted(options.ignore) == [
'E121', 'E123', 'E126', 'E226', 'E24', 'E704', 'E8', 'W503', 'W504',
]
assert options.exclude == [os.path.abspath('tests/*')]