Skip to content

Commit

Permalink
fix(setup.cfg): silently ignore invalid sections to avoid exceptions
Browse files Browse the repository at this point in the history
See #69 for a permanent solution.
  • Loading branch information
andreoliwa committed Aug 8, 2019
1 parent b482ea1 commit 79cb441
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
12 changes: 7 additions & 5 deletions nitpick/files/setup_cfg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Checker for the `setup.cfg <https://docs.python.org/3/distutils/configfile.html>` config file."""
from configparser import ConfigParser
from io import StringIO
from typing import Any, List, Set, Tuple
from typing import Any, Dict, List, Set, Tuple

import dictdiffer

Expand Down Expand Up @@ -37,10 +37,12 @@ def get_missing_output(self, actual_sections: Set[str] = None) -> str:
if self.missing_sections:
missing_cfg = ConfigParser()
for section in sorted(self.missing_sections):
# TODO this invalid configuration raises AttributeError: 'list' object has no attribute 'items':
# ["setup.cfg"]
# comma_separated_values = ["flake8.ignore", "flake8.exclude"]
missing_cfg[section] = self.file_dict[section]
expected_config = self.file_dict[section] # type: Dict
if not isinstance(expected_config, dict):
# Silently ignore invalid sections for now, to avoid exceptions.
# This should be solved in https://github.com/andreoliwa/nitpick/issues/69
continue
missing_cfg[section] = expected_config
return self.get_example_cfg(missing_cfg)
return ""

Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions tests/test_setup_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,28 @@ def test_different_missing_keys(request):
max-line-length = 112\x1b[0m
"""
)


def test_invalid_configuration_comma_separated_values(request):
"""Test an invalid configuration for comma_separated_values."""
ProjectMock(request).style(
"""
["setup.cfg".flake8]
max-line-length = 85
max-complexity = 12
ignore = "D100,D101,D102,D103,D104,D105,D106,D107,D202,E203,W503"
select = "E241,C,E,F,W,B,B9"
["setup.cfg"]
comma_separated_values = ["flake8.ignore", "flake8.exclude"]
"""
).lint().assert_errors_contain(
"""
NIP321 File setup.cfg was not found. Create it with this content:\x1b[92m
[flake8]
ignore = D100,D101,D102,D103,D104,D105,D106,D107,D202,E203,W503
max-complexity = 12
max-line-length = 85
select = E241,C,E,F,W,B,B9\x1b[0m
"""
)

0 comments on commit 79cb441

Please sign in to comment.