예제 #1
0
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"])
예제 #2
0
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'
    })
예제 #3
0
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")
예제 #4
0
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)
예제 #5
0
def testBasicParseMainDeckParameters():

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

    assert(actualDeck._comments == ['# Quick Anki notes', '# listType = bulletPoints'])
    assert(actualDeck._parameters == {'listType': 'bulletPoints'})
예제 #6
0
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")
예제 #7
0
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)
예제 #8
0
def testMainDeckHasParameters():

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

    params = {'fileType': 'topics'}
    assert(actualDeck._parameters == params)
예제 #9
0
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)
예제 #11
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)
예제 #12
0
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])
예제 #13
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)
예제 #14
0
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)
예제 #15
0
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"
    ])
예제 #16
0
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'])
예제 #17
0
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">&quot;hello world&quot;</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">&quot;worked&quot;</span>)<br></pre></div> </div>""")
예제 #18
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"])
예제 #19
0
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\")"])
예제 #20
0
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")
예제 #21
0
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")
예제 #23
0
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])
예제 #24
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)
예제 #25
0
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"])
예제 #26
0
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")
예제 #27
0
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
예제 #28
0
def testTopicsDeckNamedCorrectly():

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

    assert(actualDeck.deckName == "topicsLayout")
예제 #29
0
def testFileWithNoQuestions():

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

    assert (len(actualDeck.getQuestions()) == 0)
예제 #30
0
def testBasicPraseNamedCorrectly():

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

    assert(actualDeck.deckName == "basic")