Exemple #1
0
def test_08_display_ListWindow_update():
    createdListWindow = ListWindow(100, 100, {"Title": "List"}, 3,
                                   ("Column1", "Column2", "Column3"))
    createdListWindow.setHeader()
    with pytest.raises(TypeError):
        createdListWindow.update("NotATuple")
    with pytest.raises(TypeError):
        createdListWindow.update(["NotATuple"])
    with pytest.raises(ValueError):
        createdListWindow.update(("1", "2", "3", "4"))
    with pytest.raises(ValueError):
        createdListWindow.update(("1", "2"))
    createdListWindow.lines = []
    entry1 = ("Entry1,1", "Entry1,2", "Entry1,3")
    createdListWindow.update(entry1)
    assert entry1 == createdListWindow.lines[0]
    entry2 = ("Entry2,1", "Entry2,2", "Entry2,3")
    entry3 = ("Entry3,1", "Entry3,2", "Entry3,3")
    createdListWindow.update([entry2, entry3])
    assert entry2 == createdListWindow.lines[1]
    assert entry3 == createdListWindow.lines[2]
Exemple #2
0
def test_16_display_ListWindow_fillEmpty_afterTableDraw(capsys, height):
    """
    This test is used to varify
    """
    def mock_input(s):
        return s + " (mocked)"

    createdListWindow = ListWindow(height, 100, {"Title": "List"}, 3,
                                   ("Column1", "Column2", "Column3"))
    createdListWindow.setHeader()
    createdListWindow.makeheader()
    headerLines = createdListWindow.header
    tableEntries = []
    tableEntries2 = []
    for i in range(5):
        tableEntries.append(("Entry" + str(i) + ",1", "Entry" + str(i) + ",2",
                             "Entry" + str(i) + ",3"))
        tableEntries2.append(
            ("SecEntry" + str(i) + ",1", "SecEntry" + str(i) + ",2",
             "SecEntry" + str(i) + ",3"))
    createdListWindow.update(tableEntries)
    tableLines = createdListWindow.makeTable(
        createdListWindow.tableHeaderElements, createdListWindow.lines,
        createdListWindow.tableMaxLen)
    createdListWindow.draw(fillWindow=True)
    captured = capsys.readouterr()
    # -1 because there is one empty element after the split
    assert len(captured.out.split("\n")) - 1 == height

    # for iline, line in enumerate(captured.out.split("\n")):
    #     print(iline, "a ",line)
    # captured = capsys.readouterr()
    display.input = mock_input
    createdListWindow.interact("Requesting input", None, onlyInteraction=True)
    createdListWindow.lines = []
    createdListWindow.update(tableEntries2)
    tableLines2 = createdListWindow.makeTable(
        createdListWindow.tableHeaderElements, createdListWindow.lines,
        createdListWindow.tableMaxLen)
    createdListWindow.draw(fillWindow=True)

    captured = capsys.readouterr()
    assert len(captured.out.split("\n")) - 1 == height
    # for iline, line in enumerate(captured.out.split("\n")):
    #     print("{0:2}".format(iline), "b",line)

    #Build expectation
    lineIdentifiers = 3 * (list(string.ascii_lowercase) +
                           list(string.ascii_uppercase) + list(range(10)))
    leftAlignTableLines = []
    for line in tableLines:
        lineLen = len(line)
        leftAlignTableLines.append(" " + line + " " +
                                   (createdListWindow.boxWidth - lineLen) *
                                   " ")
    leftAlignTableLines2 = []
    for line in tableLines2:
        lineLen = len(line)
        leftAlignTableLines2.append(" " + line + " " +
                                    (createdListWindow.boxWidth - lineLen) *
                                    " ")

    interactionStr = "" + mock_input("Requesting input: Requesting input: ")
    interaction = [interactionStr + " " * (100 - len(interactionStr))]

    blankLines = (height - len(headerLines) - len(leftAlignTableLines) -
                  len(leftAlignTableLines2) - 1) * [100 * " "]

    expectedLines = []
    for iline, line in enumerate(headerLines + blankLines +
                                 leftAlignTableLines + interaction +
                                 leftAlignTableLines2):
        expectedLines.append(line.replace(" ", lineIdentifiers[iline]))

    modCapturedLines = []
    for iline, line in enumerate(captured.out.split("\n")):
        if line != "":
            modCapturedLines.append(
                line.replace(" ", str(lineIdentifiers[iline])))

    ####################################################################################
    print(
        "/////////////////////////////// EXPECTATION /////////////////////////////////////"
    )
    for line in expectedLines:
        print(line)
    print(
        "///////////////////////////////// RETURN ////////////////////////////////////////"
    )
    for line in modCapturedLines:
        print(line)
    ####################################################################################
    assert len(expectedLines) == len(modCapturedLines)
    for iline in range(len(modCapturedLines)):
        assert modCapturedLines[iline] == expectedLines[iline]