update unit tests to use deck_due_tree()

This commit is contained in:
Damien Elmes 2020-05-16 12:10:40 +10:00
parent 0c340eba64
commit 24dd116f91
3 changed files with 35 additions and 40 deletions

View File

@ -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:

View File

@ -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():

View File

@ -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