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")
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"])
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")
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 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>")
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>")
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>")
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)
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)
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)")
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")
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)
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)
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>" )
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"))
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>" )
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>")
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 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 ])