anki/pylib/tests/test_stats.py
Abdo b23f17df27
Drop support for checkpoints (#2742)
* Drop support for checkpoints

* Deprecate .flush()

* Remove .begin/.commit

* Remove rollback() and deprecate save/autosave/reset()

There's no need to commit anymore, as the Rust code is handling
transactions for us.

* Add safer transact() method

This will ensure add-on authors can't accidentally leave a transaction
open, leading to data loss.

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2023-10-17 12:43:34 +10:00

40 lines
958 B
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import os
import tempfile
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
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
def test_graphs_empty():
col = getEmptyCol()
assert col.stats().report()
def test_graphs():
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