diff options
author | William Schwartz <wkschwartz@gmail.com> | 2020-11-09 16:41:13 -0600 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-11-11 09:18:26 +0100 |
commit | c0fc5ba3808becefcdc8b878f133fd2a864a072d (patch) | |
tree | 0078f9f6c1fd6c3ba7f2b5862653e604e2fdc4a1 /tests/shell | |
parent | d26d1c196dbb82bf034608576b1019b163086e51 (diff) | |
download | django-c0fc5ba3808becefcdc8b878f133fd2a864a072d.tar.gz |
Fixed #32183 -- Fixed shell crash when passing code with nested scopes.
Diffstat (limited to 'tests/shell')
-rw-r--r-- | tests/shell/tests.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/shell/tests.py b/tests/shell/tests.py index 13cad10c21..d861b5599b 100644 --- a/tests/shell/tests.py +++ b/tests/shell/tests.py @@ -10,6 +10,12 @@ from django.test.utils import captured_stdin, captured_stdout class ShellCommandTestCase(SimpleTestCase): script_globals = 'print("__name__" in globals())' + script_with_inline_function = ( + 'import django\n' + 'def f():\n' + ' print(django.__version__)\n' + 'f()' + ) def test_command_option(self): with self.assertLogs('test', 'INFO') as cm: @@ -27,6 +33,11 @@ class ShellCommandTestCase(SimpleTestCase): call_command('shell', command=self.script_globals) self.assertEqual(stdout.getvalue().strip(), 'True') + def test_command_option_inline_function_call(self): + with captured_stdout() as stdout: + call_command('shell', command=self.script_with_inline_function) + self.assertEqual(stdout.getvalue().strip(), __version__) + @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): @@ -48,6 +59,18 @@ class ShellCommandTestCase(SimpleTestCase): call_command('shell') 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') # [1] + def test_stdin_read_inline_function_call(self, select): + with captured_stdin() as stdin, captured_stdout() as stdout: + stdin.write(self.script_with_inline_function) + stdin.seek(0) + call_command('shell') + self.assertEqual(stdout.getvalue().strip(), __version__) + @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): |