tests: run all tests, but exclude tests specific to my computer from CI

controllable via HPI_TESTS_KARLICOSS=true
This commit is contained in:
Dima Gerasimov 2021-02-14 17:31:44 +00:00 committed by karlicoss
parent 6239879245
commit d562f00dca
21 changed files with 93 additions and 72 deletions

View file

@ -1,12 +1,11 @@
[pytest]
# for now, running with with_my pytest tests/reddit.py
# discover __init__,py as well
# TODO also importing too much with it...
# TODO FIXME wtf is this??
python_files = reddit.py
# discover files that don't follow test_ naming. Useful to keep tests along with the source code
python_files = *.py
addopts =
-rap
--verbose
# TODO hmm, not sure... guess it makes sense considering all the ext modules..
--continue-on-collection-errors
# otherwise it won't discover doctests
# eh? importing too much
# --doctest-modules

View file

@ -1,3 +0,0 @@
At the moment, some tests here are specific to my data.
If you know any good public data sources I could test against instead, please let me know!

View file

@ -1,11 +1,13 @@
#!/usr/bin/env python3
from pathlib import Path
from more_itertools import one
from .common import skip_if_not_karlicoss
import pytest # type: ignore
@skip_if_not_karlicoss
def test() -> None:
from my.bluemaestro import measurements
res = list(measurements())

View file

@ -1,7 +1,8 @@
from .common import skip_if_not_karlicoss as pytestmark
from more_itertools import ilen
def test() -> None:
from my.coding.commits import commits
def test():
all_commits = commits()
assert ilen(all_commits) > 10

7
tests/common.py Normal file
View file

@ -0,0 +1,7 @@
import os
import pytest
skip_if_not_karlicoss = pytest.mark.skipif(
'HPI_TESTS_KARLICOSS' not in os.environ, reason='test only works on @karlicoss data for now',
)

View file

@ -18,10 +18,10 @@ def setup_notes_path(notes: Path) -> None:
def test_dynamic_configuration(notes: Path) -> None:
setup_notes_path(notes)
from my.body.weight import dataframe
weight_df = dataframe()
from my.body.weight import from_orgmode
weights = [0.0 if isinstance(x, Exception) else x.value for x in from_orgmode()]
assert list(weight_df['weight'].fillna(0.0)) == [
assert weights == [
0.0,
62.0,
0.0,

View file

@ -1,7 +1,10 @@
from my.emfit import datas
from .common import skip_if_not_karlicoss as pytestmark
def test() -> None:
from my.emfit import datas
# TODO this should be implement via sanity checks/stat instead?
# the same code will be used for tests & for user reports
ds = [x for x in datas() if not isinstance(x, Exception)]
for d in ds:
assert d.start.tzinfo is not None
@ -10,7 +13,10 @@ def test() -> None:
assert d.sleep_end.tzinfo is not None
from .common import skip_if_not_karlicoss
@skip_if_not_karlicoss
def test_tz() -> None:
from my.emfit import datas
# TODO check errors too?
ds = [x for x in datas() if not isinstance(x, Exception)]

View file

@ -1,6 +1,7 @@
from my.foursquare import get_checkins
from .common import skip_if_not_karlicoss as pytestmark
def test_checkins():
def test_checkins() -> None:
from my.foursquare import get_checkins
# todo reuse stats?
checkins = get_checkins()
assert len(checkins) > 100

View file

@ -1,16 +1,15 @@
#!/usr/bin/env python3
from .common import skip_if_not_karlicoss as pytestmark
from more_itertools import ilen
from my.coding.github import get_events
# todo test against stats? not sure.. maybe both
def test_gdpr():
def test_gdpr() -> None:
import my.github.gdpr as gdpr
assert ilen(gdpr.events()) > 100
def test():
def test() -> None:
from my.coding.github import get_events
events = get_events()
assert ilen(events) > 100
for e in events:

View file

@ -1,7 +1,6 @@
#!/usr/bin/env python3
from .common import skip_if_not_karlicoss as pytestmark
def test() -> None:
from my.hypothesis import pages, highlights
def test():
assert len(list(pages())) > 10
assert len(list(highlights())) > 10

View file

@ -1,5 +1,6 @@
from .common import skip_if_not_karlicoss as pytestmark
def test_pages() -> None:
# TODO ugh. need lazy import to simplify testing?
from my.instapaper import pages
def test_pages():
assert len(list(pages())) > 3

View file

@ -1,11 +1,10 @@
# TODO depends on my private data... move somewhere, and exclude from CI somehow?
from .common import skip_if_not_karlicoss as pytestmark
from datetime import date, time
from my.jawbone import sleeps_by_date
# todo private test.. move away
def test_tz():
def test_tz() -> None:
from my.jawbone import sleeps_by_date
sleeps = sleeps_by_date()
for s in sleeps.values():
assert s.sleep_start.tzinfo is not None

View file

@ -1,13 +1,16 @@
from .common import skip_if_not_karlicoss as pytestmark
# todo maybe belongs to common
from more_itertools import ilen
def test() -> None:
from my.lastfm import scrobbles
def test():
assert ilen(scrobbles()) > 1000
def test_datetime_ascending():
def test_datetime_ascending() -> None:
from my.lastfm import scrobbles
from more_itertools import pairwise
for a, b in pairwise(scrobbles()):
assert a.dt <= b.dt

View file

@ -1,6 +1,9 @@
from my import orgmode
from my.core.orgmode import collect
from .common import skip_if_not_karlicoss
@skip_if_not_karlicoss
def test() -> None:
# meh
results = list(orgmode.query().collect_all(lambda n: [n] if 'python' in n.tags else []))

View file

@ -1,3 +1,5 @@
from .common import skip_if_not_karlicoss as pytestmark
from datetime import datetime
import pytz

View file

@ -1,6 +1,7 @@
from .common import skip_if_not_karlicoss as pytestmark
def test() -> None:
from my.rtm import all_tasks
def test():
tasks = all_tasks()
assert len([t for t in tasks if 'gluons' in t.title]) > 0

View file

@ -1,7 +1,9 @@
from .common import skip_if_not_karlicoss as pytestmark
# TODO maybe instead detect if it has any data at all
# if none, then skip the test, say that user doesn't have any data?
# TODO implement via stat?
def test() -> None:
from my.smscalls import calls, messages
# TODO that's a pretty dumb test; perhaps can be generic..
def test():
assert len(list(calls())) > 10
assert len(list(messages())) > 10

View file

@ -8,12 +8,9 @@ from my.google.takeout.html import read_html
from my.google.takeout.paths import get_last_takeout
def ilen(it):
# TODO more_itertools?
return len(list(it))
from more_itertools import ilen
def test_location_perf():
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)))
@ -30,7 +27,7 @@ import pytest # type: ignore
'My Activity/Search/MyActivity.html',
]
)
def test_parser(path: str):
def test_parser(path: str) -> None:
path = 'Takeout/' + path
tpath = get_last_takeout(path=path)
assert tpath is not None
@ -39,7 +36,7 @@ def test_parser(path: str):
print(len(results))
def test_myactivity_search():
def test_myactivity_search() -> None:
path = 'Takeout/My Activity/Search/MyActivity.html'
tpath = get_last_takeout(path=path)
assert tpath is not None

View file

@ -1,12 +1,16 @@
from .common import skip_if_not_karlicoss as pytestmark
# todo current test doesn't depend on data, in principle...
# should make lazy loading the default..
from datetime import datetime
import json
import pytz
def test_tweet() -> None:
from my.twitter.archive import Tweet
def test_tweet():
raw = """
{
"retweeted" : false,

View file

@ -1,11 +1,14 @@
# TODO move elsewhere?
# these tests would only make sense with some existing data? although some of them would work for everyone..
# not sure what's a good way of handling this..
from .common import skip_if_not_karlicoss as pytestmark
# TODO ugh. if i uncomment this here (on top level), then this test vvv fails
# from my.media.youtube import get_watched, Watched
# HPI_TESTS_KARLICOSS=true pytest -raps tests/tz.py tests/youtube.py
def test() -> None:
from my.media.youtube import get_watched, Watched
def test():
watched = list(get_watched())
assert len(watched) > 1000

19
tox.ini
View file

@ -8,6 +8,8 @@ passenv = CI CI_*
# deliberately set to nonexistent path to check the fallback logic
setenv = MY_CONFIG = nonexistent
commands =
# TODO core & modules should be tested separately?
pip install -e .[testing]
# python -m pytest {posargs}
@ -23,18 +25,11 @@ commands =
# my.body.weight dep
pip install orgparse
python3 -m pytest \
tests/cli.py \
tests/core.py \
tests/misc.py \
tests/get_files.py \
tests/config.py::test_environment_variable \
tests/demo.py \
tests/bluemaestro.py \
tests/location.py \
tests/tz.py \
tests/calendar.py \
tests/config.py \
python3 -m pytest tests \
# ignore some tests which might take a while to run on ci..
--ignore tests/takeout.py \
--ignore tests/extra/polar.py \
--ignore tests/pdfs/test_pdfs.py \
{posargs}