Exemple #1
0
def test_sub_sub_list_improper_formatting():

    answers = [["level3"], "level2", ["level3", ["level4"]]]
    a = AnkiNoteBuilder()
    answerString = a.createAnswerString({}, answers)

    assert (
        answerString ==
        "<ul style='list-style-position: inside;'><ul style='list-style-position: inside;'><li>level3</li></ul><li>level2</li><ul style='list-style-position: inside;'><li>level3</li><ul style='list-style-position: inside;'><li>level4</li></ul></ul></ul>"
    )
Exemple #2
0
def testBuildNoteForSublists():

    answers = [
        "first answer", ["sublist 1", ["sublist2"], "back to sublist1"],
        "second answer"
    ]
    a = AnkiNoteBuilder()
    answerString = a.createAnswerString({}, answers)

    expectedString = "<ul style='list-style-position: inside;'><li>first answer</li><ul style='list-style-position: inside;'><li>sublist 1</li><ul style='list-style-position: inside;'><li>sublist2</li></ul><li>back to sublist1</li></ul><li>second answer</li></ul>"
    assert (answerString == expectedString)
Exemple #3
0
def testMultiLineQuestionLine():

    q = AnkiQuestion("Capital Cities\nCapital of dublin")
    q.addAnswer("Dublin")
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    assert (
        noteData["fields"]["Front"] == "Capital Cities<br>Capital of dublin")
Exemple #4
0
def testLegacyModelTypeWorks():

    q = AnkiQuestion("Capital of dublin")
    q.addAnswer("Dublin")
    q.addParameter("type", "testType")
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    assert (noteData["modelName"] == "testType")
Exemple #5
0
def testBuildNoteWithTags():

    # Build Generic question
    q = AnkiQuestion("When was Dublin founded {{c1::1204}}")
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    q.addParameter("tags", "a,b,c")

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])
    assert (noteData.get("tags") == ['a', 'b', 'c'])
Exemple #6
0
def testMultiLevelListWith_listEqualToFalseParameter():

    q = AnkiQuestion("Question")
    q.addParameter("list", "false")
    q.addAnswer("answer 1")
    q.addAnswer(["sub answer 1"])
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])
    assert (
        noteData.get("fields").get("Back") == "answer 1<br>sub answer 1<br>")
Exemple #7
0
def testQuestionWithoutListTags():

    q = AnkiQuestion("Capital of dublin")
    q.addAnswer("Dublin 1")
    q.addAnswer("Dublin 2")
    q.addParameter("list", "false")
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    assert (noteData["fields"]["Back"] == "Dublin 1<br>Dublin 2<br>")
Exemple #8
0
def testBuildingSingleFieldClozeNote():

    q = AnkiQuestion("When was Dublin founded {{c1::1204}}")
    q.addParameter("type", "Cloze")
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    assert (
        noteData["fields"]["Text"] == "When was Dublin founded {{c1::1204}}")
    assert (noteData["fields"]["Extra"] == "")
Exemple #9
0
def testQuestionTypeCorrectlyUsed():

    #Build basic quesions
    q = AnkiQuestion("Capital of dublin")
    q.addAnswer("Dublin")
    q.addParameter("type", "Basic (and reversed card)")

    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    assert (noteData["modelName"] == "Basic (and reversed card)")
Exemple #10
0
def testBuildingMultiFieldNotes():

    q = AnkiQuestion("Question")
    q.addAnswer("Answer")
    q.addLineToNamedField("field1", "Value 1")
    q.addLineToNamedField("field1", "Value 2")
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    expectedString = "<ul style='list-style-position: inside;'><li>Value 1</li><li>Value 2</li></ul>"
    assert (noteData.get("fields").get("field1", None) != None)
    assert (noteData.get("fields").get("field1") == expectedString)
Exemple #11
0
def testCodeQuestionBuildsWithListStyle():

    q = AnkiQuestion("Capital of dublin")
    q.addParameter("codeStyle", "manni")
    q.addCode("python3", ["print('Hello')"])
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    assert (
        noteData["fields"]["Back"] ==
        """<ul style='list-style-position: inside;'><li><div style="text-align:left"> <div class="highlight" style="background: #f0f3f3"><pre style="line-height: 125%"><span></span><span style="color: #336666">print</span>(<span style="color: #CC3300">&#39;Hello&#39;</span>)<br></pre></div> </div></li></ul>"""
    )
Exemple #12
0
def testQuestionOrderedList():

    q = AnkiQuestion("Capital of dublin")
    q.addAnswer("Dublin 1")
    q.addAnswer("Dublin 2")
    q.addParameter("list", "ol")
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    assert (
        noteData["fields"]["Back"] ==
        "<ol style='list-style-position: inside;'><li>Dublin 1</li><li>Dublin 2</li></ol>"
    )
Exemple #13
0
def testBuildingClozeNotes():

    q = AnkiQuestion("When was Dublin founded {{c1::1204}}")
    q.addAnswer("Some Extra info")
    q.addParameter("type", "Cloze")
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    assert (
        noteData["fields"]["Text"] == "When was Dublin founded {{c1::1204}}")
    assert (
        noteData["fields"]["Extra"] ==
        "<ul style='list-style-position: inside;'><li>Some Extra info</li></ul>"
    )
Exemple #14
0
def testBuildBasicNote():

    #Build basic quesions
    q = AnkiQuestion("Capital of dublin")
    q.addAnswer("Dublin")
    deck = AnkiDeck("Capitals")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])

    expectedDeckName = config.defaultDeck + config.defaultDeckConnector + "Capitals"
    print(noteData)
    assert (noteData["deckName"] == expectedDeckName)
    assert (noteData["modelName"] == "Basic")
    assert (noteData["tags"] == [])
    assert (noteData["fields"]["Front"] == "Capital of dublin")
    assert (noteData["fields"]["Back"] ==
            "<ul style='list-style-position: inside;'><li>Dublin</li></ul>")
Exemple #15
0
def test_no_base_deck_paramters():

    q = AnkiQuestion("Question")
    q.addAnswer("answer 1")
    deck = AnkiDeck("test")
    deck.addQuestion(q)

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])
    assert (noteData["deckName"] != "test")

    # Remove default deck
    q.addParameter("baseDeck", "false")

    a = AnkiNoteBuilder()
    noteData = a.buildNote(deck.getQuestions()[0])
    assert (noteData.get("deckName", "test"))