mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 06:44:18 +00:00
refactor and simplify configuration loading
This commit is contained in:
parent
dc9b7eb3e4
commit
65c893728e
20 changed files with 351 additions and 883 deletions
|
|
@ -1,5 +1,4 @@
|
|||
"""Test aggregation of config files and command-line options."""
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
|
@ -9,24 +8,38 @@ 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):
|
||||
@pytest.fixture
|
||||
def flake8_config(tmp_path):
|
||||
cfg_s = """\
|
||||
[flake8]
|
||||
ignore =
|
||||
E123,
|
||||
W234,
|
||||
E111
|
||||
exclude =
|
||||
foo/,
|
||||
bar/,
|
||||
bogus/
|
||||
quiet = 1
|
||||
"""
|
||||
cfg = tmp_path.joinpath("tox.ini")
|
||||
cfg.write_text(cfg_s)
|
||||
return str(cfg)
|
||||
|
||||
|
||||
def test_aggregate_options_with_config(optmanager, flake8_config):
|
||||
"""Verify we aggregate options and config values appropriately."""
|
||||
arguments = [
|
||||
"flake8",
|
||||
|
|
@ -35,11 +48,12 @@ def test_aggregate_options_with_config(optmanager):
|
|||
"--exclude",
|
||||
"tests/*",
|
||||
]
|
||||
config_finder = config.ConfigFileFinder(
|
||||
"flake8", config_file=CLI_SPECIFIED_CONFIG
|
||||
)
|
||||
cfg, cfg_dir = config.load_config(flake8_config, [])
|
||||
options = aggregator.aggregate_options(
|
||||
optmanager, config_finder, arguments
|
||||
optmanager,
|
||||
cfg,
|
||||
cfg_dir,
|
||||
arguments,
|
||||
)
|
||||
|
||||
assert options.select == ["E11", "E34", "E402", "W", "F"]
|
||||
|
|
@ -47,7 +61,7 @@ def test_aggregate_options_with_config(optmanager):
|
|||
assert options.exclude == [os.path.abspath("tests/*")]
|
||||
|
||||
|
||||
def test_aggregate_options_when_isolated(optmanager):
|
||||
def test_aggregate_options_when_isolated(optmanager, flake8_config):
|
||||
"""Verify we aggregate options and config values appropriately."""
|
||||
arguments = [
|
||||
"flake8",
|
||||
|
|
@ -56,11 +70,9 @@ def test_aggregate_options_when_isolated(optmanager):
|
|||
"--exclude",
|
||||
"tests/*",
|
||||
]
|
||||
config_finder = config.ConfigFileFinder("flake8", ignore_config_files=True)
|
||||
cfg, cfg_dir = config.load_config(flake8_config, [], isolated=True)
|
||||
optmanager.extend_default_ignore(["E8"])
|
||||
options = aggregator.aggregate_options(
|
||||
optmanager, config_finder, arguments
|
||||
)
|
||||
options = aggregator.aggregate_options(optmanager, cfg, cfg_dir, arguments)
|
||||
|
||||
assert options.select == ["E11", "E34", "E402", "W", "F"]
|
||||
assert sorted(options.ignore) == [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue