config: Determine path to user configuration immediately

Preemptively determine the path of the user configuration file during
the construction of the `ConfigFileFinder` object.  The user
configuration path will always be the same, regardless of when it gets
obtained by a run of `flake8`.

This isolates the logic of determining the user configuration path into
a static helper method to be called to set the `.user_config_file`
attribute.  The helper method leverages `utils.is_windows()`, instead of
reimplementing the check, and decomposes clearly the directory name and
the base name to construct the path with a single `return` path.
Additionally, this avoids reconstructing the path on demand of obtaining
the user configuration file path.
This commit is contained in:
Eric N. Vander Weele 2020-01-20 16:42:16 -05:00
parent 990adcd56e
commit aab1f14375
3 changed files with 24 additions and 38 deletions

View file

@ -2,7 +2,6 @@
"""Tests for the ConfigFileFinder."""
import configparser
import os
import sys
import mock
import pytest
@ -13,18 +12,6 @@ CLI_SPECIFIED_FILEPATH = 'tests/fixtures/config_files/cli-specified.ini'
BROKEN_CONFIG_PATH = 'tests/fixtures/config_files/broken.ini'
@pytest.mark.parametrize('platform,is_windows', [
('win32', True),
('linux', False),
('darwin', False),
])
def test_windows_detection(platform, is_windows):
"""Verify we detect Windows to the best of our knowledge."""
with mock.patch.object(sys, 'platform', platform):
finder = config.ConfigFileFinder('flake8')
assert finder.is_windows is is_windows
def test_cli_config():
"""Verify opening and reading the file specified via the cli."""
cli_filepath = CLI_SPECIFIED_FILEPATH