diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c45d99a..8b23921 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,12 +50,12 @@ jobs: - run: bash scripts/ci/run - if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: .coverage.mypy-misc_${{ matrix.platform }}_${{ matrix.python-version }} path: .coverage.mypy-misc/ - if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: .coverage.mypy-core_${{ matrix.platform }}_${{ matrix.python-version }} path: .coverage.mypy-core/ diff --git a/tests/bluemaestro.py b/tests/bluemaestro.py index 1416900..283bd77 100644 --- a/tests/bluemaestro.py +++ b/tests/bluemaestro.py @@ -1,13 +1,26 @@ -#!/usr/bin/env python3 from pathlib import Path +from typing import TYPE_CHECKING, Iterator, Any + 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: - from my.bluemaestro import measurements - res2020 = [m for m in measurements() if '2020' in str(m.dt)] + res2020 = [m for m in ok_measurements() if '2020' in str(m.dt)] tp = [x for x in res2020 if x.temp == 2.1] assert len(tp) > 0 @@ -24,8 +37,7 @@ def test() -> None: def test_old_db() -> None: - from my.bluemaestro import measurements - res = list(measurements()) + res = list(ok_measurements()) 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') diff --git a/tests/jawbone.py b/tests/jawbone.py index c53459d..776ac50 100644 --- a/tests/jawbone.py +++ b/tests/jawbone.py @@ -4,7 +4,7 @@ from datetime import date, time # todo private test.. move away 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() for s in sleeps.values(): assert s.sleep_start.tzinfo is not None diff --git a/tests/pdfs.py b/tests/pdfs.py index d5134bf..ae6318d 100644 --- a/tests/pdfs.py +++ b/tests/pdfs.py @@ -23,7 +23,8 @@ def test_with_error(with_config, tmp_path: Path) -> None: g = root / 'garbage.pdf' g.write_text('garbage') 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,) from my.pdfs import annotations diff --git a/tests/takeout.py b/tests/takeout.py index f45a51d..7cc2164 100644 --- a/tests/takeout.py +++ b/tests/takeout.py @@ -13,7 +13,7 @@ from more_itertools import ilen def test_location_perf() -> None: # 2.80 s for 10 iterations and 10K points # 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? diff --git a/tests/test_tmp_config.py b/tests/test_tmp_config.py index eb26e54..197d3f7 100644 --- a/tests/test_tmp_config.py +++ b/tests/test_tmp_config.py @@ -6,11 +6,11 @@ from my.core.cfg import tmp_config import pytest -def _init_default_config(): +def _init_default_config() -> None: import my.config class default_config: 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: diff --git a/tox.ini b/tox.ini index a8af102..6e7ca23 100644 --- a/tox.ini +++ b/tox.ini @@ -80,7 +80,7 @@ allowlist_externals = cat commands = pip install -e .[testing,optional] pip install orgparse # used it core.orgmode? - # todo add tests? + {envpython} -m mypy --install-types --non-interactive \ -p my.core \ --txt-report .coverage.mypy-core \ @@ -88,10 +88,16 @@ commands = {posargs} 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) # todo maybe split into separate jobs? need to add comment how to run [testenv:mypy-misc] +allowlist_externals = cat commands = pip install -e .[testing,optional] @@ -132,6 +138,10 @@ commands = --html-report .coverage.mypy-misc \ {posargs} # 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 # > ugh ... need to reset HOME, otherwise user's site-packages are somehow leaking into mypy's path...