From 55ac85c7e723cff14434bf9e10c08f459b003798 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 4 May 2020 08:53:41 +0100 Subject: [PATCH] cpath tests, rely more on it --- my/rtm.py | 7 +++---- tests/misc.py | 13 +++++-------- tox.ini | 3 ++- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/my/rtm.py b/my/rtm.py index dfaaf02..0b23fdd 100755 --- a/my/rtm.py +++ b/my/rtm.py @@ -9,7 +9,7 @@ from typing import Dict, List, Optional, Iterator from datetime import datetime from .common import LazyLogger, get_files, group_by_key, cproperty, make_dict -from .kython.kompress import open as kopen +from .kython.kompress import CPath from my.config import rtm as config @@ -80,7 +80,7 @@ class MyTodo: class DAL: - def __init__(self, data: bytes, revision=None) -> None: + def __init__(self, data: str, revision=None) -> None: self.cal = icalendar.Calendar.from_ical(data) self.revision = revision @@ -99,8 +99,7 @@ class DAL: def dal(): last = get_files(config.export_path)[-1] - with kopen(last) as fo: - data = fo.read() + data = CPath(last).read_text() # TODO make it automatic return DAL(data=data, revision='TODO') diff --git a/tests/misc.py b/tests/misc.py index e8c4fc2..73d1255 100644 --- a/tests/misc.py +++ b/tests/misc.py @@ -5,7 +5,7 @@ import lzma import io import zipfile -from my.kython.kompress import kopen, kexists +from my.kython.kompress import kopen, kexists, CPath import pytest # type: ignore @@ -41,10 +41,7 @@ def test_kexists(prepare, tmp_path: Path) -> None: assert not kexists(tmp_path / 'nosuchzip.zip', 'path/in/archive') -def test_cpath(): - # TODO - raise RuntimeError - - -# TODO FIXME these tests should def run on CI -# TODO get rid of all decode utf8? +def test_cpath(prepare, tmp_path: Path) -> None: + CPath(str(tmp_path / 'file' )).read_text() == 'just plaintext' + CPath( tmp_path / 'file.xz').read_text() == 'compressed text' + # TODO not sure about zip files?? diff --git a/tox.ini b/tox.ini index 51ee32d..fdecedf 100644 --- a/tox.ini +++ b/tox.ini @@ -8,11 +8,12 @@ passenv = CI CI_* # deliberately set to nonexistent pathe to check the fallback logic setenv = MY_CONFIG = nonexistent commands = - pip install -e . + pip install -e .[testing] # TODO ?? # python -m pytest {posargs} python3 -c 'import my.init; from my.config import stub as config; print(config.key)' python3 -c 'import my.init; import my.config; import my.config.repos' # shouldn't fail at least + python3 -m pytest tests/misc.py tests/get_files.py # TODO run demo.py? just make sure with_my is a bit cleverer? # TODO e.g. under CI, rely on installing