diff --git a/bananalyzer/data/schemas.py b/bananalyzer/data/schemas.py index 7ee63193..9dda9b9c 100644 --- a/bananalyzer/data/schemas.py +++ b/bananalyzer/data/schemas.py @@ -1,7 +1,9 @@ +import json from abc import ABC, abstractmethod from typing import Any, Dict, List, Literal, Optional, Union import pytest +from deepdiff import DeepDiff from pydantic import BaseModel, Field, model_validator from bananalyzer.data.fetch_schemas import fetch_schemas @@ -39,9 +41,16 @@ def eval_action(self, _: str) -> bool: return True def eval_results(self, result: Dict[str, Any]) -> None: - if result != self.expected: - diff_msg = f"Expected: {self.expected}\nActual: {result}" - pytest.fail(f"JSONEval mismatch:\n{diff_msg}") + diff = DeepDiff( + self.expected, result, ignore_order=True, report_repetition=True + ) + if diff: + # Pretty print both expected and actual results + pretty_expected = json.dumps(self.expected, indent=4) + pretty_actual = json.dumps(result, indent=4) + + diff_msg = f"Actual: {pretty_actual}\nExpected: {pretty_expected}" + pytest.fail(f"JSONEval mismatch!\n{diff_msg}") class ActionEval(BaseModel): diff --git a/poetry.lock b/poetry.lock index ed22aff4..38de4557 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.0 and should not be changed by hand. [[package]] name = "annotated-types" @@ -140,6 +140,24 @@ files = [ [package.extras] toml = ["tomli"] +[[package]] +name = "deepdiff" +version = "6.7.0" +description = "Deep Difference and Search of any Python object/data. Recreate objects by adding adding deltas to each other." +optional = false +python-versions = ">=3.7" +files = [ + {file = "deepdiff-6.7.0-py3-none-any.whl", hash = "sha256:d64dd64be5b2e3917c7cc557d69e68d008d798a5cd4981d1508707037504d50a"}, + {file = "deepdiff-6.7.0.tar.gz", hash = "sha256:4c60fc1da4ac12aa73de98b7f303971607c6f928867fabf143cd51a434badb7d"}, +] + +[package.dependencies] +ordered-set = ">=4.0.2,<4.2.0" + +[package.extras] +cli = ["click (==8.1.3)", "pyyaml (==6.0.1)"] +optimize = ["orjson"] + [[package]] name = "greenlet" version = "3.0.0" @@ -300,6 +318,20 @@ files = [ {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, ] +[[package]] +name = "ordered-set" +version = "4.1.0" +description = "An OrderedSet is a custom MutableSet that remembers its order, so that every" +optional = false +python-versions = ">=3.7" +files = [ + {file = "ordered-set-4.1.0.tar.gz", hash = "sha256:694a8e44c87657c59292ede72891eb91d34131f6531463aab3009191c77364a8"}, + {file = "ordered_set-4.1.0-py3-none-any.whl", hash = "sha256:046e1132c71fcf3330438a539928932caf51ddbc582496833e23de611de14562"}, +] + +[package.extras] +dev = ["black", "mypy", "pytest"] + [[package]] name = "packaging" version = "23.2" @@ -644,4 +676,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "990b35581775f15bb482ee313169e0fa388ee54415de0714182f71dc11ba792d" +content-hash = "90a7ee0f922d1ead60d4bb620e426f3bf7e7fda3681f11023b58a4aff26ae56d" diff --git a/pyproject.toml b/pyproject.toml index bcb86d28..d4b355b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ python = "^3.11" playwright = "^1.39.0" pydantic = "^2.4.2" pytest-asyncio = "^0.21.1" +deepdiff = "^6.7.0" [tool.poetry.group.test.dependencies] pytest = "^7.4.2"