1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #35515 -- Refactored internal get_and_report_namespace in the shell command.

This commit is contained in:
Natalia
2025-02-07 14:18:54 -03:00
committed by nessita
parent 3839afb63a
commit 44ccd20375
2 changed files with 16 additions and 20 deletions

View File

@@ -85,13 +85,14 @@ class ShellCommandTestCase(SimpleTestCase):
def test_ipython(self):
cmd = shell.Command()
mock_ipython = mock.Mock(start_ipython=mock.MagicMock())
options = {"verbosity": 0, "no_imports": False}
with mock.patch.dict(sys.modules, {"IPython": mock_ipython}):
cmd.ipython({"verbosity": 0, "no_imports": False})
cmd.ipython(options)
self.assertEqual(
mock_ipython.start_ipython.mock_calls,
[mock.call(argv=[], user_ns=cmd.get_and_report_namespace(0))],
[mock.call(argv=[], user_ns=cmd.get_and_report_namespace(**options))],
)
@mock.patch("django.core.management.commands.shell.select.select") # [1]
@@ -106,12 +107,14 @@ class ShellCommandTestCase(SimpleTestCase):
def test_bpython(self):
cmd = shell.Command()
mock_bpython = mock.Mock(embed=mock.MagicMock())
options = {"verbosity": 0, "no_imports": False}
with mock.patch.dict(sys.modules, {"bpython": mock_bpython}):
cmd.bpython({"verbosity": 0, "no_imports": False})
cmd.bpython(options)
self.assertEqual(
mock_bpython.embed.mock_calls, [mock.call(cmd.get_and_report_namespace(0))]
mock_bpython.embed.mock_calls,
[mock.call(cmd.get_and_report_namespace(**options))],
)
@mock.patch("django.core.management.commands.shell.select.select") # [1]
@@ -126,13 +129,14 @@ class ShellCommandTestCase(SimpleTestCase):
def test_python(self):
cmd = shell.Command()
mock_code = mock.Mock(interact=mock.MagicMock())
options = {"verbosity": 0, "no_startup": True, "no_imports": False}
with mock.patch.dict(sys.modules, {"code": mock_code}):
cmd.python({"verbosity": 0, "no_startup": True, "no_imports": False})
cmd.python(options)
self.assertEqual(
mock_code.interact.mock_calls,
[mock.call(local=cmd.get_and_report_namespace(0))],
[mock.call(local=cmd.get_and_report_namespace(**options))],
)
# [1] Patch select to prevent tests failing when the test suite is run