initial kompress tests
This commit is contained in:
parent
db47ba2d7e
commit
c3a77b6256
3 changed files with 42 additions and 1 deletions
|
@ -17,6 +17,7 @@ def _zstd_open(path: Path):
|
||||||
|
|
||||||
|
|
||||||
def kopen(path: PathIsh, *args, **kwargs): # TODO is it bytes stream??
|
def kopen(path: PathIsh, *args, **kwargs): # TODO is it bytes stream??
|
||||||
|
# TODO allow passing in mode?
|
||||||
pp = Path(path)
|
pp = Path(path)
|
||||||
suf = pp.suffix
|
suf = pp.suffix
|
||||||
if suf in {'.xz'}:
|
if suf in {'.xz'}:
|
||||||
|
|
|
@ -14,7 +14,6 @@ import my.config.repos.rexport.dal as rexport
|
||||||
|
|
||||||
|
|
||||||
def get_sources() -> Sequence[Path]:
|
def get_sources() -> Sequence[Path]:
|
||||||
# TODO use zstd?
|
|
||||||
# TODO rename to export_path?
|
# TODO rename to export_path?
|
||||||
files = get_files(config.export_dir)
|
files = get_files(config.export_dir)
|
||||||
res = list(map(CPath, files)); assert len(res) > 0
|
res = list(map(CPath, files)); assert len(res) > 0
|
||||||
|
|
41
tests/misc.py
Normal file
41
tests/misc.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
from pathlib import Path
|
||||||
|
from subprocess import check_call
|
||||||
|
import gzip
|
||||||
|
import lzma
|
||||||
|
import io
|
||||||
|
|
||||||
|
from my.kython.kompress import kopen
|
||||||
|
|
||||||
|
|
||||||
|
import pytest # type: ignore
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def prepare(tmp_path: Path):
|
||||||
|
(tmp_path / 'file').write_text('just plaintext')
|
||||||
|
with (tmp_path / 'file.xz').open('wb') as f:
|
||||||
|
with lzma.open(f, 'w') as lzf:
|
||||||
|
lzf.write(b'compressed text')
|
||||||
|
try:
|
||||||
|
yield None
|
||||||
|
finally:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_kopen(prepare, tmp_path: Path) -> None:
|
||||||
|
"Plaintext handled transparently"
|
||||||
|
assert kopen(tmp_path / 'file' ).read() == 'just plaintext'
|
||||||
|
assert kopen(tmp_path / 'file.xz').read() == b'compressed text' # FIXME make this str
|
||||||
|
|
||||||
|
|
||||||
|
def test_kexists(tmp_path: Path) -> None:
|
||||||
|
# TODO
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
def test_cpath():
|
||||||
|
# TODO
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
# TODO FIXME these tests should def run on CI
|
||||||
|
# TODO get rid of all decode utf8?
|
Loading…
Add table
Reference in a new issue