示例#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))