-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mount.py
54 lines (40 loc) · 1.4 KB
/
test_mount.py
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
# coding: utf8
import unittest
import os, tempfile
import mount
class MountTestCase(unittest.TestCase):
tmpdir = "/tmp/test_mount/"
def setUp(self):
self.target = os.path.join(self.tmpdir, "target")
self.source = os.path.join(self.tmpdir, "source")
self.test_file = "test.txt"
os.mkdir(self.tmpdir)
os.mkdir(self.target)
os.mkdir(self.source)
with open(os.path.join(self.source, self.test_file), "w") as f:
f.write("test")
def test_mount(self):
mount.mount(self.source, self.target, "auto", mount.MS_BIND)
self.assertTrue(os.path.exists(os.path.join(self.target,
self.test_file)))
def test_umount(self):
self.test_mount()
mount.umount(self.target)
self.assertFalse(os.path.exists(os.path.join(self.target,
self.test_file)))
def test_umount2(self):
self.test_mount()
mount.umount2(self.target, mount.MNT_FORCE)
self.assertFalse(os.path.exists(os.path.join(self.target,
self.test_file)))
def tearDown(self):
try:
mount.umount2(self.target, mount.MNT_FORCE)
except mount.MountError:
pass
os.unlink(os.path.join(self.source, self.test_file))
os.rmdir(self.source)
os.rmdir(self.target)
os.rmdir(self.tmpdir)
if __name__ == "__main__":
unittest.main()