Files
Openlane/tests/test_utils.py
qananasikq ac2753146e add tests
2026-04-21 23:50:31 +03:00

25 lines
726 B
Python

from __future__ import annotations
import unittest
from openlane_scraper.core.utils import deep_find_key
class TestDeepFindKey(unittest.TestCase):
def test_finds_nested_and_respects_depth(self) -> None:
payload = {
"root": {
"target": "a",
"nested": [{"target": "b"}, {"x": 1}],
}
}
self.assertEqual(deep_find_key(payload, {"target"}), ["a", "b"])
deep_payload = {"l1": {"l2": {"l3": {"target": "value"}}}}
self.assertEqual(deep_find_key(deep_payload, {"target"}, max_depth=2), [])
self.assertEqual(deep_find_key(deep_payload, {"target"}, max_depth=8), ["value"])
if __name__ == "__main__":
unittest.main()