mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-16 07:19:57 +00:00
feat: use IPython shell if available
This commit is contained in:
@ -30,11 +30,11 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
"""
|
||||
args = _default_args(args)
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
application_mock = mocker.patch("code.interact")
|
||||
application_mock = mocker.patch("ahriman.application.interactive_shell.InteractiveShell.interact")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Shell.run(args, repository_id, configuration, report=False)
|
||||
application_mock.assert_called_once_with(local=pytest.helpers.anyvar(int))
|
||||
application_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_run_eval(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
@ -45,7 +45,7 @@ def test_run_eval(args: argparse.Namespace, configuration: Configuration, reposi
|
||||
args = _default_args(args)
|
||||
args.code = """print("hello world")"""
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
application_mock = mocker.patch("code.InteractiveConsole.runcode")
|
||||
application_mock = mocker.patch("ahriman.application.interactive_shell.InteractiveShell.runcode")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Shell.run(args, repository_id, configuration, report=False)
|
||||
@ -62,11 +62,11 @@ def test_run_verbose(args: argparse.Namespace, configuration: Configuration, rep
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
read_mock = mocker.patch("pathlib.Path.read_text", return_value="")
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
application_mock = mocker.patch("code.interact")
|
||||
application_mock = mocker.patch("ahriman.application.interactive_shell.InteractiveShell.interact")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Shell.run(args, repository_id, configuration, report=False)
|
||||
application_mock.assert_called_once_with(local=pytest.helpers.anyvar(int))
|
||||
application_mock.assert_called_once_with()
|
||||
read_mock.assert_called_once_with(encoding="utf8")
|
||||
print_mock.assert_called_once_with(verbose=False, log_fn=pytest.helpers.anyvar(int), separator=": ")
|
||||
|
||||
|
30
tests/ahriman/application/test_interactive_shell.py
Normal file
30
tests/ahriman/application/test_interactive_shell.py
Normal file
@ -0,0 +1,30 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.application.interactive_shell import InteractiveShell
|
||||
|
||||
|
||||
def test_interact(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call IPython shell
|
||||
"""
|
||||
banner_mock = mocker.patch("IPython.terminal.embed.InteractiveShellEmbed.show_banner")
|
||||
interact_mock = mocker.patch("IPython.terminal.embed.InteractiveShellEmbed.interact")
|
||||
|
||||
shell = InteractiveShell()
|
||||
shell.interact()
|
||||
banner_mock.assert_called_once_with()
|
||||
interact_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_interact_import_error(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call builtin shell if no IPython available
|
||||
"""
|
||||
pytest.helpers.import_error("IPython.terminal.embed", ["InteractiveShellEmbed"], mocker)
|
||||
interact_mock = mocker.patch("code.InteractiveConsole.interact")
|
||||
|
||||
shell = InteractiveShell()
|
||||
shell.interact()
|
||||
interact_mock.assert_called_once_with(shell)
|
Reference in New Issue
Block a user