1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
import unittest
from reportbug import tempfiles
import os.path
class TestTempfiles(unittest.TestCase):
def test_tempfile_prefix(self):
extra = 'dummystring'
prefix = tempfiles.tempfile_prefix()
self.assertIn('reportbug', prefix)
prefix = tempfiles.tempfile_prefix(package='dpkg')
self.assertIn('dpkg', prefix)
prefix = tempfiles.tempfile_prefix(package='', extra=extra)
self.assertIn(extra, prefix)
prefix = tempfiles.tempfile_prefix(package='dpkg', extra=extra)
self.assertIn('dpkg', prefix)
self.assertIn(extra, prefix)
def test_open_write_safe(self):
filename = os.path.dirname(__file__) + '/tempfiletest'
# binary file
fd = tempfiles.open_write_safe(filename)
self.assertFalse(fd.closed)
fd.close()
self.assertTrue(fd.closed)
# remove temp file
tempfiles.cleanup_temp_file(filename)
filename = os.path.dirname(__file__) + '/tempfiletest'
# text file
fd = tempfiles.open_write_safe(filename, mode='w')
self.assertFalse(fd.closed)
fd.close()
self.assertTrue(fd.closed)
tempfiles.cleanup_temp_file(filename)
def test_TempFile(self):
fd, filename = tempfiles.TempFile()
self.assertIsNotNone(filename)
self.assertFalse(fd.closed)
fd.close()
self.assertTrue(fd.closed)
tempfiles.cleanup_temp_file(filename)
|