Skip to content

Commit ca84f90

Browse files
committed
Simplify tests.
1 parent 4f347f6 commit ca84f90

2 files changed

Lines changed: 172 additions & 458 deletions

File tree

gel/_internal/_testbase/_models.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from gel._internal import _dirhash
4040
from gel._internal import _import_extras
4141
from gel._internal._codegen._models import PydanticModelsGenerator
42+
from gel._internal._qbmodel._pydantic._models import GelModel
4243

4344
from ._base import (
4445
AsyncQueryTestCase,
@@ -76,7 +77,6 @@
7677
if TYPE_CHECKING:
7778
from collections.abc import Callable, Iterator, Mapping, Sequence
7879
import pydantic
79-
from gel._internal._qbmodel._pydantic._models import GelModel
8080

8181

8282
_unset = object()
@@ -533,6 +533,30 @@ def assertPydanticPickles(
533533
getattr(model2, "__gel_changed_fields__", ...),
534534
)
535535

536+
def _assertListEqualUnordered(
537+
self,
538+
expected: list[Any],
539+
actual: list[Any],
540+
) -> None:
541+
"""Test that two collections have equal contents, though the order
542+
may be different.
543+
544+
Compares using the id of elements. Comparing lists of lists will not
545+
work.
546+
"""
547+
548+
def key(value: Any) -> Any:
549+
if isinstance(value, GelModel) and (
550+
model_id := getattr(value, "id", None)
551+
):
552+
return model_id
553+
else:
554+
return id(value)
555+
556+
return self.assertEqual(
557+
sorted(expected, key=key), sorted(actual, key=key)
558+
)
559+
536560
def _assertObjectsWithFields(
537561
self,
538562
models: Collection[GelModel],

0 commit comments

Comments
 (0)