mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-28 21:04:13 +02:00
Merge 4a4e38d0a2 into a947dc6739
This commit is contained in:
commit
09f7b4d8b4
2 changed files with 12 additions and 1 deletions
|
|
@ -3800,7 +3800,7 @@ def _rows_from_code(code):
|
||||||
namespace = {}
|
namespace = {}
|
||||||
try:
|
try:
|
||||||
exec(code, namespace)
|
exec(code, namespace)
|
||||||
except SyntaxError as ex:
|
except Exception as ex:
|
||||||
raise click.ClickException("Error in --code: {}".format(ex))
|
raise click.ClickException("Error in --code: {}".format(ex))
|
||||||
rows = namespace.get("rows")
|
rows = namespace.get("rows")
|
||||||
if callable(rows):
|
if callable(rows):
|
||||||
|
|
|
||||||
|
|
@ -880,6 +880,17 @@ def test_insert_code_syntax_error(tmpdir):
|
||||||
assert "Error in --code" in result.output
|
assert "Error in --code" in result.output
|
||||||
|
|
||||||
|
|
||||||
|
def test_insert_code_runtime_error(tmpdir):
|
||||||
|
db_path = str(tmpdir / "dogs.db")
|
||||||
|
result = CliRunner().invoke(
|
||||||
|
cli.cli,
|
||||||
|
["insert", db_path, "creatures", "--code", 'raise ValueError("bad data")'],
|
||||||
|
)
|
||||||
|
assert result.exit_code == 1
|
||||||
|
assert "Error in --code" in result.output
|
||||||
|
assert "bad data" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_insert_code_file_not_found(tmpdir):
|
def test_insert_code_file_not_found(tmpdir):
|
||||||
db_path = str(tmpdir / "dogs.db")
|
db_path = str(tmpdir / "dogs.db")
|
||||||
result = CliRunner().invoke(
|
result = CliRunner().invoke(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue