diff options
| author | Tom Forbes <tom@tomforb.es> | 2020-06-18 12:04:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-18 13:04:10 +0200 |
| commit | 8a902b7ee622ada258d15fb122092c1f02b82698 (patch) | |
| tree | 908598a5f83b76989e834fe946a6cdbc50131c41 /tests/utils_tests/test_autoreload.py | |
| parent | 7f4db2d82b1385d1026c441e25abd4cb19fcccc6 (diff) | |
Fixed #31716 -- Fixed detection of console scripts in autoreloader on Windows.
Diffstat (limited to 'tests/utils_tests/test_autoreload.py')
| -rw-r--r-- | tests/utils_tests/test_autoreload.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py index 09656b8599..f4ecb38777 100644 --- a/tests/utils_tests/test_autoreload.py +++ b/tests/utils_tests/test_autoreload.py @@ -14,6 +14,7 @@ from pathlib import Path from subprocess import CompletedProcess from unittest import mock, skip, skipIf +import django.__main__ from django.apps.registry import Apps from django.test import SimpleTestCase from django.test.utils import extend_sys_path @@ -153,6 +154,55 @@ class TestIterModulesAndFiles(SimpleTestCase): ) +class TestChildArguments(SimpleTestCase): + @mock.patch('sys.argv', [django.__main__.__file__, 'runserver']) + @mock.patch('sys.warnoptions', []) + def test_run_as_module(self): + self.assertEqual( + autoreload.get_child_arguments(), + [sys.executable, '-m', 'django', 'runserver'] + ) + + @mock.patch('sys.argv', [__file__, 'runserver']) + @mock.patch('sys.warnoptions', ['error']) + def test_warnoptions(self): + self.assertEqual( + autoreload.get_child_arguments(), + [sys.executable, '-Werror', __file__, 'runserver'] + ) + + @mock.patch('sys.warnoptions', []) + def test_exe_fallback(self): + tmpdir = tempfile.TemporaryDirectory() + self.addCleanup(tmpdir.cleanup) + exe_path = Path(tmpdir.name) / 'django-admin.exe' + exe_path.touch() + with mock.patch('sys.argv', [exe_path.with_suffix(''), 'runserver']): + self.assertEqual( + autoreload.get_child_arguments(), + [exe_path, 'runserver'] + ) + + @mock.patch('sys.warnoptions', []) + def test_entrypoint_fallback(self): + tmpdir = tempfile.TemporaryDirectory() + self.addCleanup(tmpdir.cleanup) + script_path = Path(tmpdir.name) / 'django-admin-script.py' + script_path.touch() + with mock.patch('sys.argv', [script_path.with_name('django-admin'), 'runserver']): + self.assertEqual( + autoreload.get_child_arguments(), + [sys.executable, script_path, 'runserver'] + ) + + @mock.patch('sys.argv', ['does-not-exist', 'runserver']) + @mock.patch('sys.warnoptions', []) + def test_raises_runtimeerror(self): + msg = 'Script does-not-exist does not exist.' + with self.assertRaisesMessage(RuntimeError, msg): + autoreload.get_child_arguments() + + class TestCommonRoots(SimpleTestCase): def test_common_roots(self): paths = ( @@ -360,6 +410,9 @@ class RestartWithReloaderTests(SimpleTestCase): return mock_call def test_manage_py(self): + script = Path('manage.py') + script.touch() + self.addCleanup(script.unlink) argv = ['./manage.py', 'runserver'] mock_call = self.patch_autoreload(argv) autoreload.restart_with_reloader() |
