Skip to content

Commit

Permalink
šŸŒ Update eval to pretty print failure reason. Also do a position-lessā€¦
Browse files Browse the repository at this point in the history
ā€¦ search
  • Loading branch information
asim-shrestha committed Nov 14, 2023
1 parent ecbb878 commit ea6547a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
15 changes: 12 additions & 3 deletions bananalyzer/data/schemas.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down
36 changes: 34 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ea6547a

Please sign in to comment.