Skip to content

Commit

Permalink
Merge pull request #14 from orsinium-labs/fix-fixed-count
Browse files Browse the repository at this point in the history
suggest: Fix fixed count detection
  • Loading branch information
orsinium authored Mar 10, 2023
2 parents a8373c2 + dbb93d1 commit 6b55d66
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mypy_baseline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from ._cli import entrypoint, main


__version__ = '0.4.4'
__version__ = '0.4.5'
__all__ = ['entrypoint', 'main']
4 changes: 2 additions & 2 deletions mypy_baseline/commands/_suggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def fixed_count(self) -> int:
"""Get number of baseline violations fixed in this PR.
"""
lines = self._get_stdout(
'diff', 'HEAD', self.target, '--',
'diff', self.target, 'HEAD', '--',
str(self.config.baseline_path),
)
count = 0
Expand Down Expand Up @@ -226,7 +226,7 @@ def _check_gitlab_has_comment(self, token: str) -> bool:
import requests

resp = requests.get(
url=self._gitlab_comment_url,
url=f'{self._gitlab_comment_url}?sort=asc&per_page=100',
headers={'PRIVATE-TOKEN': token},
)
resp.raise_for_status()
Expand Down
5 changes: 3 additions & 2 deletions tests/test_commands/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
def run(cmd: list[str], exit_code: int = 0) -> str:
stdout = StringIO()
code = main(cmd, StringIO(), stdout)
assert code == exit_code
stdout.seek(0)
return stdout.read()
result = stdout.read()
assert code == exit_code, result
return result
17 changes: 16 additions & 1 deletion tests/test_commands/test_suggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from mypy_baseline._config import Config
from mypy_baseline.commands import Suggest

from .helpers import LINE1, run
from .helpers import LINE1, LINE2, run


@contextmanager
Expand Down Expand Up @@ -62,6 +62,21 @@ def test_suggest(repo_path: Path):
assert stdout.strip() == LINE1.strip()


def test_fixed_and_committed(repo_path: Path):
"""If there are committed fixes in the baseline, don't suggest.
"""
bline_path = repo_path / 'baseline.txt'
bline_path.write_text(f'{LINE1}\n{LINE2}')
run_git('add', str(bline_path))
run_git('commit', '-m', 'init')
run_git('checkout', '-b', 'feature-branch')
bline_path.write_text(LINE1)
run_git('commit', '-am', 'fix bline')
cmd = ['suggest', '--baseline-path', str(bline_path)]
stdout = run(cmd, exit_code=0)
assert stdout.strip() == ''


def test_target_branch__cli_flag():
parser = ArgumentParser()
Config.init_parser(parser)
Expand Down

0 comments on commit 6b55d66

Please sign in to comment.