mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-16 00:59:52 +00:00
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:
parent
990adcd56e
commit
aab1f14375
3 changed files with 24 additions and 38 deletions
|
|
@ -69,9 +69,9 @@ def test_parse_user_config(optmanager, config_finder):
|
|||
action='count')
|
||||
parser = config.MergedConfigParser(optmanager, config_finder)
|
||||
|
||||
with mock.patch.object(parser.config_finder, 'user_config_file') as usercf:
|
||||
usercf.return_value = 'tests/fixtures/config_files/cli-specified.ini'
|
||||
parsed_config = parser.parse_user_config()
|
||||
config_finder.user_config_file = ('tests/fixtures/config_files/'
|
||||
'cli-specified.ini')
|
||||
parsed_config = parser.parse_user_config()
|
||||
|
||||
assert parsed_config == {
|
||||
'ignore': ['E123', 'W234', 'E111'],
|
||||
|
|
@ -127,11 +127,9 @@ def test_merge_user_and_local_config(optmanager, config_finder):
|
|||
localcfs.return_value = [
|
||||
'tests/fixtures/config_files/local-config.ini'
|
||||
]
|
||||
with mock.patch.object(config_finder,
|
||||
'user_config_file') as usercf:
|
||||
usercf.return_value = ('tests/fixtures/config_files/'
|
||||
'user-config.ini')
|
||||
parsed_config = parser.merge_user_and_local_config()
|
||||
config_finder.user_config_file = ('tests/fixtures/config_files/'
|
||||
'user-config.ini')
|
||||
parsed_config = parser.merge_user_and_local_config()
|
||||
|
||||
assert parsed_config == {
|
||||
'exclude': [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue