-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sm_2.py
66 lines (49 loc) · 2.08 KB
/
test_sm_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from sm_2 import Scheduler, Card, ReviewLog
import json
import pytest
from copy import deepcopy
from datetime import datetime, timezone
class TestSM2:
def test_quickstart(self):
scheduler = Scheduler()
card = Card()
# card is due immediately upon creation
assert datetime.now(timezone.utc) > card.due
rating = 5
card, review_log = scheduler.review_card(card, rating)
due = card.due
# how much time between when the card is due and now
time_delta = due - datetime.now(timezone.utc)
# card is due in 1 day (24 hours)
assert round(time_delta.seconds / 3600) == 24
def test_serialize(self):
scheduler = Scheduler()
card = Card()
old_card = deepcopy(card)
# card is json-serializable
assert type(json.dumps(card.to_dict())) == str
# card can be serialized and de-serialized while remaining the same
card_dict = card.to_dict()
copied_card = Card.from_dict(card_dict)
assert vars(card) == vars(copied_card)
assert card.to_dict() == copied_card.to_dict()
# review the card and perform more tests
rating = 5
review_duration = 3000
card, review_log = scheduler.review_card(
card=card, rating=rating, review_duration=review_duration
)
review_log_dict = review_log.to_dict()
copied_review_log = ReviewLog.from_dict(review_log_dict)
assert review_log.to_dict() == copied_review_log.to_dict()
assert copied_review_log.review_duration == review_duration
# can use the review log to recreate the card that was reviewed
assert (
old_card.to_dict() == Card.from_dict(review_log.to_dict()["card"]).to_dict()
)
# the new reviewed card can be serialized and de-serialized while remaining the same
card_dict = card.to_dict()
copied_card = Card.from_dict(card_dict)
assert vars(card) == vars(copied_card)
assert card.to_dict() == copied_card.to_dict()
# TODO: add tests for interval lengths