mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #23919 -- Replaced tempfile.mkdtemp() with TemporaryDirectory() context manager.
This commit is contained in:
parent
fee42fd99e
commit
6478e07a62
5 changed files with 34 additions and 57 deletions
|
@ -218,10 +218,9 @@ class TestInteractiveMessages(CollectionTestCase):
|
|||
|
||||
def test_no_warning_for_empty_staticdir(self):
|
||||
stdout = StringIO()
|
||||
static_dir = tempfile.mkdtemp(prefix='collectstatic_empty_staticdir_test')
|
||||
with override_settings(STATIC_ROOT=static_dir):
|
||||
call_command('collectstatic', interactive=True, stdout=stdout)
|
||||
shutil.rmtree(static_dir)
|
||||
with tempfile.TemporaryDirectory(prefix='collectstatic_empty_staticdir_test') as static_dir:
|
||||
with override_settings(STATIC_ROOT=static_dir):
|
||||
call_command('collectstatic', interactive=True, stdout=stdout)
|
||||
output = stdout.getvalue()
|
||||
self.assertNotIn(self.overwrite_warning_msg, output)
|
||||
self.assertNotIn(self.delete_warning_msg, output)
|
||||
|
@ -360,24 +359,22 @@ class TestCollectionOverwriteWarning(CollectionTestCase):
|
|||
"""
|
||||
There is a warning when there are duplicate destinations.
|
||||
"""
|
||||
static_dir = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, static_dir)
|
||||
with tempfile.TemporaryDirectory() as static_dir:
|
||||
duplicate = os.path.join(static_dir, 'test', 'file.txt')
|
||||
os.mkdir(os.path.dirname(duplicate))
|
||||
with open(duplicate, 'w+') as f:
|
||||
f.write('duplicate of file.txt')
|
||||
|
||||
duplicate = os.path.join(static_dir, 'test', 'file.txt')
|
||||
os.mkdir(os.path.dirname(duplicate))
|
||||
with open(duplicate, 'w+') as f:
|
||||
f.write('duplicate of file.txt')
|
||||
with self.settings(STATICFILES_DIRS=[static_dir]):
|
||||
output = self._collectstatic_output(clear=True)
|
||||
self.assertIn(self.warning_string, output)
|
||||
|
||||
with self.settings(STATICFILES_DIRS=[static_dir]):
|
||||
output = self._collectstatic_output(clear=True)
|
||||
self.assertIn(self.warning_string, output)
|
||||
os.remove(duplicate)
|
||||
|
||||
os.remove(duplicate)
|
||||
|
||||
# Make sure the warning went away again.
|
||||
with self.settings(STATICFILES_DIRS=[static_dir]):
|
||||
output = self._collectstatic_output(clear=True)
|
||||
self.assertNotIn(self.warning_string, output)
|
||||
# Make sure the warning went away again.
|
||||
with self.settings(STATICFILES_DIRS=[static_dir]):
|
||||
output = self._collectstatic_output(clear=True)
|
||||
self.assertNotIn(self.warning_string, output)
|
||||
|
||||
|
||||
@override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.DummyStorage')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue