fix: Enhance dictionary access tests and refactor apply_json_filter function (#7335)

* refactor: streamline apply_json_filter function for improved clarity and performance

- Simplified data extraction from Data objects and handled None inputs.
- Enhanced dictionary access logic and removed redundant checks.
- Improved handling of special cases for filter access, including nested and array structures.

* test: enhance dictionary access tests with additional examples

- Added new example cases to the test_basic_dict_access function to cover edge cases, including empty dictionaries and keys with spaces.
- Improved test robustness by utilizing the @example decorator from hypothesis for better failure discovery.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2025-03-28 13:22:29 -03:00 • committed by GitHub
commit 7e65be32a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 39 deletions

View file

@ -1,5 +1,5 @@
import pytest
from hypothesis import assume, given
from hypothesis import assume, example, given
from hypothesis import strategies as st
from langflow.schema.data import Data
from langflow.template.utils import apply_json_filter
@ -16,6 +16,14 @@ def dict_strategy():
# Test basic dictionary access
@given(data=st.dictionaries(st.text(), st.integers()), key=st.text())
@example(
data={" ": 0}, # or any other generated value
key=" ",
).via("discovered failure")
@example(
data={},
key=" ",
).via("discovered failure")
def test_basic_dict_access(data, key):
# Skip empty key tests which have special handling
assume(key != "")