Beispiel #1
0
def testSubDeck0HasBasicQuestion():

    filename = "tests/testData/topicsLayout.org"
    actualDeck = parseData.parse(filename)

    q1 = AnkiQuestion("What is the capital of Ireland")
    q1.addAnswer("Dublin")
    q1.deckName = "Capital cites"

    assert(actualDeck.subDecks[0].getQuestions()[0].question == "What is the capital of Ireland")
    assert(actualDeck.subDecks[0].getQuestions()[0]._answers == ["Dublin"])
Beispiel #2
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")
Beispiel #3
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'])
def testAddImageForAnkiQuestion():

    fullImagePath = os.path.abspath("tests/testData/imageFolder/image.png")

    deck = AnkiDeck("Test deck")
    question = AnkiQuestion("test question")
    deck.addQuestion(question)
    question.addImage("image.png", fullImagePath)

    with open(fullImagePath, 'rb') as data:
        mediaItem = AnkiQuestionMedia("image", "image.png", data.read())

    assert(mediaItem == question.getMedia()[0])
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"] == "")
def testCreationOfNamedNoteFieldWithinAnkiQuestion():

    a = AnkiQuestion("question")
    a.addAnswer("answer")

    a.addNoteField("testField")
    a.addLineToNamedField("testField", "data")

    namedFields = a.getNamedFields()

    namedFields = a.getNamedFields()
    n = NamedNoteField("testField")
    n.addLine("data")
    assert (namedFields[0] == n)
Beispiel #7
0
def testCodeQuestionBuildsWithListSection():

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

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

    print(noteData["fields"]["Back"])

    assert (
        noteData["fields"]["Back"] ==
        """<ul style='list-style-position: inside;'><li><div style="text-align:left"> <div class="highlight" style="background: #ffffff"><pre style="line-height: 125%"><span></span><span style="color: #007020">print</span>(<span style="background-color: #fff0f0">&#39;Hello&#39;</span>)<br></pre></div> </div></li></ul>"""
    )
Beispiel #8
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>")
Beispiel #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>")
Beispiel #10
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 #11
0
def testMultipleNamedNoteField():

    a = AnkiQuestion("question")
    a.addAnswer("answer")

    a.addLineToNamedField("testField", "data")
    a.addLineToNamedField("testField1", "data1")
    namedFields = a.getNamedFields()

    # No guarantee of ordering
    if namedFields[0].getFieldName() == "testField":
        a, b = 0, 1
    else:
        a, b = 1, 0

    assert (namedFields[a].getFieldName() == "testField")
    assert (namedFields[a].getLines() == ["data"])
    assert (namedFields[b].getFieldName() == "testField1")
    assert (namedFields[b].getLines() == ["data1"])
def testMultiLineQuestion():

    data = ["* Question line 1","* Question line 2","** Answer"]
    deckBuilder = DeckBuilder()
    deck = deckBuilder.buildDeck(data, "test Deck", "")

    expectedQuestion = AnkiQuestion()
    q1 = AnkiQuestion("What is the capital of Ireland")
    expectedQuestion.addQuestion("Question line 1")
    expectedQuestion.addQuestion("Question line 2")
    expectedQuestion.addAnswer("Answer")

    assert(deck.getQuestions()[0].question == expectedQuestion.question)
    assert(deck.getQuestions()[0]._answers == expectedQuestion._answers)
Beispiel #13
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")
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>")
Beispiel #15
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 #16
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 #17
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 #18
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)
Beispiel #19
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 #20
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 #21
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>"
    )
Beispiel #22
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 #23
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
    ])