Exemplo n.º 1
0
def test_set_entry():
    """Test Actions through their implementation in Encyclopaedia."""

    enc = Encyclopaedia()

    for x in range(5):
        e = EncEntry(
            parent=enc,
            name="Test Name",
            text=["Test Text"],
            locked=False
        )

    for x in range(5):
        EncEntry(
            parent=enc,
            name="Test Name",
            text=["Test Text"],
            locked=True
        )

    # Use the last unlocked Entry created for the test.
    enc.SetEntry(e)()

    assert e == enc.active
    assert 4 == enc.current_position
Exemplo n.º 2
0
def test_viewed_callback_change_entry():
    enc = Encyclopaedia()

    e = EncEntry(
        parent=enc,
        name="Test Name",
        text=["Test Text"]
    )

    e2 = EncEntry(
        parent=enc,
        name="Test Name",
        text=["Test Text"]
    )

    global i
    i = 0

    def cb(*args):
        global i
        i += 1

    e2.viewed_callback = (cb,)

    assert 0 == i

    enc.SetEntry(e)()
    assert 0 == i

    enc.NextEntry()()

    assert 1 == i
Exemplo n.º 3
0
def test_next_page():
    enc = Encyclopaedia()

    e = EncEntry(
        parent=enc,
        name="Test Name",
        text=["Test Text"],
    )

    ee = EncEntry(
        parent=e,
        name="Sub1",
        text=["Test Text"],
    )

    eee = EncEntry(
        parent=e,
        name="Sub2",
        text=["Test Text"],
    )

    enc.SetEntry(e)()

    assert e == enc.active
    assert enc.sub_current_position == 1

    enc.NextPage()()

    assert enc.sub_current_position == 2
    assert e.current_page == ee
Exemplo n.º 4
0
def test_set_entry_show_locked_entry():
    """Given an Encyclopaedia with 10 unlocked entries and 5 locked entries,
    And show_locked_entry is true,
    When I set the 10th unlocked entry to be the active entry,
    Then the entry should be marked as viewed,
    And the entry should be the active entry,
    And the Encyclopaedia's current_position should be 14
    """
    enc = Encyclopaedia(show_locked_buttons=False, show_locked_entry=True)

    for x in range(0, 5):
        EncEntry(parent=enc,
                 name="Test Name {}".format(x + 1),
                 text=["Test Text"],
                 locked=False)

    for x in range(5, 10):
        EncEntry(parent=enc,
                 name="Test Name {}".format(x + 1),
                 text=["Test Text"],
                 locked=True)

    for x in range(10, 15):
        e = EncEntry(parent=enc,
                     name="Test Name {}".format(x + 1),
                     text=["Test Text"],
                     locked=False)

    # Use the last unlocked Entry created for the test.
    enc.SetEntry(e)()

    assert e == enc.active
    assert e.viewed
    assert 14 == enc.current_position
Exemplo n.º 5
0
def test_viewed_callback_multiple():
    enc = Encyclopaedia()

    e = EncEntry(parent=enc, name="Test Name", text=["Test Text"])

    global i
    i = 0

    global j
    j = 50

    @e.on("viewed")
    def cb(entry):
        global i
        i += 1

    @e.on("viewed")
    def cb2(entry):
        global j
        j += 10

    assert 0 == i
    assert 50 == j

    enc.SetEntry(e)()

    assert 1 == i
    assert 60 == j
Exemplo n.º 6
0
def test_entry_current_page():
    enc = Encyclopaedia()

    e = EncEntry(
        parent=enc,
        name="Test Name",
        text=["Test Text"],
        locked=False
    )

    enc.SetEntry(e)()

    assert "Page 1 / 1" == enc.labels.entry_current_page
Exemplo n.º 7
0
def test_viewed_callback_set_entry():
    enc = Encyclopaedia()

    e = EncEntry(parent=enc, name="Test Name", text=["Test Text"])

    global i
    i = 0

    @e.on("viewed")
    def cb(entry):
        global i
        i += 1

    assert 0 == i

    enc.SetEntry(e)()

    assert 1 == i