summaryrefslogtreecommitdiff
path: root/tests/shell
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-11-11 09:01:44 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-11-11 09:17:20 +0100
commitd26d1c196dbb82bf034608576b1019b163086e51 (patch)
tree4424e1e71765e504b77ab1b1b79bde38c79aa2d8 /tests/shell
parent50c3ac6fa9b7c8a94a6d1dc87edf775e3bc4d575 (diff)
Refs #25680 -- Added shell tests for globals available in passed commands.
Diffstat (limited to 'tests/shell')
-rw-r--r--tests/shell/tests.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/shell/tests.py b/tests/shell/tests.py
index f33a9ae701..13cad10c21 100644
--- a/tests/shell/tests.py
+++ b/tests/shell/tests.py
@@ -9,6 +9,7 @@ from django.test.utils import captured_stdin, captured_stdout
class ShellCommandTestCase(SimpleTestCase):
+ script_globals = 'print("__name__" in globals())'
def test_command_option(self):
with self.assertLogs('test', 'INFO') as cm:
@@ -21,6 +22,11 @@ class ShellCommandTestCase(SimpleTestCase):
)
self.assertEqual(cm.records[0].getMessage(), __version__)
+ def test_command_option_globals(self):
+ with captured_stdout() as stdout:
+ call_command('shell', command=self.script_globals)
+ self.assertEqual(stdout.getvalue().strip(), 'True')
+
@unittest.skipIf(sys.platform == 'win32', "Windows select() doesn't support file descriptors.")
@mock.patch('django.core.management.commands.shell.select')
def test_stdin_read(self, select):
@@ -30,6 +36,18 @@ class ShellCommandTestCase(SimpleTestCase):
call_command('shell')
self.assertEqual(stdout.getvalue().strip(), '100')
+ @unittest.skipIf(
+ sys.platform == 'win32',
+ "Windows select() doesn't support file descriptors.",
+ )
+ @mock.patch('django.core.management.commands.shell.select') # [1]
+ def test_stdin_read_globals(self, select):
+ with captured_stdin() as stdin, captured_stdout() as stdout:
+ stdin.write(self.script_globals)
+ stdin.seek(0)
+ call_command('shell')
+ self.assertEqual(stdout.getvalue().strip(), 'True')
+
@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):