mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
fix allMedia() and unit tests
This commit is contained in:
parent
ed7367d67f
commit
7a849fccc5
2 changed files with 11 additions and 12 deletions
|
@ -89,7 +89,6 @@ If the same name exists, compare checksums."""
|
||||||
# convert latex first
|
# convert latex first
|
||||||
model = self.deck.models.get(mid)
|
model = self.deck.models.get(mid)
|
||||||
string = mungeQA(string, None, None, model, None, self.deck)
|
string = mungeQA(string, None, None, model, None, self.deck)
|
||||||
print string
|
|
||||||
# extract filenames
|
# extract filenames
|
||||||
for reg in self.regexps:
|
for reg in self.regexps:
|
||||||
for (full, fname) in re.findall(reg, string):
|
for (full, fname) in re.findall(reg, string):
|
||||||
|
@ -161,10 +160,9 @@ If the same name exists, compare checksums."""
|
||||||
def allMedia(self):
|
def allMedia(self):
|
||||||
"Return a set of all referenced filenames."
|
"Return a set of all referenced filenames."
|
||||||
files = set()
|
files = set()
|
||||||
for p in self.deck.renderQA(type="all"):
|
for mid, flds in self.deck.db.execute("select mid, flds from facts"):
|
||||||
for type in ("q", "a"):
|
for f in self.files(mid, flds):
|
||||||
for f in self.mediaFiles(p[type]):
|
files.add(f)
|
||||||
files.add(f)
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
# Copying on import
|
# Copying on import
|
||||||
|
|
|
@ -21,14 +21,15 @@ def test_add():
|
||||||
|
|
||||||
def test_strings():
|
def test_strings():
|
||||||
d = getEmptyDeck()
|
d = getEmptyDeck()
|
||||||
mf = d.media.mediaFiles
|
mf = d.media.files
|
||||||
assert mf("aoeu") == []
|
mid = d.models.models.keys()[0]
|
||||||
assert mf("aoeu<img src='foo.jpg'>ao") == ["foo.jpg"]
|
assert mf(mid, "aoeu") == []
|
||||||
assert mf("aoeu<img src=foo bar.jpg>ao") == ["foo bar.jpg"]
|
assert mf(mid, "aoeu<img src='foo.jpg'>ao") == ["foo.jpg"]
|
||||||
assert mf("aoeu<img src=\"foo.jpg\">ao") == ["foo.jpg"]
|
assert mf(mid, "aoeu<img src=foo bar.jpg>ao") == ["foo bar.jpg"]
|
||||||
assert mf("aoeu<img src=\"foo.jpg\"><img class=yo src=fo>ao") == [
|
assert mf(mid, "aoeu<img src=\"foo.jpg\">ao") == ["foo.jpg"]
|
||||||
|
assert mf(mid, "aoeu<img src=\"foo.jpg\"><img class=yo src=fo>ao") == [
|
||||||
"foo.jpg", "fo"]
|
"foo.jpg", "fo"]
|
||||||
assert mf("aou[sound:foo.mp3]aou") == ["foo.mp3"]
|
assert mf(mid, "aou[sound:foo.mp3]aou") == ["foo.mp3"]
|
||||||
sp = d.media.strip
|
sp = d.media.strip
|
||||||
assert sp("aoeu") == "aoeu"
|
assert sp("aoeu") == "aoeu"
|
||||||
assert sp("aoeu[sound:foo.mp3]aoeu") == "aoeuaoeu"
|
assert sp("aoeu[sound:foo.mp3]aoeu") == "aoeuaoeu"
|
||||||
|
|
Loading…
Reference in a new issue