Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use pathlib.Path on the entire message.location.path #580

Merged
merged 10 commits into from
Feb 15, 2023
141 changes: 112 additions & 29 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions prospector/postfilter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -30,7 +29,7 @@ def filter_messages(filepaths: List[Path], messages: List[Message]) -> List[Mess
filtered = []
for message in messages:
# first get rid of the pylint informational messages
relative_message_path = os.path.relpath(message.location.path)
relative_message_path = Path(message.location.path)

if message.source == "pylint" and message.code in (
"suppressed-message",
Expand Down
22 changes: 22 additions & 0 deletions tests/suppression/test_suppression.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import os
import unittest
from pathlib import Path
from unittest.mock import patch

from prospector.config import ProspectorConfig
from prospector.run import Prospector
from prospector.suppression import get_noqa_suppressions


Expand All @@ -24,3 +28,21 @@ def test_ignore_enum_error(self):
file_contents = self._get_file_contents("test_ignore_enum/test.py")
_, lines = get_noqa_suppressions(file_contents)
self.assertSetEqual({5}, lines)

def test_filter_messages(self):
workdir = Path(__file__).parent / "testdata/test_filter_messages"
with patch("setoptconf.source.commandline.sys.argv", ["prospector"]):
config = ProspectorConfig(workdir=workdir)
config.paths = [workdir]
pros = Prospector(config)
pros.execute()
self.assertEqual(0, pros.summary["message_count"])

def test_filter_messages_negative(self):
workdir = Path(__file__).parent / "testdata/test_filter_messages_negative"
with patch("setoptconf.source.commandline.sys.argv", ["prospector"]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkout the tests/utils.py module, patch_execution and patch_cli might do what you need here and might as well reuse it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christokur I'm not sure you took carlio's comment into account, could you look into it please ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it into account yes

with patch("setoptconf.source.commandline.sys.argv", ...

and

with patch("sys.argv",  ...

have different semantics which is why I did not use patch_cli

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok refactored things but be aware that pyupgrade also made changes to how typing is used

config = ProspectorConfig(workdir=workdir)
config.paths = [workdir]
pros = Prospector(config)
pros.execute()
self.assertEqual(5, pros.summary["message_count"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output-format: pylint
autodetect: false
strictness: veryhigh
test-warnings: true
doc-warnings: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum, unique


@unique
class FOO_BAR(Enum): # noqa
BAZ = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import collections # noqa
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import collections # noqa
import os # noqa
import tempfile # noqa
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output-format: pylint
autodetect: false
strictness: veryhigh
test-warnings: true
doc-warnings: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum, unique


@unique
class FOO_BAR(Enum):
BAZ = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import collections
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import collections
import os
import tempfile