Beispiel #1
0
def testDecksInheritParamsFromParentDeck():

    q1 = AnkiQuestion("Test question")
    q1.addAnswer("Test Answer")
    q1.addParameter("q0", "question")

    deck0 = AnkiDeck("deck0")
    deck0.addParameter("deck0", "deck0")
    deck0.addQuestion(q1)

    deck1 = AnkiDeck("deck1")
    deck1.addParameter("deck1", "deck1")
    deck1.addSubdeck(deck0)

    deck2 = AnkiDeck("deck2")
    deck2.addParameter("deck2", "deck2")
    deck2.addParameter("deck1", "deck2")
    deck2.addParameter("deck0", "deck2")
    deck2.addParameter("q0", "deck2")
    deck2.addSubdeck(deck1)

    questions = deck2.getQuestions()
    print(deck2._parameters)

    print(questions[0]._parameters)
    assert (questions[0].getParameter("deck2") == "deck2")
    assert (questions[0].getParameter("deck1") == "deck1")
    assert (questions[0].getParameter("deck0") == "deck0")
    assert (questions[0].getParameter("q0") == "question")
Beispiel #2
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'])
Beispiel #3
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")
Beispiel #4
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>")
Beispiel #5
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"] == "")
Beispiel #6
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>")
Beispiel #7
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)")
Beispiel #8
0
def testQuestionInheritParamsFromDeck():

    q1 = AnkiQuestion("Test question")
    q1.addAnswer("Test Answer")
    q1.addParameter("type", "reversed")

    deck = AnkiDeck("Test Deck")
    deck.addParameter("type1", "basic1")
    deck.addParameter("type", "basic")
    deck.addQuestion(q1)

    questions = deck.getQuestions()

    assert (questions[0].getParameter("type") == "reversed")
    assert (questions[0].getParameter("type1") == "basic1")
Beispiel #9
0
def testCommentsAndParametersForAnkiQuestion():

    q = AnkiQuestion("Test question")
    q.addAnswer("Test Answer")
    q.addTag("test tag")
    q.addComment("Test comment")
    q.addParameter("type", "basic")
    q.addParameter("type1", "basic1")

    assert (q.getAnswers() == ["Test Answer"])
    assert (q.getTags() == ["test tag"])
    assert (q.getComments() == ["Test comment"])
    assert (q.getParameter("type") == "basic")
    assert (q.getParameter("type1") == "basic1")
    assert (q.getParameter("notFound") == None)
Beispiel #10
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>"""
    )
Beispiel #11
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>"
    )
Beispiel #12
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"))
Beispiel #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>"
    )