From 79cb44186305794f0a5f7ab93d7c138a03b0d0f9 Mon Sep 17 00:00:00 2001 From: Augusto Wagner Andreoli Date: Thu, 8 Aug 2019 21:19:44 +0200 Subject: [PATCH] fix(setup.cfg): silently ignore invalid sections to avoid exceptions See #69 for a permanent solution. --- nitpick/files/setup_cfg.py | 12 +++++++----- poetry.lock | 8 ++++---- tests/test_setup_cfg.py | 25 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/nitpick/files/setup_cfg.py b/nitpick/files/setup_cfg.py index 1216e66d..4737ac8c 100644 --- a/nitpick/files/setup_cfg.py +++ b/nitpick/files/setup_cfg.py @@ -1,7 +1,7 @@ """Checker for the `setup.cfg ` 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 @@ -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 "" diff --git a/poetry.lock b/poetry.lock index 1e32f816..83e73271 100644 --- a/poetry.lock +++ b/poetry.lock @@ -523,12 +523,12 @@ description = "ruamel.yaml is a YAML parser/emitter that supports roundtrip pres name = "ruamel.yaml" optional = false python-versions = "*" -version = "0.16.0" +version = "0.16.1" [package.dependencies] [package.dependencies."ruamel.yaml.clib"] python = "<3.8" -version = "*" +version = ">=0.1.2" [[package]] category = "main" @@ -714,7 +714,7 @@ version = "0.1.7" [[package]] category = "dev" description = "Enable Unicode input and display when running Python from Windows console." -marker = "sys_platform == \"win32\" and python_version < \"3.6\" and python_version >= \"3.4\" or sys_platform == \"win32\" and python_version < \"3.6\"" +marker = "sys_platform == \"win32\" and python_version < \"3.6\" or sys_platform == \"win32\" and python_version < \"3.6\" and python_version >= \"3.4\"" name = "win-unicode-console" optional = false python-versions = "*" @@ -792,7 +792,7 @@ python-slugify = ["a9f468227cb11e20e251670d78e1b5f6b0b15dd37bbd5c9814a25a904e44f pytz = ["26c0b32e437e54a18161324a2fca3c4b9846b74a8dccddd843113109e1116b32", "c894d57500a4cd2d5c71114aaab77dbab5eabd9022308ce5ac9bb93a60a6f0c7"] requests = ["11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4", "9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31"] responses = ["502d9c0c8008439cfcdef7e251f507fcfdd503b56e8c0c87c3c3e3393953f790", "97193c0183d63fba8cd3a041c75464e4b09ea0aff6328800d1546598567dde0b"] -"ruamel.yaml" = ["4c1dbad22790b5ea8587c2a0cae97ebc7a9d0d88de5d0edb70dea2eab7d8534a", "eb4b1ffd095785c50f110118cb6f7bb9cd011ecc013b014436d38b7f8fb7afa9"] +"ruamel.yaml" = ["547aeab5c51c93bc750ed2a320c1559b605bde3aa569216aa75fd91d8a1c4623"] "ruamel.yaml.clib" = ["0bbe19d3e099f8ba384e1846e6b54f245f58aeec8700edbbf9abb87afa54fd82", "2f38024592613f3a8772bbc2904be027d9abf463518ba145f2d0c8e6da27009f", "44449b3764a3f75815eea8ae5930b98e8326be64a90b0f782747318f861abfe0", "5710be9a357801c31c1eaa37b9bc92d38176d785af5b2f0c9751385c5dc9659a", "5a089acb6833ed5f412e24cbe3e665683064c1429824d2819137b5ade54435c3", "6143386ddd61599ea081c012a69a16e5bdd7b3c6c231bd039534365a48940f30", "6726aaf851f5f9e4cbdd3e1e414bc700bdd39220e8bc386415fd41c87b1b53c2", "68fbc3b5d94d145a391452f886ae5fca240cb7e3ab6bd66e1a721507cdaac28a", "75ebddf99ba9e0b48f32b5bdcf9e5a2b84c017da9e0db7bf11995fa414aa09cd", "79948a6712baa686773a43906728e20932c923f7b2a91be7347993be2d745e55", "8a2dd8e8b08d369558cade05731172c4b5e2f4c5097762c6b352bd28fd9f9dc4", "c747acdb5e8c242ab2280df6f0c239e62838af4bee647031d96b3db2f9cefc04", "cadc8eecd27414dca30366b2535cb5e3f3b47b4e2d6be7a0b13e4e52e459ff9f", "cee86ecc893a6a8ecaa7c6a9c2d06f75f614176210d78a5f155f8e78d6989509", "e59af39e895aff28ee5f55515983cab3466d1a029c91c04db29da1c0f09cf333", "eee7ecd2eee648884fae6c51ae50c814acdcc5d6340dc96c970158aebcd25ac6", "ef8d4522d231cb9b29f6cdd0edc8faac9d9715c60dc7becbd6eb82c915a98e5b", "f504d45230cc9abf2810623b924ae048b224a90adb01f97db4e766cfdda8e6eb"] six = ["3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73"] snowballstemmer = ["9f3b9ffe0809d174f7047e121431acf99c89a7040f0ca84f94ba53a498e6d0c9"] diff --git a/tests/test_setup_cfg.py b/tests/test_setup_cfg.py index da0a4dcd..35b0a667 100644 --- a/tests/test_setup_cfg.py +++ b/tests/test_setup_cfg.py @@ -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 + """ + )