summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2020-01-09 20:43:50 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-01-09 20:47:45 +0100
commit4c1b401e8250f9f520b3c7dc369554477ce8b15a (patch)
treef98cedae1601d1cbdf716752f31d40575dfccaa7 /tests
parentaa6c620249bc8c2a6245c8d7b928b05e7e5e78fc (diff)
downloaddjango-fix/remove-stray-file.tar.gz
Added file cleanup in FileFieldTests.test_pickle().fix/remove-stray-file
Diffstat (limited to 'tests')
-rw-r--r--tests/model_fields/test_filefield.py40
1 files changed, 24 insertions, 16 deletions
diff --git a/tests/model_fields/test_filefield.py b/tests/model_fields/test_filefield.py
index 5600051a35..67c08c984c 100644
--- a/tests/model_fields/test_filefield.py
+++ b/tests/model_fields/test_filefield.py
@@ -110,19 +110,27 @@ class FileFieldTests(TestCase):
file1 = File(fp, name='test_file.py')
document = Document(myfile='test_file.py')
document.myfile.save('test_file.py', file1)
-
- dump = pickle.dumps(document)
- loaded_document = pickle.loads(dump)
- self.assertEqual(document.myfile, loaded_document.myfile)
- self.assertEqual(document.myfile.url, loaded_document.myfile.url)
- self.assertEqual(document.myfile.storage, loaded_document.myfile.storage)
- self.assertEqual(document.myfile.instance, loaded_document.myfile.instance)
- self.assertEqual(document.myfile.field, loaded_document.myfile.field)
-
- myfile_dump = pickle.dumps(document.myfile)
- loaded_myfile = pickle.loads(myfile_dump)
- self.assertEqual(document.myfile, loaded_myfile)
- self.assertEqual(document.myfile.url, loaded_myfile.url)
- self.assertEqual(document.myfile.storage, loaded_myfile.storage)
- self.assertEqual(document.myfile.instance, loaded_myfile.instance)
- self.assertEqual(document.myfile.field, loaded_myfile.field)
+ try:
+ dump = pickle.dumps(document)
+ loaded_document = pickle.loads(dump)
+ self.assertEqual(document.myfile, loaded_document.myfile)
+ self.assertEqual(document.myfile.url, loaded_document.myfile.url)
+ self.assertEqual(
+ document.myfile.storage,
+ loaded_document.myfile.storage,
+ )
+ self.assertEqual(
+ document.myfile.instance,
+ loaded_document.myfile.instance,
+ )
+ self.assertEqual(document.myfile.field, loaded_document.myfile.field)
+
+ myfile_dump = pickle.dumps(document.myfile)
+ loaded_myfile = pickle.loads(myfile_dump)
+ self.assertEqual(document.myfile, loaded_myfile)
+ self.assertEqual(document.myfile.url, loaded_myfile.url)
+ self.assertEqual(document.myfile.storage, loaded_myfile.storage)
+ self.assertEqual(document.myfile.instance, loaded_myfile.instance)
+ self.assertEqual(document.myfile.field, loaded_myfile.field)
+ finally:
+ document.myfile.delete()