@@ -25,6 +25,25 @@ def fake_valkey_client():
2525 return fakeredis .FakeStrictRedis (decode_responses = False )
2626
2727
28+ def convert_hash_fields_to_str (hash_fields : dict ) -> dict :
29+ """Helper to convert hash field bytes to strings for test assertions.
30+
31+ Args:
32+ hash_fields: Raw hash fields from Valkey (may contain bytes)
33+
34+ Returns:
35+ Dictionary with bytes converted to strings (except binary vector field)
36+ """
37+ result = {}
38+ for k , v in hash_fields .items ():
39+ key_str = k .decode ("utf-8" ) if isinstance (k , bytes ) else k
40+ # Skip binary vector field - it's not UTF-8 text
41+ if key_str == "vector" and isinstance (v , bytes ):
42+ result [key_str ] = v # Keep as bytes
43+ else :
44+ result [key_str ] = v .decode ("utf-8" ) if isinstance (v , bytes ) else v
45+ return result
46+
2847class TestValkeyIndexConfig :
2948 """Test suite for ValkeyIndexConfig TypedDict."""
3049
@@ -682,16 +701,7 @@ def test_document_creation_includes_searchable_fields(self, fake_valkey_client):
682701 hash_fields = fake_valkey_client .hgetall (key )
683702
684703 # Convert bytes keys/values to strings for easier checking
685- hash_fields_str = {}
686- for k , v in hash_fields .items ():
687- key_str = k .decode ("utf-8" ) if isinstance (k , bytes ) else k
688- # Skip binary vector field - it's not UTF-8 text
689- if key_str == "vector" and isinstance (v , bytes ):
690- val_str = v # Keep as bytes
691- else :
692- val_str = v .decode ("utf-8" ) if isinstance (v , bytes ) else v
693- hash_fields_str [key_str ] = val_str
694-
704+ hash_fields_str = convert_hash_fields_to_str (hash_fields )
695705 # Verify that searchable fields are included in hash fields
696706 # (without value_ prefix)
697707 assert "user_id" in hash_fields_str
@@ -744,16 +754,7 @@ def test_list_fields_handled_correctly(self, fake_valkey_client):
744754 hash_fields = fake_valkey_client .hgetall (key )
745755
746756 # Convert bytes keys/values to strings for easier checking
747- hash_fields_str = {}
748- for k , v in hash_fields .items ():
749- key_str = k .decode ("utf-8" ) if isinstance (k , bytes ) else k
750- # Skip binary vector field - it's not UTF-8 text
751- if key_str == "vector" and isinstance (v , bytes ):
752- val_str = v # Keep as bytes
753- else :
754- val_str = v .decode ("utf-8" ) if isinstance (v , bytes ) else v
755- hash_fields_str [key_str ] = val_str
756-
757+ hash_fields_str = convert_hash_fields_to_str (hash_fields )
757758 # Verify that list fields are converted to comma-separated strings
758759 assert hash_fields_str ["tags" ] == "machine-learning,ai,python"
759760 assert hash_fields_str ["categories" ] == "tech,tutorial"
0 commit comments