From 5d903aee54d0dd5e90475e403e9ba2790d926cab Mon Sep 17 00:00:00 2001 From: Chris Barnes Date: Sun, 1 Nov 2026 18:24:44 +0000 Subject: [PATCH 1/2] Fix test case ordering --- src/oztest/case_filter.py | 43 ++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/oztest/case_filter.py b/src/oztest/case_filter.py index efc0f8c..f340f41 100644 --- a/src/oztest/case_filter.py +++ b/src/oztest/case_filter.py @@ -6,8 +6,9 @@ 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 +from typing import Any, Protocol, Self from packaging.specifiers import SpecifierSet from packaging.version import Version @@ -108,6 +109,25 @@ def __init__(self, version: str) -> None: super().__init__(version) +class Ord(Protocol): + def __lt__(self, other: Self) -> bool: ... + def __gt__(self, other: Self) -> bool: ... + + +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. @@ -139,15 +159,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]: From bfe49ee5cf4e0bf71d08a6ac83baa902fc2b1875 Mon Sep 17 00:00:00 2001 From: Chris Barnes Date: Sun, 1 Nov 2026 18:28:11 +0000 Subject: [PATCH 2/2] Remove unnecessary protocol --- src/oztest/case_filter.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/oztest/case_filter.py b/src/oztest/case_filter.py index f340f41..e5b4607 100644 --- a/src/oztest/case_filter.py +++ b/src/oztest/case_filter.py @@ -8,7 +8,7 @@ from importlib.resources import as_file, files from operator import gt, lt from pathlib import Path -from typing import Any, Protocol, Self +from typing import Any from packaging.specifiers import SpecifierSet from packaging.version import Version @@ -109,11 +109,6 @@ def __init__(self, version: str) -> None: super().__init__(version) -class Ord(Protocol): - def __lt__(self, other: Self) -> bool: ... - def __gt__(self, other: Self) -> bool: ... - - def cmp_by_fields( early_true: Callable[[Any, Any], bool], early_false: Callable[[Any, Any], bool],