mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-24 02:44:32 +02:00
Fix for --multi combined with --dry-run, closes #415
This commit is contained in:
parent
878d5f5cea
commit
751ab205ac
2 changed files with 40 additions and 1 deletions
|
|
@ -2676,7 +2676,10 @@ def convert(
|
||||||
raise click.ClickException(str(e))
|
raise click.ClickException(str(e))
|
||||||
if dry_run:
|
if dry_run:
|
||||||
# Pull first 20 values for first column and preview them
|
# Pull first 20 values for first column and preview them
|
||||||
db.conn.create_function("preview_transform", 1, lambda v: fn(v) if v else v)
|
preview = lambda v: fn(v) if v else v
|
||||||
|
if multi:
|
||||||
|
preview = lambda v: json.dumps(fn(v), default=repr) if v else v
|
||||||
|
db.conn.create_function("preview_transform", 1, preview)
|
||||||
sql = """
|
sql = """
|
||||||
select
|
select
|
||||||
[{column}] as value,
|
[{column}] as value,
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,42 @@ def test_convert_dryrun(test_db_and_path):
|
||||||
assert result.output.strip().split("\n")[-1] == "Would affect 1 row"
|
assert result.output.strip().split("\n")[-1] == "Would affect 1 row"
|
||||||
|
|
||||||
|
|
||||||
|
def test_convert_multi_dryrun(test_db_and_path):
|
||||||
|
db_path = test_db_and_path[1]
|
||||||
|
result = CliRunner().invoke(
|
||||||
|
cli.cli,
|
||||||
|
[
|
||||||
|
"convert",
|
||||||
|
db_path,
|
||||||
|
"example",
|
||||||
|
"dt",
|
||||||
|
"{'foo': 'bar', 'baz': 1}",
|
||||||
|
"--dry-run",
|
||||||
|
"--multi",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert result.output.strip() == (
|
||||||
|
"5th October 2019 12:04\n"
|
||||||
|
" --- becomes:\n"
|
||||||
|
'{"foo": "bar", "baz": 1}\n'
|
||||||
|
"\n"
|
||||||
|
"6th October 2019 00:05:06\n"
|
||||||
|
" --- becomes:\n"
|
||||||
|
'{"foo": "bar", "baz": 1}\n'
|
||||||
|
"\n"
|
||||||
|
"\n"
|
||||||
|
" --- becomes:\n"
|
||||||
|
"\n"
|
||||||
|
"\n"
|
||||||
|
"None\n"
|
||||||
|
" --- becomes:\n"
|
||||||
|
"None\n"
|
||||||
|
"\n"
|
||||||
|
"Would affect 4 rows"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("drop", (True, False))
|
@pytest.mark.parametrize("drop", (True, False))
|
||||||
def test_convert_output_column(test_db_and_path, drop):
|
def test_convert_output_column(test_db_and_path, drop):
|
||||||
db, db_path = test_db_and_path
|
db, db_path = test_db_and_path
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue