-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_smount.py
80 lines (69 loc) · 2.18 KB
/
test_smount.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import unittest
import pyfakefs.fake_filesystem_unittest
from smount.smount import SerialMounter, MountPoint, MountType
TEST_CONFIG_1 = """
mount_types:
one:
mount: echo does nothing
umount: echo does nothing neither
mounts:
m_one:
src: /
target: /tmp
type: one
m_two:
src: .
target: /tmp
type: one
"""
TEST_CONFIG_2 = """
mount_types:
one:
mount: echo does nothing
umount: echo does nothing neither
mounts:
m_one:
src: /
target: /tmp
type: one
m_two:
src: .
target: /tmp
type: two
"""
class TestSerialMounter(unittest.TestCase):
def setUp(self):
self.instance = SerialMounter([TEST_CONFIG_1])
def test_ok_list_mounts(self):
self.assertEqual(len(self.instance.get_mount_points()), 2)
def test_ko_list_mounts(self):
#FIXME: Better handle this!
self.assertRaises(KeyError, SerialMounter, [TEST_CONFIG_2])
def test_get_config(self):
mount = self.instance.get('m_one')
self.assertEqual(mount.name, 'm_one')
class TestMountPoint(pyfakefs.fake_filesystem_unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.setUpClassPyfakefs()
cls.nil_mount_type = MountType("nop", {"mount": "true", "umount":"true"})
cls.fake_fs().create_dir("/one")
cls.fake_fs().create_file("/one/a")
cls.fake_fs().create_file("/one/b")
cls.fake_fs().create_file("/one/c")
cls.fake_fs().create_dir("/three")
def test_impossible_mount(self):
test = MountPoint("test", {"src":"/one/a", "target":"/four"}, self.nil_mount_type)
self.assertRaises(RuntimeError, test.mount)
def test_mount(self):
test = MountPoint("test", {"src":"/one/a", "target":"/three"}, self.nil_mount_type)
test.mount()
def test_mount_expanded(self):
src = "/one/*"
test = MountPoint("test",
{"src":src, "target":"/three", "expand": "last-alpha"},
self.nil_mount_type)
self.assertEqual(test.expand(src), "/one/c")
self.assertEqual(test.mount(), True)
if __name__ == '__main__':
unittest.main()