Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Back Extra" field to Cloze builtin model #101

Merged
merged 7 commits into from
Jan 4, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix up tests
  • Loading branch information
kerrickstaley committed Jan 4, 2022
commit e1369a948c112076efcb7f5079ea7816736c8309
30 changes: 28 additions & 2 deletions tests/test_builtin_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import genanki
import os
import pytest
import tempfile
import warnings


def test_builtin_models():
Expand All @@ -24,13 +26,37 @@ def test_builtin_models():
model=genanki.BASIC_TYPE_IN_THE_ANSWER_MODEL,
fields=['Taiwan', 'Taipei']))

my_deck.add_note(genanki.Note(
model=genanki.CLOZE_MODEL,
fields=[
'{{c1::Ottawa}} is the capital of {{c2::Canada}}',
'Ottawa is in Ontario province.']))

# Just try writing the notes to a .apkg file; if there is no Exception and no Warnings, we assume
# things are good.
fnode, fpath = tempfile.mkstemp()
os.close(fnode)

with warnings.catch_warnings(record=True) as warning_list:
my_deck.write_to_file(fpath)

assert not warning_list

os.unlink(fpath)

def test_cloze_with_single_field_warns():
my_deck = genanki.Deck(
1598559905,
'Country Capitals')

my_deck.add_note(genanki.Note(
model=genanki.CLOZE_MODEL,
fields=['{{c1::Rome}} is the capital of {{c2::Italy}}']))

# Just try writing the note to a .apkg file; if there is no Exception, we assume things are good.
fnode, fpath = tempfile.mkstemp()
os.close(fnode)
my_deck.write_to_file(fpath)

with pytest.warns(DeprecationWarning):
my_deck.write_to_file(fpath)

os.unlink(fpath)