def testSubDeck1HasBasicQuestion(): filename = "tests/testData/topicsLayout.org" actualDeck = parseData.parse(filename) assert(actualDeck.subDecks[1].getQuestions()[0].question == "What are the main languages in Ireland") assert(actualDeck.subDecks[1].getQuestions()[0]._answers == ["English", "Irish"])
def testTopicsDeckHasEachSectionParsedIndependently(): filename = "tests/testData/topicsLayout1.org" actualDeck = parseData.parse(filename) params = {'type': 'basic'} comments = ["#type=basic"] assert (len(actualDeck.subDecks) == 2) assert (actualDeck.subDecks[0]._comments == []) assert (actualDeck.subDecks[0]._parameters == {}) assert (actualDeck.subDecks[1].getQuestions()[0]._comments == [ '# type = basic', '#type=Basic (and reversed card)' ]) assert (actualDeck.subDecks[1].getQuestions()[0]._parameters == { 'type': 'Basic (and reversed card)' }) assert (actualDeck.subDecks[1].getQuestions()[1]._comments == [ '# type = basic' ]) assert (actualDeck.subDecks[1].getQuestions()[1]._parameters == { 'type': 'basic' })
def testOrganisedFlatTopics(): filename = "tests/testData/organisedFlatFile.org" actualDeck = parseData.parse(filename) question1 = actualDeck.getQuestions()[0] assert (question1.getQuestions()[0] == "Systems design primer\nFirst main rule of scalability?") assert (question1.getAnswers()[0] == "Each server behind load balancer") assert (question1.getAnswers()[1] == "Contains same codebase and does not store any user related data") question2 = actualDeck.getQuestions()[1] assert (question2.getQuestions()[0] == "Systems design primer\nWhere should sessions be stored?") assert (question2.getAnswers()[0] == "Centralized data store accessible to servers") question3 = actualDeck.getQuestions()[2] assert ( question3.getQuestions()[0] == "Programming design patterns (online version)\nWhat is the main purpose of the factory pattern? (2)" ) assert ( question3.getAnswers()[0] == "To allow object creation without exposing the creation logic to client" ) assert (question3.getAnswers()[1] == "Allow reference to objects via an interface")
def testBasicWithSublevelsAnswers(): filename = "tests/testData/basicWithSublevels.org" actualDeck = parseData.parse(filename) answers = ['.jar => contains libraries / resources / accessories files', '.war => contain the web application => jsp / html / javascript / other files', ['Need for web apps', ["fourth 1", "fourth 2"], "back to third"]] assert(actualDeck.getQuestions()[0]._answers == answers)
def testBasicParseMainDeckParameters(): filename = "tests/testData/basic.org" actualDeck = parseData.parse(filename) assert(actualDeck._comments == ['# Quick Anki notes', '# listType = bulletPoints']) assert(actualDeck._parameters == {'listType': 'bulletPoints'})
def testTopicsSubDecksNamedCorrectly(): filename = "tests/testData/topicsLayout.org" actualDeck = parseData.parse(filename) assert(actualDeck.subDecks[0].deckName == "Capital cites") assert(actualDeck.subDecks[1].deckName == "Languages of countries")
def testMainDeckHasComment(): filename = "tests/testData/topicsLayout.org" actualDeck = parseData.parse(filename) comments = ['# More advanced org file layout. Each topics has its own questions.', '#fileType = topics'] assert(actualDeck._comments == comments)
def testMainDeckHasParameters(): filename = "tests/testData/topicsLayout.org" actualDeck = parseData.parse(filename) params = {'fileType': 'topics'} assert(actualDeck._parameters == params)
def testImageWithSize_url(): filename = "tests/testData/image_url.org" actualDeck = parseData.parse(os.path.abspath(filename)) # Test that comments are removed from the line assert ("#" not in actualDeck.getQuestions()[0].getAnswers()[0])
def testNotesTypeSection(): ## Note section should be ignored as they define notes that are not anki questions filename = "tests/testData/noteTypes.org" actualDeck = parseData.parse(filename) # assert(actualDeck.getQuestions()[0].getParameter("type") == "notes") assert (len(actualDeck.getQuestions()) == 0)
def testSubDeck1HasParamters(): filename = "tests/testData/topicsLayout.org" actualDeck = parseData.parse(filename) params = {'type': 'basic'} comments = ["#type=basic"] assert(actualDeck.subDecks[1]._comments == comments) assert(actualDeck.subDecks[1]._parameters == params)
def testImageWithSize(): filename = "tests/testData/image.org" actualDeck = parseData.parse(os.path.abspath(filename)) assert ('<img src="image.png" style="' in actualDeck.getQuestions()[2].getAnswers()[0]) assert ('width:100px;' in actualDeck.getQuestions()[2].getAnswers()[0]) assert ('height:100px;' in actualDeck.getQuestions()[2].getAnswers()[0])
def testSubDeck1QuestionHasParamters(): filename = "tests/testData/topicsLayout.org" actualDeck = parseData.parse(filename) params = {'type': 'reverse'} comments = ["#type=reverse"] assert(actualDeck.subDecks[1].getQuestions()[0]._parameters == params) assert(actualDeck.subDecks[1].getQuestions()[0]._comments == comments)
def testBasicParseQuestionsHaveParametersAndParameters(): filename = "tests/testData/basic.org" actualDeck = parseData.parse(filename) params = {'other': 'test', 'listType': 'bulletPoints'} # List type if inherited from parent deck comments = ['# other=test'] assert(actualDeck.getQuestions()[0]._parameters == params) assert(actualDeck.getQuestions()[0]._comments == comments)
def testBaiscPraseQuestsion(): filename = "tests/testData/basic.org" actualDeck = parseData.parse(filename) assert (actualDeck.getQuestions()[0].question[0] == "Put request") assert (actualDeck.getQuestions()[0].getAnswers() == [ "Puts file / resource at specific url", "If file ==> exists => replaces // !exist => creates", "Request => idempotent" ])
def testMultipleSubListsBug(): filename = "tests/testData/missingListLevel.org" actualDeck = parseData.parse(filename) print(actualDeck.getQuestions()[0].getAnswers()) # Assert that a deck is built assert(actualDeck) # TODO generate correctly formated strange list assert(actualDeck.getQuestions()[0].getAnswers() == ['Level 3A Answer', ['level 2B answer'], 'Level 3B Answer'])
def testParseCodeIsFormatted(): filename = "tests/testData/codeQuestion.org" actualDeck = parseData.parse(filename) questions = actualDeck.getQuestions() print(questions[0].getAnswers()[1]) assert(questions[0].getAnswers()[1] == """<div style="text-align:left"> <div class="highlight" style="background: #ffffff"><pre style="line-height: 125%"><span></span><span style="color: #008800; font-weight: bold">print</span>(<span style="background-color: #fff0f0">"hello world"</span>)<br></pre></div> </div>""") assert(questions[1].getAnswers()[0] == """<div style="text-align:left"> <div class="highlight" style="background: #ffffff"><pre style="line-height: 125%"><span></span><span style="color: #008800; font-weight: bold">if</span> (this):<br> <span style="color: #008800; font-weight: bold">print</span>(<span style="background-color: #fff0f0">"worked"</span>)<br></pre></div> </div>""")
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 testParseCodeInBackQuotes(): filename = "tests/testData/codeQuestion.org" actualDeck = parseData.parse(filename) questions = actualDeck.getQuestions() assert(questions[0].getCodeLanguage() == "python") assert(questions[0].getCodeSection() == ["print(\"hello world\")"]) assert(questions[1].getCodeLanguage() == "python") assert(questions[1].getCodeSection() == ["if (this):", " print(\"worked\")"])
def testOrganisedTopics(): filename = "tests/testData/organisedFile.org" actualDeck = parseData.parse(filename) question1 = actualDeck.getQuestions()[0] assert(question1.getQuestions()[0] == "First main rule of scalability?") assert(question1.getAnswers()[0] == "Each server behind load balancer") question2 = actualDeck.getQuestions()[1] assert(question2.getQuestions()[0] == "What is the main purpose of the factory pattern?") assert(question2.getAnswers()[0] == "Allow reference to objects via an interface")
def testParsingUnicodeCharacters(): # data = ['* Hello world in Chinese?', '** 你好'] # deck = parseData._buildDeck(data, "test.org") filename = "tests/testData/unicode.org" actualDeck = parseData.parse(filename) print(actualDeck.getQuestions()[0]) question = actualDeck.getQuestions()[0] assert (question.getQuestions()[0] == "Hello world in Chinese?") assert (question.getAnswers()[0] == "你好")
def testBulletPointDocsAreHandeledBy_parseData(): libreOfficeFile = "tests/testData/documents/bulletpoint-doc-libreOffice-osx.html" libreDeck = parse(libreOfficeFile) assert (libreDeck.getQuestions()[0].getQuestions()[0] == "What is the capital of Ireland") assert (libreDeck.getQuestions()[0].getAnswers()[0] == "Dublin") wordWindowsFile = "tests/testData/documents/bulletpoint-doc-word-windows.htm" windowsWordDeck = parse(wordWindowsFile) assert (windowsWordDeck.getQuestions()[0].getQuestions()[0] == "What is the capital of Ireland") assert (windowsWordDeck.getQuestions()[0].getAnswers()[0] == "Dublin") wordOsxFile = "tests/testData/documents/bulletpoint-doc-word-osx.html" osxWordDeck = parse(wordOsxFile) assert (osxWordDeck.getQuestions()[0].getQuestions()[0] == "What is the capital of Ireland") assert (osxWordDeck.getQuestions()[0].getAnswers()[0] == "Dublin")
def testImageTagCorrectProccesed(): filename = "tests/testData/image.org" actualDeck = parseData.parse(os.path.abspath(filename)) imageFile = "tests/testData/imageFolder/image.png" fullImagePath = os.path.abspath(imageFile) with open(fullImagePath, 'rb') as data: mediaItem = AnkiQuestionMedia("image", "image.png", data.read()) assert(actualDeck.getQuestions()[0].getAnswers()[1] == '<img src="image.png" />') assert(mediaItem == actualDeck.getMedia()[0])
def testImageCorrectlyUploaded(): filename = "tests/testData/image.org" actualDeck = parseData.parse(os.path.abspath(filename)) imageFile = "tests/testData/imageFolder/image.png" fullImagePath = os.path.abspath(imageFile) a = AnkiConnector() preparedMedia = a.prepareMedia(actualDeck.getMedia()) assert (preparedMedia[0].get('fileName') == "image.png") with open(fullImagePath, 'rb') as data: encodedImage = base64.b64encode(data.read()).decode("utf-8") assert (preparedMedia[0].get("data") == encodedImage)
def testParsingClozeQuestions(): filename = "tests/testData/cloze.org" actualDeck = parseData.parse(filename) assert(len(actualDeck.getQuestions()) == 4) assert(actualDeck.getQuestions()[0].getQuestions() == ["When was Dublin founded {{c1::1204}}"]) assert(actualDeck.getQuestions()[0].getAnswers() == ["Some extra info"]) assert(actualDeck.getQuestions()[0].getParameter("type") == "Cloze") # Check can form Cloze card without answer assert(actualDeck.getQuestions()[1].getQuestions() == ["When was Dublin founded {{c1::1204}}"]) assert(actualDeck.getQuestions()[1].getAnswers() == []) # Check that 4th questions is not affect by previous cloze types assert(actualDeck.getQuestions()[3].getQuestions() == ["Normal Question"])
def testFlatTopics(): filename = "tests/testData/flatTopics.org" actualDeck = parseData.parse(filename) question1 = actualDeck.getQuestions()[0] assert(question1.getQuestions()[0] == "Capital cites\nWhat is the capital of Ireland") assert(question1.getAnswers()[0] == "Dublin") question2 = actualDeck.getQuestions()[1] assert(question2.getQuestions()[0] == "Capital cites\nWhat is the capital of Germany") assert(question2.getAnswers()[0] == "Berlin") question3 = actualDeck.getQuestions()[2] assert(question3.getQuestions()[0] == "Languages of countries\nWhat is the main languages in Ireland") assert(question3.getAnswers()[0] == "Irish") question4 = actualDeck.getQuestions()[3] assert(question4.getQuestions()[0] == "Languages of countries\nWhat is the main languages in Germany") assert(question4.getAnswers()[0] == "German")
def testImagesAreLazyLoad(): # Set config config.lazyLoadImages = True try: filename = "tests/testData/image_url.org" actualDeck = parseData.parse(os.path.abspath(filename)) assert (actualDeck.getMedia()[0].lazyLoad == True) assert (actualDeck.getMedia()[0].data == None) # Test image can still be loaded actualDeck.getMedia()[0].lazyLoadImage() assert (actualDeck.getMedia()[0].lazyLoad == False) assert (actualDeck.getMedia()[0].data != None) finally: # Revert config to default config.lazyLoadImages = False
def testTopicsDeckNamedCorrectly(): filename = "tests/testData/topicsLayout.org" actualDeck = parseData.parse(filename) assert(actualDeck.deckName == "topicsLayout")
def testFileWithNoQuestions(): filename = "tests/testData/empty.org" actualDeck = parseData.parse(filename) assert (len(actualDeck.getQuestions()) == 0)
def testBasicPraseNamedCorrectly(): filename = "tests/testData/basic.org" actualDeck = parseData.parse(filename) assert(actualDeck.deckName == "basic")