Skip to content

Commit

Permalink
fix(cli/check_fixtures): Allow a single fixture check
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Nov 5, 2024
1 parent 852f62f commit d1028ea
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/cli/check_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

from pathlib import Path
from typing import Generator

import click
from rich.progress import BarColumn, Progress, TaskProgressColumn, TextColumn, TimeElapsedColumn
Expand Down Expand Up @@ -59,10 +60,10 @@ def check_json(json_file_path: Path):
@click.option(
"--input",
"-i",
"input_dir",
type=click.Path(exists=True, file_okay=False, dir_okay=True, readable=True),
"input_str",
type=click.Path(exists=True, file_okay=True, dir_okay=True, readable=True),
required=True,
help="The input directory containing json fixture files",
help="The input json file or directory containing json fixture files",
)
@click.option(
"--quiet",
Expand All @@ -83,17 +84,25 @@ def check_json(json_file_path: Path):
expose_value=True,
help="Stop and raise any exceptions encountered while checking fixtures.",
)
def check_fixtures(input_dir: str, quiet_mode: bool, stop_on_error: bool):
def check_fixtures(input_str: str, quiet_mode: bool, stop_on_error: bool):
"""
Perform some checks on the fixtures contained in the specified directory.
"""
input_path = Path(input_dir)
input_path = Path(input_str)
success = True
file_count = 0
filename_display_width = 25
if not quiet_mode:
if input_path.is_file():
file_count = 1
elif not quiet_mode:
file_count = count_json_files_exclude_index(input_path)

def get_input_files() -> Generator[Path, None, None]:
if input_path.is_file():
yield input_path
else:
yield from input_path.rglob("*.json")

with Progress(
TextColumn(
f"[bold cyan]{{task.fields[filename]:<{filename_display_width}}}[/]", justify="left"
Expand All @@ -106,7 +115,7 @@ def check_fixtures(input_dir: str, quiet_mode: bool, stop_on_error: bool):
) as progress:

task_id = progress.add_task("Checking fixtures", total=file_count, filename="...")
for json_file_path in input_path.rglob("*.json"):
for json_file_path in get_input_files():
if json_file_path.name == "index.json":
continue

Expand Down

0 comments on commit d1028ea

Please sign in to comment.