Merging upstream version 1.15.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e6604cf449
commit
d4dff17dce
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)
|
||||
|
|
|
@ -40,6 +40,18 @@ def complete_event():
|
|||
return Mock()
|
||||
|
||||
|
||||
def test_escape_name(completer):
|
||||
|
||||
for name, expected_name in [# Upper case name shouldn't be escaped
|
||||
("BAR", "BAR"),
|
||||
# This name is escaped and should start with back tick
|
||||
("2025todos", "`2025todos`"),
|
||||
# normal case
|
||||
("people", "people"),
|
||||
# table name with _underscore should not be escaped
|
||||
("django_users", "django_users")]:
|
||||
assert completer.escape_name(name) == expected_name
|
||||
|
||||
def test_empty_string_completion(completer, complete_event):
|
||||
text = ""
|
||||
position = 0
|
||||
|
@ -302,7 +314,7 @@ def test_auto_escaped_col_names(completer, complete_event):
|
|||
result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
|
||||
assert result == [
|
||||
Completion(text="*", start_position=0),
|
||||
Completion(text="`ABC`", start_position=0),
|
||||
Completion(text="ABC", start_position=0),
|
||||
Completion(text="`insert`", start_position=0),
|
||||
Completion(text="id", start_position=0),
|
||||
] + list(map(Completion, completer.functions)) + [Completion(text="select", start_position=0)] + list(
|
||||
|
@ -317,7 +329,7 @@ def test_un_escaped_table_names(completer, complete_event):
|
|||
assert result == list(
|
||||
[
|
||||
Completion(text="*", start_position=0),
|
||||
Completion(text="`ABC`", start_position=0),
|
||||
Completion(text="ABC", start_position=0),
|
||||
Completion(text="`insert`", start_position=0),
|
||||
Completion(text="id", start_position=0),
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue