Add tests for command-line search and fix bugs#394
Merged
Conversation
Move the lmfdb_search logic into an importable module (lmfdb/cmdline_search.py) with a main(argv) entry point so it can be unit tested; lmfdb_search becomes a thin wrapper. Bugs fixed (all crashed at runtime): * missing `import os` (used by --output) and `import csv` (used by csv/tsv output on raw tables) * --cols validation referenced `table` before it was assigned * url-style queries against a raw table referenced an undefined `wrapper`; now reported with a helpful error * undefined `limit` in the section cleaners block (should be args.limit) * `info` was undefined for section searches with a json/empty query and a download format; it is now always initialized * json output was rejected for sections and also fell through to the download branch; json now works for all tables and sections * json serialization crashed on Sage Integer/RealLiteral values; now uses Json.prep, matching the LMFDB API * --format pari crashed because the download language key is "gp"; added a mapping Add lmfdb/tests/test_cmdline_search.py covering raw/json/csv/tsv output, section download formats (sage, pari, magma), url and json queries, --cols, --sort, --oneper, --completeness, --output/--force, and error handling. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add CommandLineSearch.md (linked from the README) describing the
lmfdb_search command-line interface: sections vs. raw tables, the three
query formats, output formats, all options, and worked examples.
While writing the examples, found that --oneper makes psycodict include
extra grouping/sort columns in each record, which made csv/tsv output
crash in csv.DictWriter ("dict contains fields not in fieldnames"). Pass
extrasaction="ignore" so the output is restricted to the projection, and
add a regression test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…lues bug * --random/-r: return a single object chosen uniformly at random from those matching the query, via table.random(). * implement print_help: `lmfdb_search help TABLE` prints the table description and every column description; `help TABLE COL` prints a single column's description (using table.description()/column_description()). * raw SQL (--sql) already worked, but a second raw= search in the same process failed because psycodict's search() has a mutable default raw_values=[] that _build_query appends limit/offset onto, so stale values leak between calls. Pass a fresh raw_values=[] to immunize the CLI, and add tests for raw SQL. * clarify the "json/tsv language support to downloads" TODO: it refers to adding JSON/TSV DownloadLanguage subclasses to lmfdb/utils/downloader.py; until then the CLI produces those formats itself. * document --random, the help subcommand, and raw SQL in CommandLineSearch.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The "checking that we didn't miss any test files" lint step counts test files and requires every one to be listed in matrix_includes.json. Add the new test file to the hilbert_modular_forms/sato_tate_groups/tests shard (proddb and devmirror) and bump the expected count from 42 to 43. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a test suite for the new
lmfdb_searchcommand-line interface and fixes the bugs the tests surface. Targets thecmdlinebranch so it can fold into LMFDB#7044.Structure
Moves the
lmfdb_searchlogic into an importable module (lmfdb/cmdline_search.py) with amain(argv)entry point so it can be unit tested;lmfdb_searchbecomes a thin wrapper.Bugs fixed (all crashed at runtime)
import os(used by--output) andimport csv(used by csv/tsv output on raw tables)--colsvalidation referencedtablebefore it was assignedwrapper; now reported with a helpful errorlimitin the section cleaners block (should beargs.limit)infowas undefined for section searches with a json/empty query and a download format; now always initializedInteger/RealLiteralvalues; now usesJson.prep, matching the LMFDB API--format paricrashed because the download language key isgp; added a mappingTests
lmfdb/tests/test_cmdline_search.pycovers raw/json/csv/tsv output, section download formats (sage, pari, magma), url and json queries,--cols,--sort,--oneper,--completeness,--output/--force, and error handling. All 24 pass.🤖 Generated with Claude Code