Exemplo n.º 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")
Exemplo n.º 2
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"))
Exemplo n.º 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")
Exemplo n.º 4
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")
Exemplo n.º 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'])
Exemplo n.º 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>")
Exemplo n.º 7
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"] == "")
def testManyMultiLineQuestionLines():

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

    a = AnkiConnector()
    noteData = a._buildNote(deck.getQuestions()[0])

    assert (noteData["fields"]["Front"] ==
            "Capital Cities<br>Capital of dublin <br>Second line <br>")
Exemplo n.º 9
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>")
Exemplo n.º 10
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)")
Exemplo n.º 11
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")
Exemplo n.º 12
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>"""
    )
Exemplo n.º 13
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)
Exemplo n.º 14
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>"
    )
Exemplo n.º 15
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>"
    )
Exemplo n.º 16
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>")
Exemplo n.º 17
0
def testDeckNameSetFor_GetAllDeckQuestion():

    parent = AnkiDeck("parent")
    child = AnkiDeck("child")
    subChild = AnkiDeck("subChild")

    child.addSubdeck(subChild)
    parent.addSubdeck(child)

    # Expected question
    expectedQuestion1 = AnkiQuestion("What is the capital of Ireland")
    expectedQuestion1.addAnswer("Dublin")
    expectedQuestion1.setDeckName("parent")

    expectedQuestion2 = AnkiQuestion("What is the capital of France")
    expectedQuestion2.addAnswer("Paris")
    expectedQuestion2.setDeckName("parent::child")

    expectedQuestion3 = AnkiQuestion("What is the capital of Germany")
    expectedQuestion3.addAnswer("Berlin")
    expectedQuestion3.setDeckName("parent::child::subChild")

    # Add questions
    firstQuestion = AnkiQuestion("What is the capital of Ireland")
    firstQuestion.addAnswer("Dublin")
    parent.addQuestion(firstQuestion)

    secondQuestion = AnkiQuestion("What is the capital of France")
    secondQuestion.addAnswer("Paris")
    child.addQuestion(secondQuestion)

    thirdQuestion = AnkiQuestion("What is the capital of Germany")
    thirdQuestion.addAnswer("Berlin")
    subChild.addQuestion(thirdQuestion)

    # Comprae
    questions = parent.getQuestions()

    assert (questions == [
        expectedQuestion1, expectedQuestion2, expectedQuestion3
    ])