summaryrefslogtreecommitdiff
path: root/tests/shell
diff options
context:
space:
mode:
authorSalvo Polizzi <plzslv03a25c351k@studium.unict.it>2024-06-11 10:08:02 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-06-27 16:42:55 +0200
commitdfac15d57048432fd8ad3dd189276d1ef304fc4c (patch)
treef575cad3dbeacd2819bfd4d2bfe8438b8c51ae74 /tests/shell
parentf0d05a747f7a099e6c6bc58c42a787546d2212e7 (diff)
Fixed #35517, Refs #35515 -- Improved test coverage of shell command.
Diffstat (limited to 'tests/shell')
-rw-r--r--tests/shell/tests.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/shell/tests.py b/tests/shell/tests.py
index 1a5f22f032..ca823f6290 100644
--- a/tests/shell/tests.py
+++ b/tests/shell/tests.py
@@ -4,6 +4,7 @@ from unittest import mock
from django import __version__
from django.core.management import CommandError, call_command
+from django.core.management.commands import shell
from django.test import SimpleTestCase
from django.test.utils import captured_stdin, captured_stdout
@@ -70,6 +71,15 @@ class ShellCommandTestCase(SimpleTestCase):
call_command("shell")
self.assertEqual(stdout.getvalue().strip(), __version__)
+ def test_ipython(self):
+ cmd = shell.Command()
+ mock_ipython = mock.Mock(start_ipython=mock.MagicMock())
+
+ with mock.patch.dict(sys.modules, {"IPython": mock_ipython}):
+ cmd.ipython({})
+
+ self.assertEqual(mock_ipython.start_ipython.mock_calls, [mock.call(argv=[])])
+
@mock.patch("django.core.management.commands.shell.select.select") # [1]
@mock.patch.dict("sys.modules", {"IPython": None})
def test_shell_with_ipython_not_installed(self, select):
@@ -79,6 +89,15 @@ class ShellCommandTestCase(SimpleTestCase):
):
call_command("shell", interface="ipython")
+ def test_bpython(self):
+ cmd = shell.Command()
+ mock_bpython = mock.Mock(embed=mock.MagicMock())
+
+ with mock.patch.dict(sys.modules, {"bpython": mock_bpython}):
+ cmd.bpython({})
+
+ self.assertEqual(mock_bpython.embed.mock_calls, [mock.call()])
+
@mock.patch("django.core.management.commands.shell.select.select") # [1]
@mock.patch.dict("sys.modules", {"bpython": None})
def test_shell_with_bpython_not_installed(self, select):
@@ -88,7 +107,16 @@ class ShellCommandTestCase(SimpleTestCase):
):
call_command("shell", interface="bpython")
- # [1] Patch select to prevent tests failing when when the test suite is run
+ def test_python(self):
+ cmd = shell.Command()
+ mock_code = mock.Mock(interact=mock.MagicMock())
+
+ with mock.patch.dict(sys.modules, {"code": mock_code}):
+ cmd.python({"no_startup": True})
+
+ self.assertEqual(mock_code.interact.mock_calls, [mock.call(local={})])
+
+ # [1] Patch select to prevent tests failing when the test suite is run
# in parallel mode. The tests are run in a subprocess and the subprocess's
# stdin is closed and replaced by /dev/null. Reading from /dev/null always
# returns EOF and so select always shows that sys.stdin is ready to read.