sqlite-utils/tests
Simon Willison 871038505b
Type fixes now enforced by ty
* Fix type warning for pipe.stdout possibly being None

Add conditional check before calling .read() on pipe.stdout since
Popen can return None for stdout.

* Use ctx.meta instead of dynamic attribute for database cleanup

Click's Context.meta dictionary is the proper way to store arbitrary
data on the context object, avoiding type checker warnings about
dynamic attribute assignment.

* Add assert for tables.callback before calling

Click's callback attribute is typed as Optional[Callable], so add
assert to satisfy type checker that it's not None.

* Fix type errors in cli.py and db.py

- Add type annotation for Database.conn to fix context manager errors
- Convert exception objects to str() when raising ClickException
- Handle None return from find_spatialite() with proper error message

* Fix remaining type errors in cli.py

- Add typing import and type annotations for dict kwargs
- Use db.table() instead of db[] for extract command
- Fix missing str() conversion for exception

* Fix type errors in db.py

- Add type annotation for Database.conn
- Add type: ignore for optional sqlite_dump import
- Update execute/query parameter types to Sequence|Dict for sqlite3 compatibility
- Use getattr for fn.__name__ access to handle callables without __name__
- Handle None return from find_spatialite() with OSError
- Fix pk_values assignment to use local variable

* Add type: ignore for optional pysqlite3 and sqlean imports

These are alternative sqlite3 implementations that may not be installed.

* Fix type errors in tests and plugins

- Add type: ignore for monkey-patching Database.__init__ in conftest
- Fix CLI test to pass string "2" instead of integer to Click invoke
- Add type: ignore for optional sqlean import
- Fix add_geometry_column test to use "XY" instead of integer 2
- Add type: ignore for click.Context as context manager
- Add type: ignore for enable_fts test that intentionally omits argument
- Add type: ignore for sys._called_from_test dynamic attribute
- Fix rows_from_file test type error for intentional wrong argument
- Handle None from pm.get_hookcallers in plugins.py

* Use db.table() instead of db[] for Table-specific operations

Changes db[table] to db.table(table) in CLI commands where we know
we're working with tables, not views. This resolves most of the
Table | View disambiguation type warnings since db.table() returns
Table directly rather than Table | View.

* Fix remaining type warnings in sqlite_utils package

- Add assert for sniff_buffer not being None
- Handle cursor.fetchone() potentially returning None
- Use db.table() for counts_table and index_foreign_keys
- Add type: ignore for cursor union type in raw mode

* Ran Black

* Run ty in CI

* ty check sqlite_utils

* Skip running ty on Windows

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 19:34:45 -08:00
..
sniff sqlite-utils insert --sniff option, closes #230 2021-02-14 11:23:12 -08:00
__init__.py Initial project layout + database table creation tools 2018-07-28 06:46:17 -07:00
conftest.py Type fixes now enforced by ty 2025-12-16 19:34:45 -08:00
ext.c Support entrypoints for --load-extension (#473) 2022-08-26 22:55:47 -07:00
test_analyze.py Use sqlean if available in environment (#560) 2023-06-25 16:25:51 -07:00
test_analyze_tables.py Database as a context manager, fixed many pytest warnings 2025-12-11 16:56:12 -08:00
test_attach.py db.attach(alias, filepath) method, closes #113 2021-02-18 20:56:32 -08:00
test_cli.py Database as a context manager, fixed many pytest warnings 2025-12-11 16:56:12 -08:00
test_cli_bulk.py --functions can take filenames, can be used multiple times (#681) 2025-11-23 21:46:51 -08:00
test_cli_convert.py Type fixes now enforced by ty 2025-12-16 19:34:45 -08:00
test_cli_insert.py Detect CSV/TSV column types by default (#683) 2025-11-23 22:23:15 -08:00
test_cli_memory.py Type fixes now enforced by ty 2025-12-16 19:34:45 -08:00
test_column_affinity.py Tracer mechanism for showing underlying SQL queries 2020-09-07 14:56:59 -07:00
test_constructor.py db.close() method, closes #504 2022-10-25 13:57:43 -07:00
test_conversions.py Now complies with flake8, refs #291 2021-06-22 18:22:08 -07:00
test_convert.py Removed convert skip_false and --skip-false, closes #542 2025-11-23 15:40:28 -08:00
test_create.py Use REAL not FLOAT as SQLite column type (#680) 2025-11-23 21:37:59 -08:00
test_create_view.py Tracer mechanism for showing underlying SQL queries 2020-09-07 14:56:59 -07:00
test_default_value.py Transform no longer breaks non-string default values 2023-05-08 14:13:36 -07:00
test_delete.py Swapped the order of a bunch of pytest comparisons 2023-08-17 18:05:13 -07:00
test_docs.py Added pluggy and first hook, register_commands - refs #569, #567 2023-07-22 12:04:31 -07:00
test_duplicate.py Use double quotes not braces for tables and columns (#678) 2025-11-23 20:43:26 -08:00
test_enable_counts.py Use double quotes not braces for tables and columns (#678) 2025-11-23 20:43:26 -08:00
test_extract.py Use double quotes not braces for tables and columns (#678) 2025-11-23 20:43:26 -08:00
test_extracts.py Use double quotes not braces for tables and columns (#678) 2025-11-23 20:43:26 -08:00
test_fts.py Type fixes now enforced by ty 2025-12-16 19:34:45 -08:00
test_get.py Refactored tests into new test_rows.py, refs #76 2020-04-15 18:04:55 -07:00
test_gis.py Type fixes now enforced by ty 2025-12-16 19:34:45 -08:00
test_hypothesis.py Now complies with flake8, refs #291 2021-06-22 18:22:08 -07:00
test_insert_files.py insert-files multiple --pk support, closes #621 2024-03-16 17:33:31 -07:00
test_introspect.py Database as a context manager, fixed many pytest warnings 2025-12-11 16:56:12 -08:00
test_list_mode.py table.insert_all() and table.upsert_all() now take generators of lists/tuples 2025-11-23 12:17:23 -08:00
test_lookup.py Use double quotes not braces for tables and columns (#678) 2025-11-23 20:43:26 -08:00
test_m2m.py Swapped the order of a bunch of pytest comparisons 2023-08-17 18:05:13 -07:00
test_plugins.py Database as a context manager, fixed many pytest warnings 2025-12-11 16:56:12 -08:00
test_query.py Tests for db.query() method, refs #290 2021-06-22 10:43:49 -07:00
test_recipes.py table.insert_all() and table.upsert_all() now take generators of lists/tuples 2025-11-23 12:17:23 -08:00
test_recreate.py Database as a context manager, fixed many pytest warnings 2025-12-11 16:56:12 -08:00
test_register_function.py Database as a context manager, fixed many pytest warnings 2025-12-11 16:56:12 -08:00
test_rows.py Now complies with flake8, refs #291 2021-06-22 18:22:08 -07:00
test_rows_from_file.py Type fixes now enforced by ty 2025-12-16 19:34:45 -08:00
test_sniff.py Detect CSV/TSV column types by default (#683) 2025-11-23 22:23:15 -08:00
test_suggest_column_types.py Fixed bug with null columns, closes #95 2020-03-23 13:31:06 -07:00
test_tracer.py Use double quotes not braces for tables and columns (#678) 2025-11-23 20:43:26 -08:00
test_transform.py Use double quotes not braces for tables and columns (#678) 2025-11-23 20:43:26 -08:00
test_update.py Use double quotes not braces for tables and columns (#678) 2025-11-23 20:43:26 -08:00
test_upsert.py Use ON CONFLICT for upsert, refs #652 2025-05-08 20:37:49 -07:00
test_utils.py sqlite_utils.utils.flatten() function, closes #500 2022-10-18 11:00:35 -07:00
test_wal.py Now complies with flake8, refs #291 2021-06-22 18:22:08 -07:00