initial
This commit is contained in:
29
test/test_files_bunkerfile.py
Normal file
29
test/test_files_bunkerfile.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
import tarfile
|
||||
from bunker.files.bunkerfile import BunkeredFile
|
||||
|
||||
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"
|
23
test/test_files_tarfile.py
Normal file
23
test/test_files_tarfile.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import tarfile
|
||||
|
||||
from bunker.files.tarfile import RewriteableTarFile
|
||||
from bunker.files.bunkerfile import BunkeredFile
|
||||
|
||||
|
||||
def test_create(tmpdir):
|
||||
tmpdname = str(tmpdir)
|
||||
|
||||
tf = RewriteableTarFile.open(os.path.join(tmpdname, "test.bunker"))
|
||||
f = BunkeredFile.empty("__bunker_main__")
|
||||
tf.add_file(f)
|
||||
|
||||
f = tf.get_file("__bunker_main__")
|
||||
f.write(b"foobar")
|
||||
|
||||
tf.close()
|
||||
|
||||
tf = RewriteableTarFile.open(os.path.join(tmpdname, "test.bunker"))
|
||||
f = tf.get_file("__bunker_main__")
|
||||
|
||||
assert f.read() == b"foobar"
|
Reference in New Issue
Block a user