You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

55 lines
1.4 KiB

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