diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index c61d163..e4ac573 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -84,7 +84,10 @@ def cli(): default=False, ) @click.option( - "--schema", help="Include schema for each table", is_flag=True, default=False, + "--schema", + help="Include schema for each table", + is_flag=True, + default=False, ) def tables( path, @@ -161,10 +164,23 @@ def tables( default=False, ) @click.option( - "--schema", help="Include schema for each view", is_flag=True, default=False, + "--schema", + help="Include schema for each view", + is_flag=True, + default=False, ) def views( - path, counts, nl, arrays, csv, no_headers, table, fmt, json_cols, columns, schema, + path, + counts, + nl, + arrays, + csv, + no_headers, + table, + fmt, + json_cols, + columns, + schema, ): """List the views in the database""" tables.callback( @@ -585,7 +601,9 @@ def upsert( @click.argument("columns", nargs=-1, required=True) @click.option("--pk", help="Column to use as primary key") @click.option( - "--not-null", multiple=True, help="Columns that should be created as NOT NULL", + "--not-null", + multiple=True, + help="Columns that should be created as NOT NULL", ) @click.option( "--default", @@ -600,10 +618,14 @@ def upsert( help="Column, other table, other column to set as a foreign key", ) @click.option( - "--ignore", is_flag=True, help="If table already exists, do nothing", + "--ignore", + is_flag=True, + help="If table already exists, do nothing", ) @click.option( - "--replace", is_flag=True, help="If table already exists, replace it", + "--replace", + is_flag=True, + help="If table already exists, replace it", ) def create_table(path, table, columns, pk, not_null, default, fk, ignore, replace): "Add an index to the specified table covering the specified columns" @@ -664,10 +686,14 @@ def drop_table(path, table): @click.argument("view") @click.argument("select") @click.option( - "--ignore", is_flag=True, help="If view already exists, do nothing", + "--ignore", + is_flag=True, + help="If view already exists, do nothing", ) @click.option( - "--replace", is_flag=True, help="If view already exists, replace it", + "--replace", + is_flag=True, + help="If view already exists, replace it", ) def create_view(path, view, select, ignore, replace): "Create a view for the provided SELECT query" @@ -720,7 +746,9 @@ def drop_view(path, view): help="Named :parameters for SQL query", ) @click.option( - "--load-extension", multiple=True, help="SQLite extensions to load", + "--load-extension", + multiple=True, + help="SQLite extensions to load", ) def query( path, @@ -808,7 +836,11 @@ def rows(ctx, path, dbtable, nl, arrays, csv, no_headers, table, fmt, json_cols) type=click.Path(file_okay=True, dir_okay=True, allow_dash=True), ) @click.option( - "-c", "--column", type=str, multiple=True, help="Column definitions for the table", + "-c", + "--column", + type=str, + multiple=True, + help="Column definitions for the table", ) @click.option("--pk", type=str, help="Column to use as primary key") @click.option("--alter", is_flag=True, help="Alter table to add missing columns") diff --git a/tests/test_cli.py b/tests/test_cli.py index 71a2503..e2ae298 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -800,7 +800,11 @@ def test_query_json_binary(db_path): db = Database(db_path) with db.conn: db["files"].insert( - {"name": "lorem.txt", "sz": 16984, "data": LOREM_IPSUM_COMPRESSED,}, + { + "name": "lorem.txt", + "sz": 16984, + "data": LOREM_IPSUM_COMPRESSED, + }, pk="name", ) result = CliRunner().invoke(cli.cli, [db_path, "select name, sz, data from files"]) @@ -1002,9 +1006,9 @@ def test_upsert_alter(db_path, tmpdir): cli.cli, ["upsert", db_path, "dogs", json_path, "--pk", "id", "--alter"] ) assert 0 == result.exit_code - assert [{"id": 1, "name": "Cleo", "age": 5},] == db.execute_returning_dicts( - "select * from dogs order by id" - ) + assert [ + {"id": 1, "name": "Cleo", "age": 5}, + ] == db.execute_returning_dicts("select * from dogs order by id") @pytest.mark.parametrize( @@ -1012,7 +1016,12 @@ def test_upsert_alter(db_path, tmpdir): [ # No primary key ( - ["name", "text", "age", "integer",], + [ + "name", + "text", + "age", + "integer", + ], ("CREATE TABLE [t] (\n [name] TEXT,\n [age] INTEGER\n)"), ), # All types: @@ -1057,7 +1066,14 @@ def test_create_table(args, schema): runner = CliRunner() with runner.isolated_filesystem(): result = runner.invoke( - cli.cli, ["create-table", "test.db", "t",] + args, catch_exceptions=False + cli.cli, + [ + "create-table", + "test.db", + "t", + ] + + args, + catch_exceptions=False, ) assert 0 == result.exit_code db = Database("test.db") @@ -1217,7 +1233,14 @@ def test_drop_table(): db = Database("test.db") db["t"].create({"pk": int}, pk="pk") assert "t" in db.table_names() - result = runner.invoke(cli.cli, ["drop-table", "test.db", "t",],) + result = runner.invoke( + cli.cli, + [ + "drop-table", + "test.db", + "t", + ], + ) assert 0 == result.exit_code assert "t" not in db.table_names() @@ -1227,7 +1250,14 @@ def test_drop_table_error(): with runner.isolated_filesystem(): db = Database("test.db") db["t"].create({"pk": int}, pk="pk") - result = runner.invoke(cli.cli, ["drop-table", "test.db", "t2",],) + result = runner.invoke( + cli.cli, + [ + "drop-table", + "test.db", + "t2", + ], + ) assert 1 == result.exit_code assert 'Error: Table "t2" does not exist' == result.output.strip() @@ -1238,7 +1268,14 @@ def test_drop_view(): db = Database("test.db") db.create_view("hello", "select 1") assert "hello" in db.view_names() - result = runner.invoke(cli.cli, ["drop-view", "test.db", "hello",],) + result = runner.invoke( + cli.cli, + [ + "drop-view", + "test.db", + "hello", + ], + ) assert 0 == result.exit_code assert "hello" not in db.view_names() @@ -1248,7 +1285,14 @@ def test_drop_view_error(): with runner.isolated_filesystem(): db = Database("test.db") db["t"].create({"pk": int}, pk="pk") - result = runner.invoke(cli.cli, ["drop-view", "test.db", "t2",],) + result = runner.invoke( + cli.cli, + [ + "drop-view", + "test.db", + "t2", + ], + ) assert 1 == result.exit_code assert 'Error: View "t2" does not exist' == result.output.strip() @@ -1287,7 +1331,10 @@ def test_disable_wal(): @pytest.mark.parametrize( "args,expected", [ - ([], '[{"rows_affected": 1}]',), + ( + [], + '[{"rows_affected": 1}]', + ), (["-t"], "rows_affected\n---------------\n 1"), ], ) @@ -1295,7 +1342,9 @@ def test_query_update(db_path, args, expected): db = Database(db_path) with db.conn: db["dogs"].insert_all( - [{"id": 1, "age": 4, "name": "Cleo"},] + [ + {"id": 1, "age": 4, "name": "Cleo"}, + ] ) result = CliRunner().invoke( cli.cli, [db_path, "update dogs set age = 5 where name = 'Cleo'"] + args diff --git a/tests/test_create.py b/tests/test_create.py index fc8edc0..f6fad00 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -669,7 +669,12 @@ def test_create_index_if_not_exists(fresh_db): ["list with", "two items"], {"dictionary": "simple"}, {"dictionary": {"nested": "complex"}}, - collections.OrderedDict([("key1", {"nested": "complex"}), ("key2", "foo"),]), + collections.OrderedDict( + [ + ("key1", {"nested": "complex"}), + ("key2", "foo"), + ] + ), [{"list": "of"}, {"two": "dicts"}], ), ) diff --git a/tests/test_fts.py b/tests/test_fts.py index bac4117..b1a946d 100644 --- a/tests/test_fts.py +++ b/tests/test_fts.py @@ -98,7 +98,8 @@ def test_fts_tokenize(fresh_db): table.insert_all(search_records) # Test without porter stemming table.enable_fts( - ["text", "country"], fts_version="FTS{}".format(fts_version), + ["text", "country"], + fts_version="FTS{}".format(fts_version), ) assert [] == table.search("bite") # Test WITH stemming