Skip to content

Commit c680761

Browse files
committed
Use message_history arg for run_chat; fix typos in tests
1 parent c487d58 commit c680761

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

pydantic_ai_slim/pydantic_ai/_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def cli( # noqa: C901
232232
return 0
233233

234234
try:
235-
return asyncio.run(run_chat(stream, agent, console, code_theme, prog_name, history=history))
235+
return asyncio.run(run_chat(stream, agent, console, code_theme, prog_name, message_history=history))
236236
except KeyboardInterrupt: # pragma: no cover
237237
return 0
238238

tests/test_cli.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _create_test_module(**namespace: Any) -> None:
5858

5959

6060
@pytest.fixture
61-
def emtpy_last_conversation_path():
61+
def empty_last_conversation_path():
6262
path = PYDANTIC_AI_HOME / LAST_CONVERSATION_FILENAME
6363

6464
if path.exists():
@@ -180,32 +180,32 @@ def test_cli_continue_last_conversation(
180180
args: list[str],
181181
capfd: CaptureFixture[str],
182182
env: TestEnv,
183-
emtpy_last_conversation_path: Path,
183+
empty_last_conversation_path: Path,
184184
):
185185
env.set('OPENAI_API_KEY', 'test')
186186
with cli_agent.override(model=TestModel(custom_output_text='# world')):
187187
assert cli(args) == 0
188188
assert capfd.readouterr().out.splitlines() == snapshot([IsStr(), '# world'])
189-
assert emtpy_last_conversation_path.exists()
190-
content = emtpy_last_conversation_path.read_text()
189+
assert empty_last_conversation_path.exists()
190+
content = empty_last_conversation_path.read_text()
191191
assert content
192192

193193
assert cli(args) == 0
194194
assert capfd.readouterr().out.splitlines() == snapshot([IsStr(), '# world'])
195-
assert emtpy_last_conversation_path.exists()
196-
# verity that new content is appended to the file
197-
assert len(emtpy_last_conversation_path.read_text()) > len(content)
195+
assert empty_last_conversation_path.exists()
196+
# verify that new content is appended to the file
197+
assert len(empty_last_conversation_path.read_text()) > len(content)
198198

199199

200200
@pytest.mark.parametrize('args', [['hello', '-c'], ['hello', '--continue']])
201201
def test_cli_continue_last_conversation_corrupted_file(
202202
args: list[str],
203203
capfd: CaptureFixture[str],
204204
env: TestEnv,
205-
emtpy_last_conversation_path: Path,
205+
empty_last_conversation_path: Path,
206206
):
207207
env.set('OPENAI_API_KEY', 'test')
208-
emtpy_last_conversation_path.write_text('not a valid json')
208+
empty_last_conversation_path.write_text('not a valid json')
209209
with cli_agent.override(model=TestModel(custom_output_text='# world')):
210210
assert cli(args) == 0
211211
assert capfd.readouterr().out.splitlines() == snapshot(
@@ -216,8 +216,8 @@ def test_cli_continue_last_conversation_corrupted_file(
216216
'# world',
217217
]
218218
)
219-
assert emtpy_last_conversation_path.exists()
220-
assert emtpy_last_conversation_path.read_text()
219+
assert empty_last_conversation_path.exists()
220+
assert empty_last_conversation_path.read_text()
221221

222222

223223
def test_chat(capfd: CaptureFixture[str], mocker: MockerFixture, env: TestEnv):
@@ -320,21 +320,42 @@ def test_code_theme_unset(mocker: MockerFixture, env: TestEnv):
320320
env.set('OPENAI_API_KEY', 'test')
321321
mock_run_chat = mocker.patch('pydantic_ai._cli.run_chat')
322322
cli([])
323-
mock_run_chat.assert_awaited_once_with(True, IsInstance(Agent), IsInstance(Console), 'monokai', 'pai', history=None)
323+
mock_run_chat.assert_awaited_once_with(
324+
True,
325+
IsInstance(Agent),
326+
IsInstance(Console),
327+
'monokai',
328+
'pai',
329+
message_history=None,
330+
)
324331

325332

326333
def test_code_theme_light(mocker: MockerFixture, env: TestEnv):
327334
env.set('OPENAI_API_KEY', 'test')
328335
mock_run_chat = mocker.patch('pydantic_ai._cli.run_chat')
329336
cli(['--code-theme=light'])
330-
mock_run_chat.assert_awaited_once_with(True, IsInstance(Agent), IsInstance(Console), 'default', 'pai', history=None)
337+
mock_run_chat.assert_awaited_once_with(
338+
True,
339+
IsInstance(Agent),
340+
IsInstance(Console),
341+
'default',
342+
'pai',
343+
message_history=None,
344+
)
331345

332346

333347
def test_code_theme_dark(mocker: MockerFixture, env: TestEnv):
334348
env.set('OPENAI_API_KEY', 'test')
335349
mock_run_chat = mocker.patch('pydantic_ai._cli.run_chat')
336350
cli(['--code-theme=dark'])
337-
mock_run_chat.assert_awaited_once_with(True, IsInstance(Agent), IsInstance(Console), 'monokai', 'pai', history=None)
351+
mock_run_chat.assert_awaited_once_with(
352+
True,
353+
IsInstance(Agent),
354+
IsInstance(Console),
355+
'monokai',
356+
'pai',
357+
message_history=None,
358+
)
338359

339360

340361
def test_agent_to_cli_sync(mocker: MockerFixture, env: TestEnv):

0 commit comments

Comments
 (0)