Skip to content

Add tests for command-line search and fix bugs#394

Merged
roed314 merged 4 commits into
roed314:cmdlinefrom
roed-math:cmdline
Jun 19, 2026
Merged

Add tests for command-line search and fix bugs#394
roed314 merged 4 commits into
roed314:cmdlinefrom
roed-math:cmdline

Conversation

@roed-math

Copy link
Copy Markdown

Adds a test suite for the new lmfdb_search command-line interface and fixes the bugs the tests surface. Targets the cmdline branch so it can fold into LMFDB#7044.

Structure

Moves 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; 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

Tests

lmfdb/tests/test_cmdline_search.py covers 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

roed314 and others added 4 commits June 18, 2026 09:55
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>
@roed314 roed314 merged commit 64ead3b into roed314:cmdline Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants