From 24dd116f91839c7987ffff0c6d6100d87b331edb Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 16 May 2020 12:10:40 +1000 Subject: [PATCH] update unit tests to use deck_due_tree() --- pylib/anki/schedv2.py | 3 +++ pylib/tests/test_schedv1.py | 35 +++++++++++++---------------------- pylib/tests/test_schedv2.py | 37 +++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 5913fd217..ebe40446c 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -230,6 +230,9 @@ order by due""" def deckDueTree(self) -> Any: "List of (base name, did, rev, lrn, new, children)" + print( + "deckDueTree() is deprecated; use decks.deck_tree() for a tree without counts, or sched.deck_due_tree()" + ) return self.col.backend.legacy_deck_tree() def deck_due_tree(self) -> DeckTreeNode: diff --git a/pylib/tests/test_schedv1.py b/pylib/tests/test_schedv1.py index 1f3f58976..197a08f3e 100644 --- a/pylib/tests/test_schedv1.py +++ b/pylib/tests/test_schedv1.py @@ -620,7 +620,7 @@ def test_cram(): d.sched.rebuildDyn(did) d.reset() # should appear as new in the deck list - assert sorted(d.sched.deckDueTree())[0][4] == 1 + assert sorted(d.sched.deck_due_tree().children)[0].new_count == 1 # and should appear in the counts assert d.sched.counts() == (1, 0, 0) # grab it and check estimates @@ -674,7 +674,7 @@ def test_cram(): assert d.sched.nextIvl(c, 3) == 86400 # delete the deck, returning the card mid-study d.decks.rem(d.decks.selected()) - assert len(d.sched.deckDueTree()) == 1 + assert len(d.sched.deck_due_tree().children) == 1 c.load() assert c.ivl == 1 assert c.due == d.sched.today + 1 @@ -1020,31 +1020,22 @@ def test_deckDue(): d.addNote(f) d.reset() assert len(d.decks.all_names_and_ids()) == 5 - tree = d.sched.deckDueTree() - assert tree[0][0] == "Default" + tree = d.sched.deck_due_tree().children + assert tree[0].name == "Default" # sum of child and parent - assert tree[0][1] == 1 - assert tree[0][2] == 1 - assert tree[0][4] == 1 + assert tree[0].deck_id == 1 + assert tree[0].review_count == 1 + assert tree[0].new_count == 1 # child count is just review - assert tree[0][5][0][0] == "1" - assert tree[0][5][0][1] == default1 - assert tree[0][5][0][2] == 1 - assert tree[0][5][0][4] == 0 + child = tree[0].children[0] + assert child.name == "1" + assert child.deck_id == default1 + assert child.review_count == 1 + assert child.new_count == 0 # code should not fail if a card has an invalid deck c.did = 12345 c.flush() - d.sched.deckDueTree() - - -def test_deckTree(): - d = getEmptyCol() - d.decks.id("new::b::c") - d.decks.id("new2") - # new should not appear twice in tree - names = [x[0] for x in d.sched.deckDueTree()] - names.remove("new") - assert "new" not in names + d.sched.deck_due_tree() def test_deckFlow(): diff --git a/pylib/tests/test_schedv2.py b/pylib/tests/test_schedv2.py index a25dfbd08..be805a83b 100644 --- a/pylib/tests/test_schedv2.py +++ b/pylib/tests/test_schedv2.py @@ -440,10 +440,10 @@ def test_review_limits(): c.due = 0 c.flush() - tree = d.sched.deckDueTree() + tree = d.sched.deck_due_tree().children # (('parent', 1514457677462, 5, 0, 0, (('child', 1514457677463, 5, 0, 0, ()),))) - assert tree[0][2] == 5 # parent - assert tree[0][5][0][2] == 5 # child + assert tree[0].review_count == 5 # parent + assert tree[0].children[0].review_count == 5 # child # .counts() should match d.decks.select(child["id"]) @@ -455,9 +455,9 @@ def test_review_limits(): d.sched.answerCard(c, 3) assert d.sched.counts() == (0, 0, 4) - tree = d.sched.deckDueTree() - assert tree[0][2] == 4 # parent - assert tree[0][5][0][2] == 4 # child + tree = d.sched.deck_due_tree().children + assert tree[0].review_count == 4 # parent + assert tree[0].children[0].review_count == 4 # child def test_button_spacing(): @@ -721,7 +721,7 @@ def test_filt_reviewing_early_normal(): d.sched.rebuildDyn(did) d.reset() # should appear as normal in the deck list - assert sorted(d.sched.deckDueTree())[0][2] == 1 + assert sorted(d.sched.deck_due_tree().children)[0].review_count == 1 # and should appear in the counts assert d.sched.counts() == (0, 0, 1) # grab it and check estimates @@ -1023,21 +1023,22 @@ def test_deckDue(): d.addNote(f) d.reset() assert len(d.decks.all_names_and_ids()) == 5 - tree = d.sched.deckDueTree() - assert tree[0][0] == "Default" + tree = d.sched.deck_due_tree().children + assert tree[0].name == "Default" # sum of child and parent - assert tree[0][1] == 1 - assert tree[0][2] == 1 - assert tree[0][4] == 1 + assert tree[0].deck_id == 1 + assert tree[0].review_count == 1 + assert tree[0].new_count == 1 # child count is just review - assert tree[0][5][0][0] == "1" - assert tree[0][5][0][1] == default1 - assert tree[0][5][0][2] == 1 - assert tree[0][5][0][4] == 0 + child = tree[0].children[0] + assert child.name == "1" + assert child.deck_id == default1 + assert child.review_count == 1 + assert child.new_count == 0 # code should not fail if a card has an invalid deck c.did = 12345 c.flush() - d.sched.deckDueTree() + d.sched.deck_due_tree() def test_deckTree(): @@ -1045,7 +1046,7 @@ def test_deckTree(): d.decks.id("new::b::c") d.decks.id("new2") # new should not appear twice in tree - names = [x[0] for x in d.sched.deckDueTree()] + names = [x.name for x in d.sched.deck_due_tree().children] names.remove("new") assert "new" not in names