Spaces:
Sleeping
Sleeping
fix: update CLI tests for --input flag and --no-filter
Browse files- Rename --query to --input in tests (matches CLI refactor)
- Add --no-filter to search tests since random embeddings
won't pass the default FDR threshold
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- tests/test_cli.py +17 -14
tests/test_cli.py
CHANGED
|
@@ -61,7 +61,7 @@ def test_search_help():
|
|
| 61 |
"""Test that 'cpr search --help' works."""
|
| 62 |
result = run_cli('search', '--help')
|
| 63 |
assert result.returncode == 0
|
| 64 |
-
assert '--
|
| 65 |
assert '--database' in result.stdout
|
| 66 |
assert '--output' in result.stdout
|
| 67 |
assert '--k' in result.stdout
|
|
@@ -117,7 +117,7 @@ def test_search_missing_args():
|
|
| 117 |
"""Test that search command fails without required args."""
|
| 118 |
result = run_cli('search')
|
| 119 |
assert result.returncode != 0
|
| 120 |
-
assert '--
|
| 121 |
|
| 122 |
|
| 123 |
def test_verify_missing_args():
|
|
@@ -152,13 +152,14 @@ def test_search_with_mock_data(tmp_path):
|
|
| 152 |
np.save(query_file, query_embeddings)
|
| 153 |
np.save(db_file, db_embeddings)
|
| 154 |
|
| 155 |
-
# Run search
|
| 156 |
result = run_cli(
|
| 157 |
'search',
|
| 158 |
-
'--
|
| 159 |
'--database', str(db_file),
|
| 160 |
'--output', str(output_file),
|
| 161 |
-
'--k', '3'
|
|
|
|
| 162 |
)
|
| 163 |
|
| 164 |
assert result.returncode == 0
|
|
@@ -195,7 +196,7 @@ def test_search_with_threshold(tmp_path):
|
|
| 195 |
# Run search with high threshold
|
| 196 |
result = run_cli(
|
| 197 |
'search',
|
| 198 |
-
'--
|
| 199 |
'--database', str(db_file),
|
| 200 |
'--output', str(output_file),
|
| 201 |
'--k', '10',
|
|
@@ -244,14 +245,15 @@ def test_search_with_metadata(tmp_path):
|
|
| 244 |
})
|
| 245 |
meta_df.to_csv(meta_file, index=False)
|
| 246 |
|
| 247 |
-
# Run search with metadata
|
| 248 |
result = run_cli(
|
| 249 |
'search',
|
| 250 |
-
'--
|
| 251 |
'--database', str(db_file),
|
| 252 |
'--database-meta', str(meta_file),
|
| 253 |
'--output', str(output_file),
|
| 254 |
-
'--k', '3'
|
|
|
|
| 255 |
)
|
| 256 |
|
| 257 |
assert result.returncode == 0
|
|
@@ -457,7 +459,7 @@ def test_search_missing_query_file(tmp_path):
|
|
| 457 |
|
| 458 |
result = run_cli(
|
| 459 |
'search',
|
| 460 |
-
'--
|
| 461 |
'--database', str(db_file),
|
| 462 |
'--output', str(output_file)
|
| 463 |
)
|
|
@@ -475,7 +477,7 @@ def test_search_missing_database_file(tmp_path):
|
|
| 475 |
|
| 476 |
result = run_cli(
|
| 477 |
'search',
|
| 478 |
-
'--
|
| 479 |
'--database', '/nonexistent/db.npy',
|
| 480 |
'--output', str(output_file)
|
| 481 |
)
|
|
@@ -528,13 +530,14 @@ def test_search_with_k_larger_than_database(tmp_path):
|
|
| 528 |
np.save(query_file, query_embeddings)
|
| 529 |
np.save(db_file, db_embeddings)
|
| 530 |
|
| 531 |
-
# Request k=10 but only have 3 items in database
|
| 532 |
result = run_cli(
|
| 533 |
'search',
|
| 534 |
-
'--
|
| 535 |
'--database', str(db_file),
|
| 536 |
'--output', str(output_file),
|
| 537 |
-
'--k', '10'
|
|
|
|
| 538 |
)
|
| 539 |
|
| 540 |
# Should succeed (FAISS will return at most db size)
|
|
|
|
| 61 |
"""Test that 'cpr search --help' works."""
|
| 62 |
result = run_cli('search', '--help')
|
| 63 |
assert result.returncode == 0
|
| 64 |
+
assert '--input' in result.stdout
|
| 65 |
assert '--database' in result.stdout
|
| 66 |
assert '--output' in result.stdout
|
| 67 |
assert '--k' in result.stdout
|
|
|
|
| 117 |
"""Test that search command fails without required args."""
|
| 118 |
result = run_cli('search')
|
| 119 |
assert result.returncode != 0
|
| 120 |
+
assert '--input' in result.stderr or 'required' in result.stderr
|
| 121 |
|
| 122 |
|
| 123 |
def test_verify_missing_args():
|
|
|
|
| 152 |
np.save(query_file, query_embeddings)
|
| 153 |
np.save(db_file, db_embeddings)
|
| 154 |
|
| 155 |
+
# Run search (use --no-filter since random embeddings won't pass FDR threshold)
|
| 156 |
result = run_cli(
|
| 157 |
'search',
|
| 158 |
+
'--input', str(query_file),
|
| 159 |
'--database', str(db_file),
|
| 160 |
'--output', str(output_file),
|
| 161 |
+
'--k', '3',
|
| 162 |
+
'--no-filter'
|
| 163 |
)
|
| 164 |
|
| 165 |
assert result.returncode == 0
|
|
|
|
| 196 |
# Run search with high threshold
|
| 197 |
result = run_cli(
|
| 198 |
'search',
|
| 199 |
+
'--input', str(query_file),
|
| 200 |
'--database', str(db_file),
|
| 201 |
'--output', str(output_file),
|
| 202 |
'--k', '10',
|
|
|
|
| 245 |
})
|
| 246 |
meta_df.to_csv(meta_file, index=False)
|
| 247 |
|
| 248 |
+
# Run search with metadata (use --no-filter since random embeddings won't pass FDR threshold)
|
| 249 |
result = run_cli(
|
| 250 |
'search',
|
| 251 |
+
'--input', str(query_file),
|
| 252 |
'--database', str(db_file),
|
| 253 |
'--database-meta', str(meta_file),
|
| 254 |
'--output', str(output_file),
|
| 255 |
+
'--k', '3',
|
| 256 |
+
'--no-filter'
|
| 257 |
)
|
| 258 |
|
| 259 |
assert result.returncode == 0
|
|
|
|
| 459 |
|
| 460 |
result = run_cli(
|
| 461 |
'search',
|
| 462 |
+
'--input', '/nonexistent/query.npy',
|
| 463 |
'--database', str(db_file),
|
| 464 |
'--output', str(output_file)
|
| 465 |
)
|
|
|
|
| 477 |
|
| 478 |
result = run_cli(
|
| 479 |
'search',
|
| 480 |
+
'--input', str(query_file),
|
| 481 |
'--database', '/nonexistent/db.npy',
|
| 482 |
'--output', str(output_file)
|
| 483 |
)
|
|
|
|
| 530 |
np.save(query_file, query_embeddings)
|
| 531 |
np.save(db_file, db_embeddings)
|
| 532 |
|
| 533 |
+
# Request k=10 but only have 3 items in database (use --no-filter)
|
| 534 |
result = run_cli(
|
| 535 |
'search',
|
| 536 |
+
'--input', str(query_file),
|
| 537 |
'--database', str(db_file),
|
| 538 |
'--output', str(output_file),
|
| 539 |
+
'--k', '10',
|
| 540 |
+
'--no-filter'
|
| 541 |
)
|
| 542 |
|
| 543 |
# Should succeed (FAISS will return at most db size)
|