-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
57 lines (51 loc) · 1.93 KB
/
test.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
from __future__ import print_function
from tempfile import mkdtemp
import os
import shutil
from subprocess import check_call, Popen
import time
import sys
osp= os.path
def tree(directory):
for root, dirs, files in os.walk(directory):
dirs = dict((i,tree(osp.join(root,i))) for i in dirs)
return [dirs, files]
def main():
expected = [{'test':
[{'bidon':
[{},
['a_file']]},
[]]},
[]]
cati_fs = osp.realpath(osp.join(osp.dirname(sys.argv[0]), 'cati_fs'))
tmp = mkdtemp(prefix='cati_fs_test')
try:
mountpoint = osp.join(tmp, 'cati_fs')
os.mkdir(mountpoint)
db = osp.join(tmp, 'cati_fs.sqlite')
mount = Popen([cati_fs, 'mount', '-c', db, mountpoint])
try:
time.sleep(1)
os.mkdir(tmp + '/bidon')
open(tmp + '/bidon/a_file', 'w').write('something')
if mount.poll() is None:
os.mkdir(mountpoint + '/test')
check_call([cati_fs, 'add', db, tmp + '/bidon', '/test/bidon'])
check_call([cati_fs, 'add', db, tmp + '/bidon/a_file', '/test/bidon/a_file'])
assert(tree(mountpoint) == expected)
assert(open(mountpoint +'/test/bidon/a_file').read() == 'something')
f = open(mountpoint + '/test/bidon/a_file', 'w')
f.write('something else')
del f
print(repr(open(mountpoint +'/test/bidon/a_file').read()))
assert(open(mountpoint +'/test/bidon/a_file').read() == 'something else')
else:
print('ERROR: while mounting cati_fs', file=sys.stderr)
return 1
finally:
check_call(['fusermount', '-u', mountpoint])
finally:
shutil.rmtree(tmp)
return 0
if __name__ == '__main__':
sys.exit(main())