reddit.rexport: some cleanup, move get_events stuff into personal overlay

This commit is contained in:
Dima Gerasimov 2023-10-19 01:08:50 +01:00 committed by karlicoss
parent fe26efaea8
commit 28d2450a21
2 changed files with 36 additions and 178 deletions

View file

@ -1,5 +1,3 @@
from datetime import datetime, timezone
from my.core.cfg import tmp_config
from my.core.common import make_dict
@ -13,34 +11,25 @@ import my.reddit.rexport as my_reddit_rexport
import my.reddit.all as my_reddit_all
def test_basic() -> None:
def test_basic_1() -> None:
# todo maybe this should call stat or something instead?
# would ensure reasonable stat implementation as well and less duplication
# note: deliberately use old module (instead of my.reddit.all) to test bwd compatibility
from my.reddit import saved, events
from my.reddit import saved
assert len(list(events())) > 0
assert len(list(saved())) > 0
def test_basic_2() -> None:
# deliberately check call from a different style of import to make sure tmp_config works
saves = list(my_reddit_rexport.saved())
assert len(saves) > 0
def test_comments() -> None:
assert len(list(my_reddit_all.comments())) > 0
def test_unfav() -> None:
from my.reddit import events
ev = events()
url = 'https://reddit.com/r/QuantifiedSelf/comments/acxy1v/personal_dashboard/'
uev = [e for e in ev if e.url == url]
assert len(uev) == 2
ff = uev[0]
# TODO could recover these from takeout perhaps?
assert ff.text == 'favorited [initial]'
uf = uev[1]
assert uf.text == 'unfavorited'
def test_saves() -> None:
from my.reddit.all import saved
@ -51,22 +40,6 @@ def test_saves() -> None:
make_dict(saves, key=lambda s: s.sid)
def test_disappearing() -> None:
# 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
evs = my_reddit_rexport.events()
favs = [s.kind for s in evs if s.text == 'favorited']
[deal_with_it] = [f for f in favs if f.title == '"Deal with it!"']
assert deal_with_it.backup_dt == datetime(2019, 4, 1, 23, 10, 25, tzinfo=timezone.utc)
def test_unfavorite() -> None:
evs = my_reddit_rexport.events()
unfavs = [s for s in evs if s.text == 'unfavorited']
[xxx] = [u for u in unfavs if u.eid == 'unf-19ifop']
assert xxx.dt == datetime(2019, 1, 29, 10, 10, 20, tzinfo=timezone.utc)
def test_preserves_extra_attr() -> None:
# doesn't strictly belong here (not specific to reddit)
# but my.reddit does a fair bit of dynamic hacking, so perhaps a good place to check nothing is lost