-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#106] Finally fixing pyroma path ignoring issue, where it has to ove…
…rride the default ignored files; also added a bunch more testing for file ignoring
- Loading branch information
Showing
44 changed files
with
319 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
import re | ||
from pathlib import Path | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
|
||
from prospector.finder import FileFinder | ||
from ..utils import patch_execution | ||
|
||
from prospector.config import ProspectorConfig | ||
|
||
|
||
class TestProspectorConfig(TestCase): | ||
def test_determine_ignores_all_str(self): | ||
with patch("sys.argv", ["", "-P", "prospector-str-ignores"]), patch( | ||
"pathlib.Path.cwd", return_value=Path(__file__).parent | ||
): | ||
config = ProspectorConfig() | ||
self.assertNotEqual(len(config.ignores), 0) | ||
boundary = r"(^|/|\\)%s(/|\\|$)" | ||
paths = ["2017", "2018"] | ||
for path in paths: | ||
compiled_ignored_path = re.compile(boundary % re.escape(path)) | ||
self.assertIn(compiled_ignored_path, config.ignores) | ||
|
||
def test_determine_ignores_containing_int_values_wont_throw_attr_exc(self): | ||
try: | ||
with patch("sys.argv", ["", "-P", "prospector-int-ignores"]), patch( | ||
"pathlib.Path.cwd", return_value=Path(__file__).parent | ||
): | ||
config = ProspectorConfig() | ||
self.assertNotEqual(len(config.ignores), 0) | ||
boundary = r"(^|/|\\)%s(/|\\|$)" | ||
paths = ["2017", "2018"] | ||
for path in paths: | ||
compiled_ignored_path = re.compile(boundary % re.escape(path)) | ||
self.assertIn(compiled_ignored_path, config.ignores) | ||
except AttributeError as attr_exc: | ||
self.fail(attr_exc) | ||
def test_relative_ignores(): | ||
""" | ||
Tests that if 'ignore-paths: something' is set, then it is ignored; that | ||
is, paths relative to the working directory should be ignored too | ||
""" | ||
workdir = Path(__file__).parent / 'testdata/test_relative_ignores' | ||
with patch_execution(workdir, "-P", "profile_relative_ignores.yml"): | ||
config = ProspectorConfig() | ||
files = FileFinder(*config.paths, exclusion_filters=[config.make_exclusion_filter()]) | ||
assert 2 == len(files.python_modules) | ||
|
||
|
||
def test_determine_ignores_all_str(): | ||
with patch_execution(Path(__file__).parent, "-P", "prospector-str-ignores"): | ||
config = ProspectorConfig() | ||
assert len(config.ignores) > 0 | ||
boundary = r"(^|/|\\)%s(/|\\|$)" | ||
paths = ["2017", "2018"] | ||
for path in paths: | ||
compiled_ignored_path = re.compile(boundary % re.escape(path)) | ||
assert compiled_ignored_path in config.ignores | ||
|
||
|
||
def test_determine_ignores_containing_int_values_wont_throw_attr_exc(): | ||
with patch_execution(Path(__file__).parent, "-P", "prospector-int-ignores"): | ||
config = ProspectorConfig() | ||
assert len(config.ignores) > 0 | ||
boundary = r"(^|/|\\)%s(/|\\|$)" | ||
paths = ["2017", "2018"] | ||
for path in paths: | ||
compiled_ignored_path = re.compile(boundary % re.escape(path)) | ||
assert compiled_ignored_path in config.ignores |
File renamed without changes.
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions
7
tests/config/testdata/test_relative_ignores/profile_relative_ignores.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
inherits: | ||
- strictness_medium | ||
- no_test_warnings | ||
|
||
|
||
ignore-paths: | ||
- something.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x = 1 + unittes |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
These are full "end-to-end" tests of a prospector run | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
1 change: 1 addition & 0 deletions
1
tests/execution/testdata/ignore_test/pkg1/pkg2/asdr_partial_aserfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x += 1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x = y+1 |
1 change: 1 addition & 0 deletions
1
tests/execution/testdata/ignore_test/pkg1/pkg2/pkg3/safdv_partial_ag45.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x += 1 |
Empty file.
1 change: 1 addition & 0 deletions
1
tests/execution/testdata/ignore_test/pkg1/pkg_ignore/broken2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a = y + 3/0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
strictness: medium | ||
|
||
ignore-paths: | ||
- pkg1/pkg_ignore | ||
ignore-patterns: | ||
- .*partial.* |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from pathlib import Path | ||
|
||
from prospector.config import ProspectorConfig | ||
from prospector.finder import FileFinder | ||
from prospector.tools.pyroma import PyromaTool | ||
from ...utils import patch_cwd, patch_cli | ||
|
||
|
||
def test_forced_include(): | ||
""" | ||
The built-in default profiles for prospector will ignore `setup.py` by default, but this needs | ||
to be explicitly overridden for pyroma *only* | ||
However, other ignore files should still not be returned. Only a setup.py in the root of the | ||
working directory should be explicitly force-included. | ||
see https://github.com/PyCQA/prospector/pull/106 | ||
""" | ||
test_data = Path(__file__).parent / 'testdata' | ||
|
||
with patch_cwd(test_data): | ||
# can't use the patch_execution shortcut due to pyroma playing with things itself too | ||
with patch_cli('prospector', '--profile', 'test-pyroma-profile.yml'): | ||
config = ProspectorConfig() | ||
files = FileFinder(*config.paths, exclusion_filters=[config.make_exclusion_filter()]) | ||
# this should not return the root setup.py by default (using the strictness profile) | ||
# but will return others (they might just be called setup.py by coincidence) | ||
assert len(files.python_modules) == 3 | ||
tool = PyromaTool() | ||
tool.configure(config, files) | ||
|
||
# must do this outside of the CLI patch because pyroma does its own sys.argv patching... | ||
messages = tool.run(files) | ||
|
||
# this should still find errors in the setup.py, but not any of the others | ||
assert len(messages) == 8 | ||
allowed = ( | ||
test_data / 'setup.py', | ||
test_data / 'pkg1/this_one_is_fine/setup.py' | ||
) | ||
for message in messages: | ||
assert message.location.path in allowed |
Empty file.
Empty file.
Oops, something went wrong.