From eea3851d40ea7e49cf27905cca19d200cf4cdbe4 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 18 Jun 2021 07:55:26 -0700 Subject: [PATCH] Added test, formatted with Black - refs #276, #277 --- sqlite_utils/cli.py | 9 +++++++-- tests/test_cli.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index 390f43e..69e04e3 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -16,7 +16,7 @@ import csv as csv_std import tabulate from .utils import file_progress, find_spatialite, sqlite3, decode_base64_values -CONTEXT_SETTINGS = dict(help_option_names=['-h','--help']) +CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) VALID_COLUMN_TYPES = ("INTEGER", "TEXT", "FLOAT", "BLOB") @@ -91,7 +91,12 @@ def load_extension_option(fn): )(fn) -@click.group(cls=DefaultGroup, default="query", default_if_no_args=True, context_settings=CONTEXT_SETTINGS) +@click.group( + cls=DefaultGroup, + default="query", + default_if_no_args=True, + context_settings=CONTEXT_SETTINGS, +) @click.version_option() def cli(): "Commands for interacting with a SQLite database" diff --git a/tests/test_cli.py b/tests/test_cli.py index c68c7db..b085ea4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -24,6 +24,22 @@ def db_path(tmpdir): return path +@pytest.mark.parametrize( + "options", + ( + ["-h"], + ["--help"], + ["insert", "-h"], + ["insert", "--help"], + ), +) +def test_help(options): + result = CliRunner().invoke(cli.cli, options) + assert result.exit_code == 0 + assert result.output.startswith("Usage: ") + assert "-h, --help" in result.output + + def test_tables(db_path): result = CliRunner().invoke(cli.cli, ["tables", db_path]) assert '[{"table": "Gosh"},\n {"table": "Gosh2"}]' == result.output.strip()