1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Used addCleanup() in tests where appropriate.

This commit is contained in:
Mariusz Felisiak
2023-12-31 10:01:31 +01:00
committed by GitHub
parent 81ccf92f15
commit d88ec42bd0
37 changed files with 121 additions and 240 deletions

View File

@@ -55,20 +55,13 @@ class ImageFieldTestMixin(SerializeMixin):
if os.path.exists(temp_storage_dir):
shutil.rmtree(temp_storage_dir)
os.mkdir(temp_storage_dir)
self.addCleanup(shutil.rmtree, temp_storage_dir)
file_path1 = os.path.join(os.path.dirname(__file__), "4x8.png")
self.file1 = self.File(open(file_path1, "rb"), name="4x8.png")
self.addCleanup(self.file1.close)
file_path2 = os.path.join(os.path.dirname(__file__), "8x4.png")
self.file2 = self.File(open(file_path2, "rb"), name="8x4.png")
def tearDown(self):
"""
Removes temp directory and all its contents.
"""
self.file1.close()
self.file2.close()
shutil.rmtree(temp_storage_dir)
self.addCleanup(self.file2.close)
def check_dimensions(self, instance, width, height, field_name="mugshot"):
"""