Skip to content

Commit 6342f2b

Browse files
committed
refactor: Improve field modifier test cleanup and naming
Two improvements to field modifier ordering integration tests: 1. Remove try/except cleanup pattern - Replaced try/finally/except blocks with direct cleanup calls - Affects 9 test methods across all field types - Cleanup failures now visible instead of silently ignored - Matches pattern used in other integration tests 2. Rename for open-source clarity - TestMultipleCommandsScenarioIntegration → TestFieldModifierIntegration - test_mlp_commands_index_creation → test_index_creation_with_multiple_modifiers - Use general naming instead of MLP-specific terminology These changes improve test maintainability and make failures more visible.
1 parent 94e2ff2 commit 6342f2b

File tree

1 file changed

+107
-135
lines changed

1 file changed

+107
-135
lines changed

tests/integration/test_field_modifier_ordering_integration.py

Lines changed: 107 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,17 @@ def test_textfield_sortable_and_index_missing(self, client, redis_url, worker_id
5353
schema = IndexSchema.from_dict(schema_dict)
5454
index = SearchIndex(schema=schema, redis_url=redis_url)
5555

56-
try:
57-
# This should succeed - if modifiers are in wrong order, it will fail
58-
index.create(overwrite=True)
59-
60-
# Verify index was created
61-
info = client.execute_command(
62-
"FT.INFO", f"test_text_sortable_missing_{worker_id}"
63-
)
64-
assert info is not None
65-
finally:
66-
try:
67-
index.delete(drop=True)
68-
except Exception:
69-
pass # Index may not exist if test was skipped or failed early
56+
# This should succeed - if modifiers are in wrong order, it will fail
57+
index.create(overwrite=True)
58+
59+
# Verify index was created
60+
info = client.execute_command(
61+
"FT.INFO", f"test_text_sortable_missing_{worker_id}"
62+
)
63+
assert info is not None
64+
65+
# Cleanup
66+
index.delete(drop=True)
7067

7168
def test_textfield_all_modifiers(self, client, redis_url, worker_id):
7269
"""Test TextField with all modifiers."""
@@ -94,18 +91,15 @@ def test_textfield_all_modifiers(self, client, redis_url, worker_id):
9491
schema = IndexSchema.from_dict(schema_dict)
9592
index = SearchIndex(schema=schema, redis_url=redis_url)
9693

97-
try:
98-
# This should succeed - if modifiers are in wrong order, it will fail
99-
index.create(overwrite=True)
94+
# This should succeed - if modifiers are in wrong order, it will fail
95+
index.create(overwrite=True)
10096

101-
# Verify index was created
102-
info = client.execute_command("FT.INFO", f"test_text_all_mods_{worker_id}")
103-
assert info is not None
104-
finally:
105-
try:
106-
index.delete(drop=True)
107-
except Exception:
108-
pass # Index may not exist if test was skipped or failed early
97+
# Verify index was created
98+
info = client.execute_command("FT.INFO", f"test_text_all_mods_{worker_id}")
99+
assert info is not None
100+
101+
# Cleanup
102+
index.delete(drop=True)
109103

110104

111105
class TestTagFieldModifierOrderingIntegration:
@@ -132,20 +126,17 @@ def test_tagfield_sortable_and_index_missing(self, client, redis_url, worker_id)
132126
schema = IndexSchema.from_dict(schema_dict)
133127
index = SearchIndex(schema=schema, redis_url=redis_url)
134128

135-
try:
136-
# This should succeed - if modifiers are in wrong order, it will fail
137-
index.create(overwrite=True)
138-
139-
# Verify index was created
140-
info = client.execute_command(
141-
"FT.INFO", f"test_tag_sortable_missing_{worker_id}"
142-
)
143-
assert info is not None
144-
finally:
145-
try:
146-
index.delete(drop=True)
147-
except Exception:
148-
pass # Index may not exist if test was skipped or failed early
129+
# This should succeed - if modifiers are in wrong order, it will fail
130+
index.create(overwrite=True)
131+
132+
# Verify index was created
133+
info = client.execute_command(
134+
"FT.INFO", f"test_tag_sortable_missing_{worker_id}"
135+
)
136+
assert info is not None
137+
138+
# Cleanup
139+
index.delete(drop=True)
149140

150141
def test_tagfield_all_modifiers(self, client, redis_url, worker_id):
151142
"""Test TagField with all modifiers."""
@@ -172,18 +163,15 @@ def test_tagfield_all_modifiers(self, client, redis_url, worker_id):
172163
schema = IndexSchema.from_dict(schema_dict)
173164
index = SearchIndex(schema=schema, redis_url=redis_url)
174165

175-
try:
176-
# This should succeed - if modifiers are in wrong order, it will fail
177-
index.create(overwrite=True)
166+
# This should succeed - if modifiers are in wrong order, it will fail
167+
index.create(overwrite=True)
168+
169+
# Verify index was created
170+
info = client.execute_command("FT.INFO", f"test_tag_all_mods_{worker_id}")
171+
assert info is not None
178172

179-
# Verify index was created
180-
info = client.execute_command("FT.INFO", f"test_tag_all_mods_{worker_id}")
181-
assert info is not None
182-
finally:
183-
try:
184-
index.delete(drop=True)
185-
except Exception:
186-
pass # Index may not exist if test was skipped or failed early
173+
# Cleanup
174+
index.delete(drop=True)
187175

188176

189177
class TestGeoFieldModifierOrderingIntegration:
@@ -210,20 +198,17 @@ def test_geofield_sortable_and_index_missing(self, client, redis_url, worker_id)
210198
schema = IndexSchema.from_dict(schema_dict)
211199
index = SearchIndex(schema=schema, redis_url=redis_url)
212200

213-
try:
214-
# This should succeed - if modifiers are in wrong order, it will fail
215-
index.create(overwrite=True)
201+
# This should succeed - if modifiers are in wrong order, it will fail
202+
index.create(overwrite=True)
203+
204+
# Verify index was created
205+
info = client.execute_command(
206+
"FT.INFO", f"test_geo_sortable_missing_{worker_id}"
207+
)
208+
assert info is not None
216209

217-
# Verify index was created
218-
info = client.execute_command(
219-
"FT.INFO", f"test_geo_sortable_missing_{worker_id}"
220-
)
221-
assert info is not None
222-
finally:
223-
try:
224-
index.delete(drop=True)
225-
except Exception:
226-
pass # Index may not exist if test was skipped or failed early
210+
# Cleanup
211+
index.delete(drop=True)
227212

228213

229214
class TestNumericFieldModifierOrderingIntegration:
@@ -252,20 +237,17 @@ def test_numericfield_sortable_and_index_missing(
252237
schema = IndexSchema.from_dict(schema_dict)
253238
index = SearchIndex(schema=schema, redis_url=redis_url)
254239

255-
try:
256-
# This should succeed - if modifiers are in wrong order, it will fail
257-
index.create(overwrite=True)
240+
# This should succeed - if modifiers are in wrong order, it will fail
241+
index.create(overwrite=True)
258242

259-
# Verify index was created
260-
info = client.execute_command(
261-
"FT.INFO", f"test_numeric_sortable_missing_{worker_id}"
262-
)
263-
assert info is not None
264-
finally:
265-
try:
266-
index.delete(drop=True)
267-
except Exception:
268-
pass # Index may not exist if test was skipped or failed early
243+
# Verify index was created
244+
info = client.execute_command(
245+
"FT.INFO", f"test_numeric_sortable_missing_{worker_id}"
246+
)
247+
assert info is not None
248+
249+
# Cleanup
250+
index.delete(drop=True)
269251

270252

271253
class TestMultiFieldModifierOrderingIntegration:
@@ -307,28 +289,25 @@ def test_mixed_field_types_with_modifiers(self, client, redis_url, worker_id):
307289
schema = IndexSchema.from_dict(schema_dict)
308290
index = SearchIndex(schema=schema, redis_url=redis_url)
309291

310-
try:
311-
# This should succeed - if modifiers are in wrong order, it will fail
312-
index.create(overwrite=True)
292+
# This should succeed - if modifiers are in wrong order, it will fail
293+
index.create(overwrite=True)
294+
295+
# Verify index was created
296+
info = client.execute_command("FT.INFO", f"test_mixed_fields_{worker_id}")
297+
assert info is not None
313298

314-
# Verify index was created
315-
info = client.execute_command("FT.INFO", f"test_mixed_fields_{worker_id}")
316-
assert info is not None
299+
# Verify all fields were created
300+
attrs_list = info[7]
301+
assert len(attrs_list) == 4
317302

318-
# Verify all fields were created
319-
attrs_list = info[7]
320-
assert len(attrs_list) == 4
321-
finally:
322-
try:
323-
index.delete(drop=True)
324-
except Exception:
325-
pass # Index may not exist if test was skipped or failed early
303+
# Cleanup
304+
index.delete(drop=True)
326305

327306

328-
class TestMultipleCommandsScenarioIntegration:
329-
"""Integration tests for mlp_commands.txt scenario."""
307+
class TestFieldModifierIntegration:
308+
"""Integration tests for complex field modifier combinations."""
330309

331-
def test_mlp_commands_index_creation(self, client, redis_url, worker_id):
310+
def test_index_creation_with_multiple_modifiers(self, client, redis_url, worker_id):
332311
"""Test creating index with INDEXMISSING SORTABLE UNF modifiers.
333312
334313
This test verifies that an index with all three modifiers
@@ -354,18 +333,15 @@ def test_mlp_commands_index_creation(self, client, redis_url, worker_id):
354333
schema = IndexSchema.from_dict(schema_dict)
355334
index = SearchIndex(schema=schema, redis_url=redis_url)
356335

357-
try:
358-
# This should succeed with correct modifier ordering
359-
index.create(overwrite=True)
336+
# This should succeed with correct modifier ordering
337+
index.create(overwrite=True)
360338

361-
# Verify index was created
362-
info = client.execute_command("FT.INFO", f"testidx_{worker_id}")
363-
assert info is not None
364-
finally:
365-
try:
366-
index.delete(drop=True)
367-
except Exception:
368-
pass # Index may not exist if test was skipped or failed early
339+
# Verify index was created
340+
info = client.execute_command("FT.INFO", f"testidx_{worker_id}")
341+
assert info is not None
342+
343+
# Cleanup
344+
index.delete(drop=True)
369345

370346
def test_indexmissing_enables_ismissing_query(self, client, redis_url, worker_id):
371347
"""Test that INDEXMISSING enables ismissing() query function."""
@@ -388,37 +364,33 @@ def test_indexmissing_enables_ismissing_query(self, client, redis_url, worker_id
388364
schema = IndexSchema.from_dict(schema_dict)
389365
index = SearchIndex(schema=schema, redis_url=redis_url)
390366

391-
try:
392-
index.create(overwrite=True)
393-
394-
# Create documents with and without the field
395-
client.hset(f"ismiss_{worker_id}:1", "optional_field", "has value")
396-
client.hset(f"ismiss_{worker_id}:2", "other_field", "no optional_field")
397-
client.hset(f"ismiss_{worker_id}:3", "optional_field", "also has value")
398-
399-
# Query for missing fields
400-
result = client.execute_command(
401-
"FT.SEARCH",
402-
f"test_ismissing_{worker_id}",
403-
"ismissing(@optional_field)",
404-
"DIALECT",
405-
"2",
406-
)
407-
408-
# Should return 1 result (ismiss_{worker_id}:2)
409-
assert result[0] == 1
410-
assert f"ismiss_{worker_id}:2" in str(result)
411-
412-
finally:
413-
try:
414-
client.delete(
415-
f"ismiss_{worker_id}:1",
416-
f"ismiss_{worker_id}:2",
417-
f"ismiss_{worker_id}:3",
418-
)
419-
index.delete(drop=True)
420-
except Exception:
421-
pass # Index may not exist if test was skipped or failed early
367+
index.create(overwrite=True)
368+
369+
# Create documents with and without the field
370+
client.hset(f"ismiss_{worker_id}:1", "optional_field", "has value")
371+
client.hset(f"ismiss_{worker_id}:2", "other_field", "no optional_field")
372+
client.hset(f"ismiss_{worker_id}:3", "optional_field", "also has value")
373+
374+
# Query for missing fields
375+
result = client.execute_command(
376+
"FT.SEARCH",
377+
f"test_ismissing_{worker_id}",
378+
"ismissing(@optional_field)",
379+
"DIALECT",
380+
"2",
381+
)
382+
383+
# Should return 1 result (ismiss_{worker_id}:2)
384+
assert result[0] == 1
385+
assert f"ismiss_{worker_id}:2" in str(result)
386+
387+
# Cleanup
388+
client.delete(
389+
f"ismiss_{worker_id}:1",
390+
f"ismiss_{worker_id}:2",
391+
f"ismiss_{worker_id}:3",
392+
)
393+
index.delete(drop=True)
422394

423395

424396
class TestFieldTypeModifierSupport:

0 commit comments

Comments
 (0)