Skip to content
Merged
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
36 changes: 27 additions & 9 deletions src/oztest/case_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from contextlib import contextmanager
from functools import total_ordering
from importlib.resources import as_file, files
from operator import gt, lt
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -108,6 +109,20 @@ def __init__(self, version: str) -> None:
super().__init__(version)


def cmp_by_fields(
early_true: Callable[[Any, Any], bool],
early_false: Callable[[Any, Any], bool],
final: bool,
fields: Iterable[tuple[Any, Any]],
) -> bool:
for a, b in fields:
if early_true(a, b):
return True
if early_false(a, b):
return False
return final


@total_ordering
class Case:
"""Information about a test case.
Expand Down Expand Up @@ -139,15 +154,18 @@ def __eq__(self, value: object) -> bool:
def __le__(self, rhs: object) -> bool:
if not isinstance(rhs, type(self)):
return NotImplemented
if self.kind < rhs.kind:
return True
if self.version < rhs.version:
return True
if self.profile < rhs.profile:
return True
if self.validity < rhs.validity:
return True
return self.name < rhs.name
return cmp_by_fields(
lt,
gt,
True,
fields=[
(self.kind, rhs.kind),
(self.version, rhs.version),
(self.profile, rhs.profile),
(self.validity, rhs.validity),
(self.name, rhs.name),
],
)

@contextmanager
def as_path(self) -> Generator[Path]:
Expand Down
Loading