my.reddit: enable CI tests

This commit is contained in:
Dima Gerasimov 2021-12-23 07:39:20 +00:00 committed by karlicoss
parent 01dfbbd58e
commit 5e9cc2a6a0
4 changed files with 37 additions and 30 deletions

View file

@ -168,7 +168,7 @@ def _get_state(bfile: Path) -> Dict[Uid, SaveWithDt]:
# TODO hmm. think about it.. if we set default backups=inputs() # TODO hmm. think about it.. if we set default backups=inputs()
# it's called early so it ends up as a global variable that we can't monkey patch easily # it's called early so it ends up as a global variable that we can't monkey patch easily
@mcachew @mcachew(lambda backups: backups)
def _get_events(backups: Sequence[Path], parallel: bool=True) -> Iterator[Event]: def _get_events(backups: Sequence[Path], parallel: bool=True) -> Iterator[Event]:
# todo cachew: let it transform return type? so you don't have to write a wrapper for lists? # todo cachew: let it transform return type? so you don't have to write a wrapper for lists?

@ -1 +1 @@
Subproject commit bcd45b64669bc94849a585b14a09a5d07f60915a Subproject commit 79c23e1b88d22f4ee740af21bbd7a237ad0a4165

View file

@ -1,19 +1,18 @@
from .common import skip_if_not_karlicoss as pytestmark
from datetime import datetime from datetime import datetime
import pytz import pytz
from my.common import make_dict
def test_basic() -> None:
def test() -> None: # todo maybe this should call stat or something instead?
from my.reddit.rexport import events, inputs, saved # would ensure reasonable stat implementation as well and less duplication
list(events()) # note: deliberately use old module (instead of my.reddit.all) to test bwd compatibility
list(saved()) from my.reddit import saved, events
assert len(list(events())) > 0
assert len(list(saved())) > 0
def test_unfav() -> None: def test_unfav() -> None:
from my.reddit.rexport import events, inputs, saved from my.reddit import events, saved
ev = events() ev = events()
url = 'https://reddit.com/r/QuantifiedSelf/comments/acxy1v/personal_dashboard/' url = 'https://reddit.com/r/QuantifiedSelf/comments/acxy1v/personal_dashboard/'
uev = [e for e in ev if e.url == url] uev = [e for e in ev if e.url == url]
@ -26,15 +25,17 @@ def test_unfav() -> None:
def test_saves() -> None: def test_saves() -> None:
from my.reddit.rexport import events, inputs, saved from my.reddit.all import saved
# TODO not sure if this is necesasry anymore?
saves = list(saved()) saves = list(saved())
# just check that they are unique.. assert len(saves) > 0
# just check that they are unique (makedict will throw)
from my.core.common import make_dict
make_dict(saves, key=lambda s: s.sid) make_dict(saves, key=lambda s: s.sid)
def test_disappearing() -> None: def test_disappearing() -> None:
from my.reddit.rexport import events, inputs, saved from my.reddit.rexport import events
# eh. so for instance, 'metro line colors' is missing from reddit-20190402005024.json for no reason # eh. so for instance, 'metro line colors' is missing from reddit-20190402005024.json for no reason
# but I guess it was just a short glitch... so whatever # but I guess it was just a short glitch... so whatever
saves = events() saves = events()
@ -44,29 +45,33 @@ def test_disappearing() -> None:
def test_unfavorite() -> None: def test_unfavorite() -> None:
from my.reddit.rexport import events, inputs, saved from my.reddit.rexport import events
evs = events() evs = events()
unfavs = [s for s in evs if s.text == 'unfavorited'] unfavs = [s for s in evs if s.text == 'unfavorited']
[xxx] = [u for u in unfavs if u.eid == 'unf-19ifop'] [xxx] = [u for u in unfavs if u.eid == 'unf-19ifop']
assert xxx.dt == datetime(2019, 1, 28, 8, 10, 20, tzinfo=pytz.utc) assert xxx.dt == datetime(2019, 1, 29, 10, 10, 20, tzinfo=pytz.utc)
def test_extra_attr() -> None: def test_preserves_extra_attr() -> None:
from my.reddit.rexport import config # doesn't strictly belong here (not specific to reddit)
assert isinstance(getattr(config, 'passthrough'), str) # but my.reddit does a fair bit of dyunamic hacking, so perhaps a good place to check nothing is lost
from my.reddit import config
assert isinstance(getattr(config, 'please_keep_me'), str)
import pytest # type: ignore import pytest # type: ignore
@pytest.fixture(autouse=True, scope='module') @pytest.fixture(autouse=True, scope='module')
def prepare(): def prepare():
from my.common import get_files from .common import testdata
from my.config import reddit as config data = testdata() / 'hpi-testdata' / 'reddit'
# since these are only tested locally, the config should be fine assert data.exists(), data
# just need to make sure local config matches that in my.config properly
files = get_files(config.rexport.export_path)
# use less files for the test to make it faster
# first bit is for 'test_unfavorite, the second is for test_disappearing
files = files[300:330] + files[500:520]
config.export_dir = files # type: ignore
setattr(config, 'passthrough', "isn't handled, but available dynamically nevertheless") # note: deliberately using old config schema so we can test migrations
class test_config:
export_dir = data
please_keep_me = 'whatever'
from my.core.cfg import tmp_config
with tmp_config() as config:
config.reddit = test_config
yield

View file

@ -47,6 +47,8 @@ commands =
hpi module install my.pdfs hpi module install my.pdfs
hpi module install my.reddit.rexport
python3 -m pytest tests \ python3 -m pytest tests \
# ignore some tests which might take a while to run on ci.. # ignore some tests which might take a while to run on ci..
--ignore tests/takeout.py \ --ignore tests/takeout.py \