Skip to content

Commit

Permalink
Add --check-allow to avoid returning 1 for known failures
Browse files Browse the repository at this point in the history
  • Loading branch information
ichard26 committed Mar 14, 2022
1 parent 016c71f commit d5622bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ black-primer and mypy-primer.
- Added `--force-stable-style` and `--force-preview-style` to forcefully set
the code style across **all** projects.
- Added `-r` as a short alias of `--repeat-projects-from`.
- Added `--check-allow` so pre-existing failures don't cause
`show-failed --check` to return one.
- Log files produced when a file fails to format are now recorded and can be
pulled via the `show` or `show-failed` commands.
- `--show-locals` is also forcefully set on GHA.
Expand Down
22 changes: 20 additions & 2 deletions src/diff_shades/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,19 @@ def compare(
@click.argument("key", metavar="project", callback=normalize_input, required=False)
@click.option("--show-log", is_flag=True, help="Show log files if present as well.")
@click.option("--check", is_flag=True, help="Return 1 if there's a failure.")
def show_failed(analysis_path: Path, key: Optional[str], show_log: bool, check: bool) -> None:
@click.option(
"--check-allow",
multiple=True,
callback=lambda ctx, p, v: set(v),
help="Ignore these failures when determining return code (--check).",
)
def show_failed(
analysis_path: Path,
key: Optional[str],
show_log: bool,
check: bool,
check_allow: Set[str],
) -> None:
"""
Show and check for failed files in an analysis.
"""
Expand All @@ -448,6 +460,7 @@ def show_failed(analysis_path: Path, key: Optional[str], show_log: bool, check:

failed_projects = 0
failed_files = 0
disallowed_failures = 0
for proj_name, proj_results in analysis.results.items():
if key and key != proj_name:
continue
Expand All @@ -459,6 +472,11 @@ def show_failed(analysis_path: Path, key: Optional[str], show_log: bool, check:
console.print(f"[bold red]{proj_name}:", highlight=False)
for number, (file, result) in enumerate(failed.items(), start=1):
s = f"{number}. {file}: {escape(result.error)} - {escape(result.message)}"
if f"{proj_name}:{file}" in check_allow:
s += "[dim] (allowed)[/]"
else:
disallowed_failures += 1

console.print(Padding(s, (0, 0, 0, 2)), highlight=False)
if result.log is not None and show_log:
padded = Padding(escape(result.log), (0, 0, 0, 4))
Expand All @@ -468,7 +486,7 @@ def show_failed(analysis_path: Path, key: Optional[str], show_log: bool, check:
console.print(f"[bold]# of failed files: {failed_files}")
console.print(f"[bold]# of failed projects: {failed_projects}")
if check:
sys.exit(bool(failed_files))
sys.exit(disallowed_failures > 0)


if __name__ == "__main__":
Expand Down
11 changes: 11 additions & 0 deletions tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,17 @@ def test_show_failed_with_check(filename: str, runner: CLIRunner) -> None:
r.assert_return_code(1 if "failing" in filename else 0)


def test_show_failed_with_check_allowed_failure(runner: CLIRunner) -> None:
cmd: SupportedArgs = [
"show-failed",
DATA_DIR / "failing.json",
"--check",
"--check-allow",
"irisa:my-other-file",
]
runner.check(cmd)


def test_show_failed_specific_project(runner: CLIRunner) -> None:
runner.check(["show-failed", DATA_DIR / "failing.json", "daylily"])

Expand Down

0 comments on commit d5622bb

Please sign in to comment.