Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 64 additions & 7 deletions conformance/ome_zarr_conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
here = Path(__file__).resolve().parent.parent
tests_dir = here / "tests"

Status = Literal["pass", "fail", "error"]

@dataclass
class CommandOutput:
Expand All @@ -39,7 +40,7 @@ def from_jso(cls, jso: dict[str, Any]) -> Self:
@dataclass
class TestResult:
test_name: str
status: Literal["pass", "fail", "error"]
status: Status
message: str | None
stderr: str
return_code: int
Expand Down Expand Up @@ -167,6 +168,52 @@ def run_all_tests(
yield res


def colour(s: str, num: int, is_bright=False, is_background=False) -> str:
match (is_bright, is_background):
case (False, False):
pref = "3"
case (False, True):
pref = "4"
case (True, False):
pref = "9"
case (True, True):
pref = "10"
return f"\x1b[{pref}{num}m{s}\x1b[0m"


class Colourer:
def __init__(self) -> None:
self.is_term = sys.stdout.isatty()

def _colour(self, s: str, num: int, is_bright=False, is_background=False) -> str:
if not self.is_term:
return s
return colour(s, num, is_bright, is_background)

def r(self, s: str) -> str:
return self._colour(s, 1)

def g(self, s: str) -> str:
return self._colour(s, 2)

def y(self, s: str) -> str:
return self._colour(s, 3)

def m(self, s: str) -> str:
return self._colour(s, 5)

def status(self, s: Status) -> str:
match s:
case "pass":
return self.g(s)
case "fail":
return self.r(s)
case "error":
return self.m(s)
case other:
raise ValueError(f"Unknown status '{other}'")


def main(raw_args=None):
parser = ArgumentParser(
description=(
Expand Down Expand Up @@ -205,7 +252,7 @@ def main(raw_args=None):
"--exclude-strict",
"-S",
action="store_true",
help="exclude strict tests",
help="DEPRECATED: exclude strict tests",
)
parser.add_argument(
"--exclude-invalid",
Expand Down Expand Up @@ -241,7 +288,12 @@ def main(raw_args=None):
3: logging.DEBUG,
}.get(args.verbose, logging.DEBUG)
logging.basicConfig(level=lvl)
logging.debug("Got args: %s", args)
logger.debug("Got args: %s", args)

if args.exclude_strict:
logger.warning(
"Strict test cases are deprecated; -S/--exclude-strict argument is implicit and will soon be removed."
)

if dingus_args is None:
print(
Expand Down Expand Up @@ -274,21 +326,26 @@ def main(raw_args=None):
test_paths = ((test_path_to_name(p, dpath), p) for p in dpath.rglob(rglob))
cases = dict(sorted((n, p) for n, p in test_paths if req.include(n)))

c = Colourer()

for res in run_all_tests(
dingus_args,
cases,
):
row = [
res.test_name,
res.status,
]
if res.status == "pass":
passes += 1
elif res.status == "fail":
failures += 1
elif res.status == "error":
errors += 1

row = [
res.test_name,
c.status(res.status),
]
if res.message:
row.append(" ".join(res.message.split()))

print("\t".join(row))

logger.info("Got %s passes, %s failures, %s errors", passes, failures, errors)
Expand Down
3 changes: 0 additions & 3 deletions examples/multiscales_strict/.config.json

This file was deleted.

93 changes: 0 additions & 93 deletions examples/multiscales_strict/multiscales_example.json

This file was deleted.

92 changes: 0 additions & 92 deletions examples/multiscales_strict/multiscales_example_relative.json

This file was deleted.

40 changes: 0 additions & 40 deletions examples/multiscales_strict/multiscales_reference_to_label.json

This file was deleted.

Loading
Loading