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 test for sort_field_index #71

Merged
merged 1 commit into from
Mar 27, 2021
Merged
Changes from all commits
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
33 changes: 33 additions & 0 deletions tests/test_genanki.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@
latex_post=CUSTOM_LATEX_POST,
)

CUSTOM_SORT_FIELD_INDEX = 1 # Anki default value is 0
TEST_MODEL_WITH_SORT_FIELD_INDEX = genanki.Model(
987123, 'with sort field index',
fields=[
{
'name': 'AField',
},
{
'name': 'BField',
},
],
templates=[
{
'name': 'card1',
'qfmt': '{{AField}}',
'afmt': '{{FrontSide}}'
'<hr id="answer">'
'{{BField}}',
}
],
sort_field_index=CUSTOM_SORT_FIELD_INDEX,
)

# VALID_MP3 and VALID_JPG courtesy of https://github.com/mathiasbynens/small
VALID_MP3 = (
b'\xff\xe3\x18\xc4\x00\x00\x00\x03H\x00\x00\x00\x00LAME3.98.2\x00\x00\x00'
Expand Down Expand Up @@ -369,3 +392,13 @@ def test_model_with_latex_pre_and_post(self):
anki_note = self.col.getNote(self.col.findNotes('')[0])
assert anki_note.model()['latexPre'] == CUSTOM_LATEX_PRE
assert anki_note.model()['latexPost'] == CUSTOM_LATEX_POST

def test_model_with_sort_field_index(self):
deck = genanki.Deck(332211, 'foodeck')
note = genanki.Note(TEST_MODEL_WITH_SORT_FIELD_INDEX, ['a', '3.A'])
deck.add_note(note)

self.import_package(genanki.Package(deck))

anki_note = self.col.getNote(self.col.findNotes('')[0])
assert anki_note.model()['sortf'] == CUSTOM_SORT_FIELD_INDEX