add tests

This commit is contained in:
qananasikq
2026-04-16 18:11:14 +03:00
parent 3ce7866643
commit 1d3c69120e
6 changed files with 736 additions and 0 deletions

31
tests/test_utils.py Normal file
View File

@@ -0,0 +1,31 @@
from __future__ import annotations
import unittest
from encar_scraper.core.utils import deep_find_key
class TestDeepFindKey(unittest.TestCase):
def test_finds_key_in_nested_structure(self) -> None:
payload = {
"root": {
"target": "a",
"nested": [{"target": "b"}, {"x": 1}],
}
}
found = deep_find_key(payload, {"target"})
self.assertEqual(found, ["a", "b"])
def test_respects_max_depth(self) -> None:
payload = {"l1": {"l2": {"l3": {"target": "value"}}}}
found_too_shallow = deep_find_key(payload, {"target"}, max_depth=2)
found_enough_depth = deep_find_key(payload, {"target"}, max_depth=8)
self.assertEqual(found_too_shallow, [])
self.assertEqual(found_enough_depth, ["value"])
if __name__ == "__main__":
unittest.main()