general/ci: mypy check tests

This commit is contained in:
Dima Gerasimov 2023-02-20 23:57:31 +00:00 committed by karlicoss
parent c63177e186
commit 07e7c62d02
7 changed files with 37 additions and 14 deletions

View file

@ -50,12 +50,12 @@ jobs:
- run: bash scripts/ci/run - run: bash scripts/ci/run
- if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms - if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v3
with: with:
name: .coverage.mypy-misc_${{ matrix.platform }}_${{ matrix.python-version }} name: .coverage.mypy-misc_${{ matrix.platform }}_${{ matrix.python-version }}
path: .coverage.mypy-misc/ path: .coverage.mypy-misc/
- if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms - if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v3
with: with:
name: .coverage.mypy-core_${{ matrix.platform }}_${{ matrix.python-version }} name: .coverage.mypy-core_${{ matrix.platform }}_${{ matrix.python-version }}
path: .coverage.mypy-core/ path: .coverage.mypy-core/

View file

@ -1,13 +1,26 @@
#!/usr/bin/env python3
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING, Iterator, Any
from more_itertools import one from more_itertools import one
import pytest # type: ignore import pytest
if TYPE_CHECKING:
from my.bluemaestro import Measurement
else:
Measurement = Any
def ok_measurements() -> Iterator[Measurement]:
from my.bluemaestro import measurements
for m in measurements():
assert not isinstance(m, Exception)
yield m
def test() -> None: def test() -> None:
from my.bluemaestro import measurements res2020 = [m for m in ok_measurements() if '2020' in str(m.dt)]
res2020 = [m for m in measurements() if '2020' in str(m.dt)]
tp = [x for x in res2020 if x.temp == 2.1] tp = [x for x in res2020 if x.temp == 2.1]
assert len(tp) > 0 assert len(tp) > 0
@ -24,8 +37,7 @@ def test() -> None:
def test_old_db() -> None: def test_old_db() -> None:
from my.bluemaestro import measurements res = list(ok_measurements())
res = list(measurements())
r1 = one(x for x in res if x.dt.strftime('%Y%m%d %H:%M:%S') == '20181003 09:07:00') r1 = one(x for x in res if x.dt.strftime('%Y%m%d %H:%M:%S') == '20181003 09:07:00')
r2 = one(x for x in res if x.dt.strftime('%Y%m%d %H:%M:%S') == '20181003 09:19:00') r2 = one(x for x in res if x.dt.strftime('%Y%m%d %H:%M:%S') == '20181003 09:19:00')

View file

@ -4,7 +4,7 @@ from datetime import date, time
# todo private test.. move away # todo private test.. move away
def test_tz() -> None: def test_tz() -> None:
from my.jawbone import sleeps_by_date from my.jawbone import sleeps_by_date # type: ignore[attr-defined]
sleeps = sleeps_by_date() sleeps = sleeps_by_date()
for s in sleeps.values(): for s in sleeps.values():
assert s.sleep_start.tzinfo is not None assert s.sleep_start.tzinfo is not None

View file

@ -23,7 +23,8 @@ def test_with_error(with_config, tmp_path: Path) -> None:
g = root / 'garbage.pdf' g = root / 'garbage.pdf'
g.write_text('garbage') g.write_text('garbage')
from my.config import pdfs from my.config import pdfs
del pdfs.roots # meh. otherwise legacy config value 'wins' # meh. otherwise legacy config value 'wins'
del pdfs.roots # type: ignore[attr-defined]
pdfs.paths = (root,) pdfs.paths = (root,)
from my.pdfs import annotations from my.pdfs import annotations

View file

@ -13,7 +13,7 @@ from more_itertools import ilen
def test_location_perf() -> None: def test_location_perf() -> None:
# 2.80 s for 10 iterations and 10K points # 2.80 s for 10 iterations and 10K points
# TODO try switching to jq and see how it goes? not sure.. # TODO try switching to jq and see how it goes? not sure..
print(ilen(islice(LT.iter_locations(), 0, 10000))) print(ilen(islice(LT.iter_locations(), 0, 10000))) # type: ignore
# in theory should support any HTML takeout file? # in theory should support any HTML takeout file?

View file

@ -6,11 +6,11 @@ from my.core.cfg import tmp_config
import pytest import pytest
def _init_default_config(): def _init_default_config() -> None:
import my.config import my.config
class default_config: class default_config:
count = 5 count = 5
my.config.simple = default_config # type: ignore[attr-defined] my.config.simple = default_config # type: ignore[attr-defined,assignment,misc]
def test_tmp_config() -> None: def test_tmp_config() -> None:

12
tox.ini
View file

@ -80,7 +80,7 @@ allowlist_externals = cat
commands = commands =
pip install -e .[testing,optional] pip install -e .[testing,optional]
pip install orgparse # used it core.orgmode? pip install orgparse # used it core.orgmode?
# todo add tests?
{envpython} -m mypy --install-types --non-interactive \ {envpython} -m mypy --install-types --non-interactive \
-p my.core \ -p my.core \
--txt-report .coverage.mypy-core \ --txt-report .coverage.mypy-core \
@ -88,10 +88,16 @@ commands =
{posargs} {posargs}
cat .coverage.mypy-core/index.txt cat .coverage.mypy-core/index.txt
# todo hmm might be better to move modules test in a separate subpackage?
{envpython} -m mypy --install-types --non-interactive \
tests \
--exclude 'tests/(bluemaestro|emfit|takeout|pdfs|jawbone).py'
# specific modules that are known to be mypy compliant (to avoid false negatives) # specific modules that are known to be mypy compliant (to avoid false negatives)
# todo maybe split into separate jobs? need to add comment how to run # todo maybe split into separate jobs? need to add comment how to run
[testenv:mypy-misc] [testenv:mypy-misc]
allowlist_externals = cat
commands = commands =
pip install -e .[testing,optional] pip install -e .[testing,optional]
@ -132,6 +138,10 @@ commands =
--html-report .coverage.mypy-misc \ --html-report .coverage.mypy-misc \
{posargs} {posargs}
# txt report is a bit more convenient to view on CI # txt report is a bit more convenient to view on CI
cat .coverage.mypy-misc/index.txt
{envpython} -m mypy --install-types --non-interactive \
tests
# note: this comment doesn't seem relevant anymore, but keeping it in case the issue happens again # note: this comment doesn't seem relevant anymore, but keeping it in case the issue happens again
# > ugh ... need to reset HOME, otherwise user's site-packages are somehow leaking into mypy's path... # > ugh ... need to reset HOME, otherwise user's site-packages are somehow leaking into mypy's path...