2012-12-21 08:51:59 +01:00
|
|
|
import tempfile, os, shutil
|
|
|
|
from anki import Collection as aopen
|
|
|
|
|
|
|
|
def assertException(exception, func):
|
|
|
|
found = False
|
|
|
|
try:
|
|
|
|
func()
|
|
|
|
except exception:
|
|
|
|
found = True
|
|
|
|
assert found
|
|
|
|
|
2014-02-13 08:33:44 +01:00
|
|
|
|
|
|
|
# Creating new decks is expensive. Just do it once, and then spin off
|
|
|
|
# copies from the master.
|
|
|
|
def getEmptyDeck():
|
|
|
|
if len(getEmptyDeck.master) == 0:
|
|
|
|
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
|
|
|
os.unlink(nam)
|
|
|
|
col = aopen(nam)
|
|
|
|
col.db.close()
|
|
|
|
getEmptyDeck.master = nam
|
|
|
|
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
|
|
|
shutil.copy(getEmptyDeck.master, nam)
|
|
|
|
return aopen(nam)
|
|
|
|
|
|
|
|
getEmptyDeck.master = ""
|
|
|
|
|
|
|
|
# Fallback for when the DB needs options passed in.
|
|
|
|
def getEmptyDeckWith(**kwargs):
|
2012-12-21 08:51:59 +01:00
|
|
|
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
|
|
|
os.unlink(nam)
|
|
|
|
return aopen(nam, **kwargs)
|
|
|
|
|
|
|
|
def getUpgradeDeckPath(name="anki12.anki"):
|
|
|
|
src = os.path.join(testDir, "support", name)
|
|
|
|
(fd, dst) = tempfile.mkstemp(suffix=".anki2")
|
|
|
|
shutil.copy(src, dst)
|
2013-09-20 11:06:41 +02:00
|
|
|
return unicode(dst, "utf8")
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
testDir = os.path.dirname(__file__)
|