Skip to content

Commit

Permalink
Merge pull request #17 from cfculhane/master
Browse files Browse the repository at this point in the history
Fix unused regex colour var, and fix bug where mypy returned no errors
  • Loading branch information
orsinium authored Sep 25, 2023
2 parents ac4a893 + 219fe40 commit 4b1e5fe
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ __pycache__/
/.venvs/
/docs/assets
/docs/build/
.python-version
.idea/
.coverage
2 changes: 1 addition & 1 deletion mypy_baseline/_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_clean_line(self, config: Config) -> str:
path = Path(*self.path.parts[:config.depth])
pos = self.line_number if config.preserve_position else 0
msg = REX_COLOR.sub('', self.message).strip()
msg = REX_COLOR_NBQA.sub('', self.message).strip()
msg = REX_COLOR_NBQA.sub('', msg).strip()
msg = REX_LINE_IN_MSG.sub('defined on line 0', msg)
line = f'{path}:{pos}: {self.severity}: {msg}'
if self.category != 'note':
Expand Down
3 changes: 3 additions & 0 deletions mypy_baseline/commands/_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def run(self) -> int:
unresolved_errors.append(error)

fixed_errors: list[Error] = []

for line in baseline:
if not line: # Skip empty lines
continue
error = Error.new(line)
if error is None:
print(f'invalid baseline, cannot parse line: {line}')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_commands/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
LINE1 = 'views.py:69: error: Hello world [assignment]\r\n'
LINE2 = 'settings.py:42: error: How are you? [union-attr]\r\n'
LINE3 = 'python/utils.py:15: error: Second argument of Enum() must be string [misc]\n'

LINE_WITH_NOTE = 'integrations/services.py:0: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports' # noqa: E501
SUCCESS_LINE = 'Success: no issues found in 26 source files'
NOTEBOOK_LINE1 = 'fail.ipynb:cell_1:2: \x1b[1m\x1b[31merror:\x1b(B\x1b[m Incompatible return value type (got \x1b(B\x1b[m\x1b[1m"int"\x1b(B\x1b[m, expected \x1b(B\x1b[m\x1b[1m"str"\x1b(B\x1b[m) \x1b(B\x1b[m\x1b[33m[return-value]\x1b(B\x1b[m\n' # noqa: E501


Expand Down
26 changes: 20 additions & 6 deletions tests/test_commands/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@

from mypy_baseline import main

from .helpers import LINE1, LINE2, LINE3, NOTEBOOK_LINE1, run
from .helpers import (
LINE1, LINE2, LINE3, LINE_WITH_NOTE, NOTEBOOK_LINE1, SUCCESS_LINE, run,
)


def test_filter():
stdin = StringIO()
stdin.write(LINE1)
stdin.write(LINE2)
stdin.write(LINE3)
stdin.write(LINE_WITH_NOTE)
stdin.seek(0)
stdout = StringIO()
code = main(['filter'], stdin, stdout)
assert code == 3
stdout.seek(0)
actual = stdout.read()
assert code == 4
actual = stdout.getvalue()
assert LINE1.strip() in actual
assert LINE2.strip() in actual
assert LINE3.strip() in actual
assert LINE_WITH_NOTE.strip() in actual
assert ' assignment ' in actual
assert ' union-attr ' in actual
assert ' unresolved' in actual
assert ' note ' in actual
assert 'Your changes introduced' in actual


Expand All @@ -35,8 +39,7 @@ def test_filter_notebook():
stdout = StringIO()
code = main(['filter'], stdin, stdout)
assert code == 1
stdout.seek(0)
actual = stdout.read()
actual = stdout.getvalue()
assert NOTEBOOK_LINE1 in actual
assert ' return-value ' in actual
assert ' unresolved' in actual
Expand All @@ -46,3 +49,14 @@ def test_filter_notebook():
def test_filter__empty_stdin():
actual = run(['filter'])
assert actual == ''


def test_filter_success():
stdin = StringIO()
stdin.write(SUCCESS_LINE)
stdin.seek(0)
stdout = StringIO()
code = main(['filter'], stdin, stdout)
assert code == 0
actual = stdout.getvalue()
assert actual == SUCCESS_LINE
7 changes: 2 additions & 5 deletions tests/test_commands/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
from .helpers import run


PROJECT_ROOT = Path(__file__).parent.parent.parent


def test_history():
readme_path = PROJECT_ROOT / 'README.md'
def test_history(request):
readme_path = Path(request.config.rootdir, 'README.md')
cmd = ['history', '--baseline-path', str(readme_path), '--no-color']
actual = run(cmd)
exp = '2022-09-01 11:45:28+02:00 60 = 3 -1 +58 8fe7afd10c [email protected]'
Expand Down

0 comments on commit 4b1e5fe

Please sign in to comment.