2019-03-08 09:54:42 +00:00
|
|
|
import os
|
|
|
|
import tarfile
|
2019-03-08 11:06:57 +00:00
|
|
|
from io import BytesIO
|
2019-03-08 11:09:01 +00:00
|
|
|
from bunker.files.bunkeredfile import BunkeredFile
|
2019-03-08 09:54:42 +00:00
|
|
|
|
|
|
|
def test_load_from_tar(tmpdir):
|
|
|
|
tmpdname = str(tmpdir)
|
|
|
|
|
|
|
|
with open(os.path.join(tmpdname, "a.tx"), "wb") as f:
|
|
|
|
f.write(b"abcdefg")
|
|
|
|
with open(os.path.join(tmpdname, "b.tx"), "wb") as f:
|
|
|
|
f.write(b"foobar")
|
|
|
|
|
|
|
|
f = tarfile.TarFile(os.path.join(tmpdname, "test.tar"), "w")
|
|
|
|
|
|
|
|
f.add(os.path.join(tmpdname, "a.tx"))
|
|
|
|
f.add(os.path.join(tmpdname, "b.tx"))
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
f = tarfile.TarFile(os.path.join(tmpdname, "test.tar"))
|
|
|
|
|
|
|
|
ainfo = f.next()
|
|
|
|
binfo = f.next()
|
|
|
|
|
|
|
|
a = BunkeredFile.from_tar(f, ainfo)
|
|
|
|
b = BunkeredFile.from_tar(f, binfo)
|
|
|
|
|
|
|
|
assert a.read() == b"abcdefg"
|
|
|
|
assert b.read() == b"foobar"
|
2019-03-08 11:06:57 +00:00
|
|
|
|
|
|
|
def test_from_BytesIO():
|
|
|
|
b = BytesIO(b"foobar")
|
|
|
|
f = BunkeredFile.from_BytesIO(b, "test")
|
|
|
|
|
|
|
|
assert len(f) == len(b"foobar")
|
|
|
|
assert f.read() == b"foobar"
|
|
|
|
|
|
|
|
|