summaryrefslogtreecommitdiff
path: root/tests/shell
diff options
context:
space:
mode:
authorPeter Inglesby <peter.inglesby@gmail.com>2017-01-12 18:12:21 +0000
committerTim Graham <timograham@gmail.com>2017-01-12 13:12:21 -0500
commit0b2e5da6ed946f10b4e0c1959f19d98449815715 (patch)
treedd28f638bffe5db09a5ce59c08ae2b818a4f5863 /tests/shell
parente303739f8ee2ca1d087b527ce56f3f5bc5291049 (diff)
Fixed #27721 -- Added interface name to shell's IPython/bython import error.
Diffstat (limited to 'tests/shell')
-rw-r--r--tests/shell/tests.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/shell/tests.py b/tests/shell/tests.py
index 11f1826d30..f2d1d0e392 100644
--- a/tests/shell/tests.py
+++ b/tests/shell/tests.py
@@ -2,7 +2,7 @@ import sys
import unittest
from django import __version__
-from django.core.management import call_command
+from django.core.management import CommandError, call_command
from django.test import SimpleTestCase, mock
from django.test.utils import captured_stdin, captured_stdout, patch_logger
@@ -29,3 +29,24 @@ class ShellCommandTestCase(SimpleTestCase):
stdin.seek(0)
call_command('shell')
self.assertEqual(stdout.getvalue().strip(), '100')
+
+ @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):
+ select.return_value = ([], [], [])
+ with self.assertRaisesMessage(CommandError, "Couldn't import ipython interface."):
+ call_command('shell', interface='ipython')
+
+ @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):
+ select.return_value = ([], [], [])
+ with self.assertRaisesMessage(CommandError, "Couldn't import bpython interface."):
+ call_command('shell', interface='bpython')
+
+ # [1] Patch select to prevent tests failing when 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.
+ # This causes problems because of the call to select.select() towards the
+ # end of shell's handle() method.