ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
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
55
56
57
#!/usr/bin/python
 
import unittest, os
import common
from autotest_lib.client.common_lib import autotemp
 
 
class tempfile_test(unittest.TestCase):
 
    def test_create_file(self):
        temp = autotemp.tempfile(unique_id='file')
        self.assertTrue(os.path.exists(temp.name))
 
 
    def test_clean(self):
        temp = autotemp.tempfile(unique_id='clean')
        # clean up sets name to None so we preserve it this way
        name = temp.name
        self.assertTrue(os.path.exists(name))
        temp.clean()
        self.assertFalse(os.path.exists(name))
 
 
    def test_del(self):
        tmp_file = autotemp.tempfile(unique_id='del')
        name = tmp_file.name
        self.assertTrue(os.path.exists(name))
        tmp_file.__del__()
        self.assertFalse(os.path.exists(name))
 
 
class tempdir(unittest.TestCase):
 
    def test_create_dir(self):
        temp_dir = autotemp.tempdir(unique_id='dir')
        self.assertTrue(os.path.exists(temp_dir.name))
        self.assertTrue(os.path.isdir(temp_dir.name))
 
 
    def test_clean(self):
        temp_dir = autotemp.tempdir(unique_id='clean')
        name = temp_dir.name
        self.assertTrue(os.path.exists(name))
        temp_dir.clean()
        self.assertFalse(os.path.exists(name))
 
 
    def test_del(self):
        temp_dir = autotemp.tempdir(unique_id='del')
        name = temp_dir.name
        self.assertTrue(os.path.exists(name))
        temp_dir.__del__()
        self.assertFalse(os.path.exists(name))
 
 
if __name__ == '__main__':
    unittest.main()