anki/pylib/tests/test_stats.py

41 lines
974 B
Python
Raw Normal View History

2021-04-13 10:45:05 +02:00
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
2019-12-25 05:18:34 +01:00
import os
2019-12-25 22:00:10 +01:00
import tempfile
2019-12-25 05:18:34 +01:00
from anki.collection import CardStats
from tests.shared import getEmptyCol
def test_stats():
col = getEmptyCol()
note = col.newNote()
note["Front"] = "foo"
col.addNote(note)
c = note.cards()[0]
# card stats
card_stats = col.card_stats_data(c.id)
assert card_stats.note_id == note.id
col.reset()
c = col.sched.getCard()
col.sched.answerCard(c, 3)
col.sched.answerCard(c, 2)
card_stats = col.card_stats_data(c.id)
assert len(card_stats.revlog) == 2
2019-12-25 05:18:34 +01:00
def test_graphs_empty():
col = getEmptyCol()
assert col.stats().report()
2019-12-25 05:18:34 +01:00
def test_graphs():
2019-12-25 22:00:10 +01:00
dir = tempfile.gettempdir()
col = getEmptyCol()
g = col.stats()
rep = g.report()
with open(os.path.join(dir, "test.html"), "w", encoding="UTF-8") as note:
note.write(rep)
return