mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00

Earlier today I pushed a change that split this code up into multiple repos, but that has proved to complicate things too much. So we're back to a single repo, except the individual submodules are better separated than they were before. The README files need updating again; I will push them out soon. Aside from splitting out the different modules, the sound code has moved from from anki to aqt.
50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
import os
|
|
import shutil
|
|
import tempfile
|
|
|
|
from anki import Collection as aopen
|
|
|
|
|
|
def assertException(exception, func):
|
|
found = False
|
|
try:
|
|
func()
|
|
except exception:
|
|
found = True
|
|
assert found
|
|
|
|
|
|
# Creating new decks is expensive. Just do it once, and then spin off
|
|
# copies from the master.
|
|
def getEmptyCol():
|
|
if len(getEmptyCol.master) == 0:
|
|
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
|
os.close(fd)
|
|
os.unlink(nam)
|
|
col = aopen(nam)
|
|
col.db.close()
|
|
getEmptyCol.master = nam
|
|
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
|
shutil.copy(getEmptyCol.master, nam)
|
|
col = aopen(nam)
|
|
return col
|
|
|
|
|
|
getEmptyCol.master = ""
|
|
|
|
# Fallback for when the DB needs options passed in.
|
|
def getEmptyDeckWith(**kwargs):
|
|
(fd, nam) = tempfile.mkstemp(suffix=".anki2")
|
|
os.close(fd)
|
|
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)
|
|
return dst
|
|
|
|
|
|
testDir = os.path.dirname(__file__)
|