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
|
import pytest
import json
from flashcards.session import Session
@pytest.fixture
def cardFiles(tmp_path):
card_files = [
tmp_path / "test1.fcard",
tmp_path / "test2.fcard",
]
for i, c in enumerate(card_files):
with open(c, "w") as f:
for j in range(0, 3):
f.write(f"FRONT\nFile {i}, card {j} front\nBACK\nback\n")
return card_files
@pytest.fixture
def stateFile(tmp_path):
return tmp_path / "state.json"
def test_practiceSession(cardFiles, stateFile):
session = Session("brutal", cardFiles, stateFile)
c = 0
for card in session.practice(5):
c += 1
assert c == 5
def test_testSession(cardFiles, stateFile):
session = Session("brutal", cardFiles, stateFile)
c = 0
for i, (card, correct) in enumerate(session.test(5)):
c += 1
correct(i % 2 == 0)
assert c == 5
with open(stateFile, "r") as f:
state = json.load(f)
latest_scores = [history[-1] for id, history in state.items()]
assert latest_scores.count(0) == 2
assert latest_scores.count(1) == 3
|