From 6ecb9536755e4ebbe2d6b9f7966c3e31baefed7e Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Wed, 6 May 2020 22:50:18 +0100 Subject: [PATCH] cleanup, mypy coverage & add common/error stubs --- README.org | 11 +++++------ lint | 2 -- my/common.py | 2 ++ my/core/common.py | 4 ++-- my/core/error.py | 2 +- my/error.py | 2 ++ tests/misc.py | 47 +++++++++++++++++++++++++---------------------- 7 files changed, 37 insertions(+), 33 deletions(-) create mode 100644 my/common.py create mode 100644 my/error.py diff --git a/README.org b/README.org index 1d62c84..579fd4f 100644 --- a/README.org +++ b/README.org @@ -5,6 +5,10 @@ #+macro: map @@html:@@$1@@html:@@ +If you're in a hurry, feel free to jump straight to the [[#usecases][demos]]. + +For *installation/configuration/development guide*, see [[https://github.com/karlicoss/HPI/tree/master/doc/SETUP.org][SETUP.org]]. + *TLDR*: I'm using [[https://github.com/karlicoss/HPI][HPI]] (Human Programming Interface) package as a means of unifying, accessing and interacting with all of my personal data. It's a Python library (named ~my~), a collection of modules for: @@ -48,11 +52,6 @@ and that's why I'm sharing this. Imagine if all your life was reflected digitally and available at your fingertips. This library is my attempt to achieve this vision. -If you're in a hurry, feel free to jump straight to the [[#usecases][demos]]. - -For *installation/configuration/development guide*, see [[https://github.com/karlicoss/HPI/tree/master/doc/SETUP.org][SETUP.org]]. - - #+toc: headlines 2 @@ -593,4 +592,4 @@ In some near future I will write more about: - challenges I had so solve - more use-cases and demos -- it's impossible to fit everything in one post! -, but happy to answer any questions on these topics now! \ No newline at end of file +, but happy to answer any questions on these topics now! diff --git a/lint b/lint index 8cdca2b..bb2f097 100755 --- a/lint +++ b/lint @@ -43,10 +43,8 @@ def core_modules() -> Iterable[str]: return [ *subpackages('my.core'), *subpackages('my.kython'), - 'my.common', 'my.config', 'my.cfg', - 'my.error', 'tests/misc.py', 'tests/get_files.py', # 'tests/config.py', TODO hmm. unclear how to type check this module diff --git a/my/common.py b/my/common.py new file mode 100644 index 0000000..bbda576 --- /dev/null +++ b/my/common.py @@ -0,0 +1,2 @@ +# will be deprecated. please add stuff to my.core +from .core.common import * diff --git a/my/core/common.py b/my/core/common.py index 063f555..1557654 100644 --- a/my/core/common.py +++ b/my/core/common.py @@ -95,14 +95,14 @@ def listify(fn=None, wrapper=list): return listify_return(fn) -# TODO FIXME use in bluemaestro +# todo use in bluemaestro # def dictify(fn=None, key=None, value=None): # def md(it): # return make_dict(it, key=key, value=value) # return listify(fn=fn, wrapper=md) -from .kython.klogging import setup_logger, LazyLogger +from ..kython.klogging import setup_logger, LazyLogger Paths = Union[Sequence[PathIsh], PathIsh] diff --git a/my/core/error.py b/my/core/error.py index 721cb63..4423940 100644 --- a/my/core/error.py +++ b/my/core/error.py @@ -67,7 +67,7 @@ def sort_res_by(items: Iterable[ResT], key) -> List[ResT]: return results -def test_sort_res_by(): +def test_sort_res_by() -> None: class Exc(Exception): def __eq__(self, other): return self.args == other.args diff --git a/my/error.py b/my/error.py new file mode 100644 index 0000000..596c90e --- /dev/null +++ b/my/error.py @@ -0,0 +1,2 @@ +# will be deprecated. please add stuff to my.core +from .core.error import * diff --git a/tests/misc.py b/tests/misc.py index 73d1255..40d63a4 100644 --- a/tests/misc.py +++ b/tests/misc.py @@ -7,10 +7,32 @@ import zipfile from my.kython.kompress import kopen, kexists, CPath +def test_kopen(tmp_path: Path) -> None: + "Plaintext handled transparently" + assert kopen(tmp_path / 'file' ).read() == 'just plaintext' + assert kopen(tmp_path / 'file.xz').read() == 'compressed text' + + "For zips behaviour is a bit different (not sure about all this, tbh...)" + assert kopen(tmp_path / 'file.zip', 'path/in/archive').read() == 'data in zip' + + +def test_kexists(tmp_path: Path) -> None: + assert kexists(str(tmp_path / 'file.zip'), 'path/in/archive') + assert not kexists(str(tmp_path / 'file.zip'), 'path/notin/archive') + + # TODO not sure about this? + assert not kexists(tmp_path / 'nosuchzip.zip', 'path/in/archive') + + +def test_cpath(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?? + import pytest # type: ignore -@pytest.fixture +@pytest.fixture(autouse=True) def prepare(tmp_path: Path): (tmp_path / 'file').write_text('just plaintext') with (tmp_path / 'file.xz').open('wb') as f: @@ -24,24 +46,5 @@ def prepare(tmp_path: Path): 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() == 'compressed text' - - "For zips behaviour is a bit different (not sure about all this, tbh...)" - assert kopen(tmp_path / 'file.zip', 'path/in/archive').read() == 'data in zip' - - -def test_kexists(prepare, tmp_path: Path) -> None: - assert kexists(str(tmp_path / 'file.zip'), 'path/in/archive') - assert not kexists(str(tmp_path / 'file.zip'), 'path/notin/archive') - - # TODO not sure about this? - assert not kexists(tmp_path / 'nosuchzip.zip', 'path/in/archive') - - -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?? +# meh +from my.core.error import test_sort_res_by