mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02:23 -04:00
handle the two remaining timing issues
This commit is contained in:
parent
69d8cdd9ed
commit
ac36fba90f
4 changed files with 49 additions and 30 deletions
|
@ -1,9 +1,22 @@
|
|||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from anki import Collection as aopen
|
||||
|
||||
# Between 2-4AM, shift the time back so test assumptions hold.
|
||||
lt = time.localtime()
|
||||
if lt.tm_hour >= 2 and lt.tm_hour < 4:
|
||||
orig_time = time.time
|
||||
|
||||
def adjusted_time():
|
||||
return orig_time() - 60 * 60 * 2
|
||||
|
||||
time.time = adjusted_time
|
||||
else:
|
||||
orig_time = None
|
||||
|
||||
|
||||
def assertException(exception, func):
|
||||
found = False
|
||||
|
@ -48,3 +61,15 @@ def getUpgradeDeckPath(name="anki12.anki"):
|
|||
|
||||
|
||||
testDir = os.path.dirname(__file__)
|
||||
|
||||
|
||||
def errorsAfterMidnight(func):
|
||||
lt = time.localtime()
|
||||
if lt.tm_hour < 4:
|
||||
print("test disabled around cutoff", func)
|
||||
else:
|
||||
func()
|
||||
|
||||
|
||||
def isNearCutoff():
|
||||
return orig_time is not None
|
||||
|
|
|
@ -6,6 +6,7 @@ import tempfile
|
|||
from anki import Collection as aopen
|
||||
from anki.exporting import *
|
||||
from anki.importing import Anki2Importer
|
||||
from tests.shared import errorsAfterMidnight
|
||||
from tests.shared import getEmptyCol as getEmptyColOrig
|
||||
|
||||
|
||||
|
@ -97,6 +98,7 @@ def test_export_ankipkg():
|
|||
e.exportInto(newname)
|
||||
|
||||
|
||||
@errorsAfterMidnight
|
||||
def test_export_anki_due():
|
||||
setup1()
|
||||
deck = getEmptyCol()
|
||||
|
|
|
@ -3,7 +3,7 @@ import pytest
|
|||
|
||||
from anki.consts import *
|
||||
from anki.rsbackend import BuiltinSortKind
|
||||
from tests.shared import getEmptyCol
|
||||
from tests.shared import getEmptyCol, isNearCutoff
|
||||
|
||||
|
||||
class DummyCollection:
|
||||
|
@ -189,19 +189,27 @@ def test_findCards():
|
|||
assert len(deck.findCards("prop:ease>2")) == 1
|
||||
assert len(deck.findCards("-prop:ease>2")) > 1
|
||||
# recently failed
|
||||
assert len(deck.findCards("rated:1:1")) == 0
|
||||
assert len(deck.findCards("rated:1:2")) == 0
|
||||
c = deck.sched.getCard()
|
||||
deck.sched.answerCard(c, 2)
|
||||
assert len(deck.findCards("rated:1:1")) == 0
|
||||
assert len(deck.findCards("rated:1:2")) == 1
|
||||
c = deck.sched.getCard()
|
||||
deck.sched.answerCard(c, 1)
|
||||
assert len(deck.findCards("rated:1:1")) == 1
|
||||
assert len(deck.findCards("rated:1:2")) == 1
|
||||
assert len(deck.findCards("rated:1")) == 2
|
||||
assert len(deck.findCards("rated:0:2")) == 0
|
||||
assert len(deck.findCards("rated:2:2")) == 1
|
||||
if not isNearCutoff():
|
||||
assert len(deck.findCards("rated:1:1")) == 0
|
||||
assert len(deck.findCards("rated:1:2")) == 0
|
||||
c = deck.sched.getCard()
|
||||
deck.sched.answerCard(c, 2)
|
||||
assert len(deck.findCards("rated:1:1")) == 0
|
||||
assert len(deck.findCards("rated:1:2")) == 1
|
||||
c = deck.sched.getCard()
|
||||
deck.sched.answerCard(c, 1)
|
||||
assert len(deck.findCards("rated:1:1")) == 1
|
||||
assert len(deck.findCards("rated:1:2")) == 1
|
||||
assert len(deck.findCards("rated:1")) == 2
|
||||
assert len(deck.findCards("rated:0:2")) == 0
|
||||
assert len(deck.findCards("rated:2:2")) == 1
|
||||
# added
|
||||
assert len(deck.findCards("added:0")) == 0
|
||||
deck.db.execute("update cards set id = id - 86400*1000 where id = ?", id)
|
||||
assert len(deck.findCards("added:1")) == deck.cardCount() - 1
|
||||
assert len(deck.findCards("added:2")) == deck.cardCount()
|
||||
else:
|
||||
print("some find tests disabled near cutoff")
|
||||
# empty field
|
||||
assert len(deck.findCards("front:")) == 0
|
||||
f = deck.newNote()
|
||||
|
@ -215,11 +223,6 @@ def test_findCards():
|
|||
assert len(deck.findCards("-(tag:monkey OR tag:sheep)")) == 6
|
||||
assert len(deck.findCards("tag:monkey or (tag:sheep sheep)")) == 2
|
||||
assert len(deck.findCards("tag:monkey or (tag:sheep octopus)")) == 1
|
||||
# added
|
||||
assert len(deck.findCards("added:0")) == 0
|
||||
deck.db.execute("update cards set id = id - 86400*1000 where id = ?", id)
|
||||
assert len(deck.findCards("added:1")) == deck.cardCount() - 1
|
||||
assert len(deck.findCards("added:2")) == deck.cardCount()
|
||||
# flag
|
||||
with pytest.raises(Exception):
|
||||
deck.findCards("flag:12")
|
||||
|
|
|
@ -16,17 +16,6 @@ def getEmptyCol():
|
|||
return col
|
||||
|
||||
|
||||
# Between 2-4AM, shift the time back so test assumptions hold.
|
||||
lt = time.localtime()
|
||||
if lt.tm_hour >= 2 and lt.tm_hour < 4:
|
||||
orig_time = time.time
|
||||
|
||||
def adjusted_time():
|
||||
return orig_time() - 60 * 60 * 2
|
||||
|
||||
time.time = adjusted_time
|
||||
|
||||
|
||||
def test_clock():
|
||||
d = getEmptyCol()
|
||||
if (d.sched.dayCutoff - intTime()) < 10 * 60:
|
||||
|
|
Loading…
Reference in a new issue