Skip to content

Commit

Permalink
Add test_media_files_in_subdirs test
Browse files Browse the repository at this point in the history
  • Loading branch information
kerrickstaley committed Dec 30, 2021
1 parent 0ad24ed commit 09d24a3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_genanki.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,32 @@ def test_media_files(self):
missing, unused, invalid = self.check_media()
assert set(missing) == {'missing.mp3', 'missing.jpg'}

def test_media_files_in_subdirs(self):
# change to a scratch directory so we can write files
os.chdir(tempfile.mkdtemp())

deck = genanki.Deck(123456, 'foodeck')
note = genanki.Note(TEST_MODEL, [
'question [sound:present.mp3] [sound:missing.mp3]',
'answer <img src="present.jpg"> <img src="missing.jpg">'])
deck.add_note(note)

# populate files with data
os.mkdir('subdir1')
with open('subdir1/present.mp3', 'wb') as h:
h.write(VALID_MP3)
os.mkdir('subdir2')
with open('subdir2/present.jpg', 'wb') as h:
h.write(VALID_JPG)

self.import_package(genanki.Package(deck, media_files=['subdir1/present.mp3', 'subdir2/present.jpg']))

os.remove('subdir1/present.mp3')
os.remove('subdir2/present.jpg')

missing, unused, invalid = self.check_media()
assert set(missing) == {'missing.mp3', 'missing.jpg'}

def test_media_files_absolute_paths(self):
# change to a scratch directory so we can write files
os.chdir(tempfile.mkdtemp())
Expand Down

0 comments on commit 09d24a3

Please sign in to comment.