machfs/test_all.py

62 lines
1.4 KiB
Python
Raw Normal View History

2018-10-08 00:18:30 +00:00
from machfs import *
import os
import time
2018-10-08 01:06:35 +00:00
def test_upperlower():
h = Volume()
h['alpha'] = File()
assert h['alpha'] is h['ALPHA']
assert list(h.keys()) == ['alpha']
def test_roundtrip():
h = Volume()
f = File()
2018-10-08 01:06:35 +00:00
h['single file'] = f
f.data = f.rsrc = b'1234' * 4096
copies = [h.write(800*1024)]
for i in range(2):
h2 = Volume()
h2.read(copies[-1])
copies.append(h2.write(800*1024))
assert copies[0] == copies[1]
assert copies[1] == copies[2]
2018-10-08 01:06:35 +00:00
assert f.data in copies[-1]
def test_macos_mount():
h = Volume()
2018-10-08 01:06:35 +00:00
h.name = 'ElmoTest'
hf = File()
2018-10-07 14:07:43 +00:00
hf.data = b'12345' * 10
2018-10-07 14:24:57 +00:00
for i in reversed(range(100)):
2018-10-08 01:06:35 +00:00
last = 'testfile-%03d' % i
2018-10-07 14:07:43 +00:00
h[last] = hf
ser = h.write(10*1024*1024)
open('/tmp/SMALL.dmg','wb').write(ser)
2018-10-07 14:24:57 +00:00
os.system('hdiutil attach /tmp/SMALL.dmg')
n = 10
while 1:
n += 1
2018-10-07 14:07:43 +00:00
assert n < 200
time.sleep(0.1)
try:
2018-10-07 14:07:43 +00:00
os.stat('/Volumes/ElmoTest/testfile-000')
except:
pass
else:
break
2018-10-08 01:06:35 +00:00
recovered = open('/Volumes/ElmoTest/' + last,'rb').read()
os.system('umount /Volumes/ElmoTest')
assert recovered == hf.data
2018-10-08 01:06:35 +00:00
2018-10-08 01:33:34 +00:00
h2 = Volume()
h2.read(ser)
assert h2['testfile-000'].data == hf.data
def test_extents_overflow():
h = Volume()
h.read(open('SourceForEmulator.dmg','rb').read())
assert h['aa'].data == b'a' * 278528