cleanup, mypy coverage & add common/error stubs

This commit is contained in:
Dima Gerasimov 2020-05-06 22:50:18 +01:00
parent 15444c7b1f
commit 6ecb953675
7 changed files with 37 additions and 33 deletions

View file

@ -5,6 +5,10 @@
#+macro: map @@html:<span style='color:darkgreen; font-weight: bolder'>@@$1@@html:</span>@@ #+macro: map @@html:<span style='color:darkgreen; font-weight: bolder'>@@$1@@html:</span>@@
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. *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: 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. Imagine if all your life was reflected digitally and available at your fingertips.
This library is my attempt to achieve this vision. 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 #+toc: headlines 2

2
lint
View file

@ -43,10 +43,8 @@ def core_modules() -> Iterable[str]:
return [ return [
*subpackages('my.core'), *subpackages('my.core'),
*subpackages('my.kython'), *subpackages('my.kython'),
'my.common',
'my.config', 'my.config',
'my.cfg', 'my.cfg',
'my.error',
'tests/misc.py', 'tests/misc.py',
'tests/get_files.py', 'tests/get_files.py',
# 'tests/config.py', TODO hmm. unclear how to type check this module # 'tests/config.py', TODO hmm. unclear how to type check this module

2
my/common.py Normal file
View file

@ -0,0 +1,2 @@
# will be deprecated. please add stuff to my.core
from .core.common import *

View file

@ -95,14 +95,14 @@ def listify(fn=None, wrapper=list):
return listify_return(fn) return listify_return(fn)
# TODO FIXME use in bluemaestro # todo use in bluemaestro
# def dictify(fn=None, key=None, value=None): # def dictify(fn=None, key=None, value=None):
# def md(it): # def md(it):
# return make_dict(it, key=key, value=value) # return make_dict(it, key=key, value=value)
# return listify(fn=fn, wrapper=md) # 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] Paths = Union[Sequence[PathIsh], PathIsh]

View file

@ -67,7 +67,7 @@ def sort_res_by(items: Iterable[ResT], key) -> List[ResT]:
return results return results
def test_sort_res_by(): def test_sort_res_by() -> None:
class Exc(Exception): class Exc(Exception):
def __eq__(self, other): def __eq__(self, other):
return self.args == other.args return self.args == other.args

2
my/error.py Normal file
View file

@ -0,0 +1,2 @@
# will be deprecated. please add stuff to my.core
from .core.error import *

View file

@ -7,10 +7,32 @@ import zipfile
from my.kython.kompress import kopen, kexists, CPath 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 import pytest # type: ignore
@pytest.fixture @pytest.fixture(autouse=True)
def prepare(tmp_path: Path): def prepare(tmp_path: Path):
(tmp_path / 'file').write_text('just plaintext') (tmp_path / 'file').write_text('just plaintext')
with (tmp_path / 'file.xz').open('wb') as f: with (tmp_path / 'file.xz').open('wb') as f:
@ -24,24 +46,5 @@ def prepare(tmp_path: Path):
pass pass
def test_kopen(prepare, tmp_path: Path) -> None: # meh
"Plaintext handled transparently" from my.core.error import test_sort_res_by
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??