Adding upstream version 1.15.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e46cfa9e3b
commit
9e5fdd01c3
10 changed files with 141 additions and 23 deletions
|
@ -59,7 +59,7 @@ def test_llm_command_with_c_flag_and_fenced_sql(mock_run_cmd, mock_llm, executor
|
|||
|
||||
test_text = r"\llm -c 'Rewrite the SQL without CTE'"
|
||||
|
||||
result, sql = handle_llm(test_text, executor)
|
||||
result, sql, duration = handle_llm(test_text, executor)
|
||||
|
||||
# We expect the function to return (result, sql), but result might be "" if verbose is not set
|
||||
# By default, `verbose` is false unless text has something like \llm --verbose?
|
||||
|
@ -67,6 +67,7 @@ def test_llm_command_with_c_flag_and_fenced_sql(mock_run_cmd, mock_llm, executor
|
|||
# Our test_text doesn't set verbose => we expect "" for the returned context.
|
||||
assert result == ""
|
||||
assert sql == "SELECT * FROM table;"
|
||||
assert isinstance(duration, float)
|
||||
|
||||
|
||||
@patch("litecli.packages.special.llm.llm")
|
||||
|
@ -87,6 +88,23 @@ def test_llm_command_known_subcommand(mock_run_cmd, mock_llm, executor):
|
|||
# And the function should raise FinishIteration(None)
|
||||
assert exc_info.value.args[0] is None
|
||||
|
||||
@patch("litecli.packages.special.llm.llm")
|
||||
@patch("litecli.packages.special.llm.run_external_cmd")
|
||||
def test_llm_command_with_help_flag(mock_run_cmd, mock_llm, executor):
|
||||
"""
|
||||
If the parts[0] is --help, we do NOT capture output, we just call run_external_cmd
|
||||
and then raise FinishIteration.
|
||||
"""
|
||||
# Let's assume 'models' is in LLM_CLI_COMMANDS
|
||||
test_text = r"\llm --help"
|
||||
|
||||
with pytest.raises(FinishIteration) as exc_info:
|
||||
handle_llm(test_text, executor)
|
||||
|
||||
# We check that run_external_cmd was called with these arguments:
|
||||
mock_run_cmd.assert_called_once_with("llm", "--help", restart_cli=False)
|
||||
# And the function should raise FinishIteration(None)
|
||||
assert exc_info.value.args[0] is None
|
||||
|
||||
@patch("litecli.packages.special.llm.llm")
|
||||
@patch("litecli.packages.special.llm.run_external_cmd")
|
||||
|
@ -116,7 +134,7 @@ def test_llm_command_with_prompt(mock_sql_using_llm, mock_ensure_template, mock_
|
|||
mock_sql_using_llm.return_value = ("context from LLM", "SELECT 1;")
|
||||
|
||||
test_text = r"\llm prompt 'Magic happening here?'"
|
||||
context, sql = handle_llm(test_text, executor)
|
||||
context, sql, duration = handle_llm(test_text, executor)
|
||||
|
||||
# ensure_litecli_template should be called
|
||||
mock_ensure_template.assert_called_once()
|
||||
|
@ -126,6 +144,7 @@ def test_llm_command_with_prompt(mock_sql_using_llm, mock_ensure_template, mock_
|
|||
mock_sql_using_llm.assert_called()
|
||||
assert context == ""
|
||||
assert sql == "SELECT 1;"
|
||||
assert isinstance(duration, float)
|
||||
|
||||
|
||||
@patch("litecli.packages.special.llm.llm")
|
||||
|
@ -138,12 +157,13 @@ def test_llm_command_question_with_context(mock_sql_using_llm, mock_ensure_templ
|
|||
mock_sql_using_llm.return_value = ("You have context!", "SELECT 2;")
|
||||
|
||||
test_text = r"\llm 'Top 10 downloads by size.'"
|
||||
context, sql = handle_llm(test_text, executor)
|
||||
context, sql, duration = handle_llm(test_text, executor)
|
||||
|
||||
mock_ensure_template.assert_called_once()
|
||||
mock_sql_using_llm.assert_called()
|
||||
assert context == ""
|
||||
assert sql == "SELECT 2;"
|
||||
assert isinstance(duration, float)
|
||||
|
||||
|
||||
@patch("litecli.packages.special.llm.llm")
|
||||
|
@ -156,7 +176,9 @@ def test_llm_command_question_verbose(mock_sql_using_llm, mock_ensure_template,
|
|||
mock_sql_using_llm.return_value = ("Verbose context, oh yeah!", "SELECT 42;")
|
||||
|
||||
test_text = r"\llm+ 'Top 10 downloads by size.'"
|
||||
context, sql = handle_llm(test_text, executor)
|
||||
context, sql, duration = handle_llm(test_text, executor)
|
||||
|
||||
assert context == "Verbose context, oh yeah!"
|
||||
assert sql == "SELECT 42;"
|
||||
|
||||
assert isinstance(duration, float)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue