From c3a77b6256627bc667959c7628fde157985e8ad6 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 4 May 2020 07:50:29 +0100 Subject: [PATCH] initial kompress tests --- my/kython/kompress.py | 1 + my/reddit.py | 1 - tests/misc.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/misc.py diff --git a/my/kython/kompress.py b/my/kython/kompress.py index 3077e71..73181ea 100644 --- a/my/kython/kompress.py +++ b/my/kython/kompress.py @@ -17,6 +17,7 @@ def _zstd_open(path: Path): def kopen(path: PathIsh, *args, **kwargs): # TODO is it bytes stream?? + # TODO allow passing in mode? pp = Path(path) suf = pp.suffix if suf in {'.xz'}: diff --git a/my/reddit.py b/my/reddit.py index 143f120..2a341f7 100755 --- a/my/reddit.py +++ b/my/reddit.py @@ -14,7 +14,6 @@ import my.config.repos.rexport.dal as rexport def get_sources() -> Sequence[Path]: - # TODO use zstd? # TODO rename to export_path? files = get_files(config.export_dir) res = list(map(CPath, files)); assert len(res) > 0 diff --git a/tests/misc.py b/tests/misc.py new file mode 100644 index 0000000..dbb3fa9 --- /dev/null +++ b/tests/misc.py @@ -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?