1#!/usr/bin/python 2 3import unittest, os 4import common 5from autotest_lib.client.common_lib import autotemp 6 7 8class tempfile_test(unittest.TestCase): 9 10 def test_create_file(self): 11 temp = autotemp.tempfile(unique_id='file') 12 self.assertTrue(os.path.exists(temp.name)) 13 14 15 def test_clean(self): 16 temp = autotemp.tempfile(unique_id='clean') 17 # clean up sets name to None so we preserve it this way 18 name = temp.name 19 self.assertTrue(os.path.exists(name)) 20 temp.clean() 21 self.assertFalse(os.path.exists(name)) 22 23 24 def test_del(self): 25 tmp_file = autotemp.tempfile(unique_id='del') 26 name = tmp_file.name 27 self.assertTrue(os.path.exists(name)) 28 tmp_file.__del__() 29 self.assertFalse(os.path.exists(name)) 30 31 32class tempdir(unittest.TestCase): 33 34 def test_create_dir(self): 35 temp_dir = autotemp.tempdir(unique_id='dir') 36 self.assertTrue(os.path.exists(temp_dir.name)) 37 self.assertTrue(os.path.isdir(temp_dir.name)) 38 39 40 def test_clean(self): 41 temp_dir = autotemp.tempdir(unique_id='clean') 42 name = temp_dir.name 43 self.assertTrue(os.path.exists(name)) 44 temp_dir.clean() 45 self.assertFalse(os.path.exists(name)) 46 47 48 def test_del(self): 49 temp_dir = autotemp.tempdir(unique_id='del') 50 name = temp_dir.name 51 self.assertTrue(os.path.exists(name)) 52 temp_dir.__del__() 53 self.assertFalse(os.path.exists(name)) 54 55 56if __name__ == '__main__': 57 unittest.main() 58