diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/utils_tests/test_autoreload.py | 64 |
1 files changed, 6 insertions, 58 deletions
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py index f47ad46b8b..f0e692d274 100644 --- a/tests/utils_tests/test_autoreload.py +++ b/tests/utils_tests/test_autoreload.py @@ -253,7 +253,7 @@ class StartDjangoTests(SimpleTestCase): self.assertEqual(mocked_thread.call_count, 1) self.assertEqual( mocked_thread.call_args[1], - {'target': fake_main_func, 'args': (123,), 'kwargs': {'abc': 123}} + {'target': fake_main_func, 'args': (123,), 'kwargs': {'abc': 123}, 'name': 'django-main-thread'} ) self.assertSequenceEqual(fake_thread.setDaemon.call_args[0], [True]) self.assertTrue(fake_thread.start.called) @@ -376,26 +376,6 @@ class IntegrationTests: @mock.patch('django.utils.autoreload.BaseReloader.notify_file_changed') @mock.patch('django.utils.autoreload.iter_all_python_module_files', return_value=frozenset()) - def test_nonexistent_file(self, mocked_modules, notify_mock): - self.reloader.watch_file(self.nonexistent_file) - with self.tick_twice(): - self.ensure_file(self.nonexistent_file) - self.assertEqual(notify_mock.call_count, 1) - self.assertCountEqual(notify_mock.call_args[0], [self.nonexistent_file]) - - @mock.patch('django.utils.autoreload.BaseReloader.notify_file_changed') - @mock.patch('django.utils.autoreload.iter_all_python_module_files', return_value=frozenset()) - def test_nonexistent_file_in_non_existing_directory(self, mocked_modules, notify_mock): - non_existing_directory = self.tempdir / 'non_existing_dir' - nonexistent_file = non_existing_directory / 'test' - self.reloader.watch_file(nonexistent_file) - with self.tick_twice(): - self.ensure_file(nonexistent_file) - self.assertEqual(notify_mock.call_count, 1) - self.assertCountEqual(notify_mock.call_args[0], [nonexistent_file]) - - @mock.patch('django.utils.autoreload.BaseReloader.notify_file_changed') - @mock.patch('django.utils.autoreload.iter_all_python_module_files', return_value=frozenset()) def test_glob(self, mocked_modules, notify_mock): non_py_file = self.ensure_file(self.tempdir / 'non_py_file') self.reloader.watch_dir(self.tempdir, '*.py') @@ -407,18 +387,6 @@ class IntegrationTests: @mock.patch('django.utils.autoreload.BaseReloader.notify_file_changed') @mock.patch('django.utils.autoreload.iter_all_python_module_files', return_value=frozenset()) - def test_glob_non_existing_directory(self, mocked_modules, notify_mock): - non_existing_directory = self.tempdir / 'does_not_exist' - nonexistent_file = non_existing_directory / 'test.py' - self.reloader.watch_dir(non_existing_directory, '*.py') - with self.tick_twice(): - self.ensure_file(nonexistent_file) - self.set_mtime(nonexistent_file, time.time()) - self.assertEqual(notify_mock.call_count, 1) - self.assertCountEqual(notify_mock.call_args[0], [nonexistent_file]) - - @mock.patch('django.utils.autoreload.BaseReloader.notify_file_changed') - @mock.patch('django.utils.autoreload.iter_all_python_module_files', return_value=frozenset()) def test_multiple_globs(self, mocked_modules, notify_mock): self.ensure_file(self.tempdir / 'x.test') self.reloader.watch_dir(self.tempdir, '*.py') @@ -666,28 +634,8 @@ class StatReloaderTests(ReloaderTests, IntegrationTests): snapshot2 = dict(self.reloader.snapshot_files()) self.assertNotEqual(snapshot1[self.existing_file], snapshot2[self.existing_file]) - def test_does_not_fire_without_changes(self): - with mock.patch.object(self.reloader, 'watched_files', return_value=[self.existing_file]), \ - mock.patch.object(self.reloader, 'notify_file_changed') as notifier: - mtime = self.existing_file.stat().st_mtime - initial_snapshot = {self.existing_file: mtime} - second_snapshot = self.reloader.loop_files(initial_snapshot, time.time()) - self.assertEqual(second_snapshot, {}) - notifier.assert_not_called() - - def test_fires_when_created(self): - with mock.patch.object(self.reloader, 'watched_files', return_value=[self.nonexistent_file]), \ - mock.patch.object(self.reloader, 'notify_file_changed') as notifier: - self.nonexistent_file.touch() - mtime = self.nonexistent_file.stat().st_mtime - second_snapshot = self.reloader.loop_files({}, mtime - 1) - self.assertCountEqual(second_snapshot.keys(), [self.nonexistent_file]) - notifier.assert_called_once_with(self.nonexistent_file) - - def test_fires_with_changes(self): - with mock.patch.object(self.reloader, 'watched_files', return_value=[self.existing_file]), \ - mock.patch.object(self.reloader, 'notify_file_changed') as notifier: - initial_snapshot = {self.existing_file: 1} - second_snapshot = self.reloader.loop_files(initial_snapshot, time.time()) - notifier.assert_called_once_with(self.existing_file) - self.assertCountEqual(second_snapshot.keys(), [self.existing_file]) + def test_snapshot_files_with_duplicates(self): + with mock.patch.object(self.reloader, 'watched_files', return_value=[self.existing_file, self.existing_file]): + snapshot = list(self.reloader.snapshot_files()) + self.assertEqual(len(snapshot), 1) + self.assertEqual(snapshot[0][0], self.existing_file) |
