Пример #1
0
 def test_temp_file_removes(self):
     foo = NamedTemporaryFile(suffix='foo.txt', delete=True)
     full_path = foo.temporary_file_path()
     path, name = os.path.split(full_path)
     self.assertRegexpMatches(name, r'\w+foo.txt')
     foo.close()
     self.assertFalse(os.path.isfile(full_path))
Пример #2
0
 def test_temp_file_removes_manually(self):
     foo = NamedTemporaryFile(suffix='foo.txt', delete=False)
     full_path = foo.temporary_file_path()
     os.remove(full_path)
     self.assertFalse(os.path.isfile(full_path))
     # although removed, shouldn't raise an error
     foo.close()
Пример #3
0
 def test_temp_file_removes(self):
     foo = NamedTemporaryFile(suffix='foo.txt', delete=True)
     full_path = foo.temporary_file_path()
     path, name = os.path.split(full_path)
     self.assertRegexpMatches(name, r'\w+foo.txt')
     foo.close()
     self.assertFalse(os.path.isfile(full_path))
Пример #4
0
 def test_temp_file_removes_manually(self):
     foo = NamedTemporaryFile(suffix='foo.txt', delete=False)
     full_path = foo.temporary_file_path()
     os.remove(full_path)
     self.assertFalse(os.path.isfile(full_path))
     # although removed, shouldn't raise an error
     foo.close()
Пример #5
0
 def get_output_file(self, in_file, instance, field, **kwargs):
     """Creates a temporary file. With regular `FileSystemStorage` it does not 
     need to be deleted, instaed file is safely moved over. With other cloud
     based storage it is a good idea to set `delete=True`."""
     return NamedTemporaryFile(
         mode='rb',
         suffix='_%s_%s%s' %
         (get_model_name(instance), field.name, self.get_ext()),
         delete=False)
Пример #6
0
 def test_temp_file_keeps(self):
     foo = NamedTemporaryFile(suffix='foo.txt', delete=False)
     full_path = foo.temporary_file_path()
     foo.close()
     self.assertTrue(os.path.isfile(full_path))
Пример #7
0
 def test_temp_file_keeps(self):
     foo = NamedTemporaryFile(suffix='foo.txt', delete=False)
     full_path = foo.temporary_file_path()
     foo.close()
     self.assertTrue(os.path.isfile(full_path))