blob: d044618ced4f93b5ae8153bba41947da5475bd77 [file] [log] [blame]
Mike Frysingerd03e6b52019-08-03 12:49:01 -04001#!/usr/bin/python2
mbligh6a242df2009-07-02 19:00:02 +00002
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()