def test_unlock_callback():
    enc = Encyclopaedia()

    global baz
    baz = 0

    def foobar():
        global baz
        baz += 1

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

    enc.unlock_callback = foobar

    # Unlock the first entry
    e.locked = False
    assert e.locked is False

    assert 1 == baz
def test_percentage_unlocked():
    """Base unit test for the
    Encyclopaedia.percentage_unlocked property.
    """

    enc = Encyclopaedia()

    for x in range(5):
        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
        )

    assert 50.00 == enc.percentage_unlocked
Esempio n. 3
0
def test_reset_sub_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()()
    enc.NextPage()()

    assert enc.sub_current_position == 3
    assert e.current_page == eee

    enc.ResetSubPage()()

    assert enc.sub_current_position == 1
    assert e.current_page == e
Esempio n. 4
0
def test_setting_entry_number():
    """
    When some entries have a pre-determined number,
    And some do not,
    Then the ones that do not should select the first available number.
    """

    enc = Encyclopaedia()

    EncEntry(
        parent=enc,
        number=4,
        name="Apple",
        text=["Test Text"],
    )

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

    assert 6 == e.number
def test_viewed_persistent_get():
    """When viewed status is controlled by a persistent variable
    Then the EncEntry's viewed attribute should be linked to a persistent
    variable.
    """
    enc = Encyclopaedia()

    about_zeus = EncEntry(
        parent=enc,
        name="Zeus",
        text=["Test Text"],
        viewed_persistent=True,
    )

    assert about_zeus.viewed == persistent.Zeus_viewed
Esempio n. 6
0
def test_entry_current_page_closed_page():
    enc = Encyclopaedia()

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

    with pytest.raises(AttributeError) as e:
        enc.labels.entry_current_page

    message = "Cannot display Entry's current page when no entry is open."
    assert message == str(e.value)
Esempio n. 7
0
def test_sort_encyclopaeda():
    """Test Actions through their implementation in Encyclopaedia."""

    enc = Encyclopaedia()

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

    enc.Sort(sorting_mode=Encyclopaedia.SORT_SUBJECT)()

    assert Encyclopaedia.SORT_SUBJECT == enc.sorting_mode
Esempio n. 8
0
def test_toggle_show_locked_entry():
    """Test Actions through their implementation in Encyclopaedia."""

    enc = Encyclopaedia()

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

    enc.ToggleShowLockedEntry()()

    assert True is enc.show_locked_entry
Esempio n. 9
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
Esempio n. 10
0
def test_next_entry():
    """Test Actions through their implementation in Encyclopaedia."""

    enc = Encyclopaedia()

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

    assert 0 == enc.current_position

    enc.NextEntry()()

    assert enc.current_entries[1] == enc.active
    assert enc.current_entries[1].viewed
    assert 1 == enc.current_position
Esempio n. 11
0
def test_sorting_mode_label():
    enc = Encyclopaedia()

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

    assert "Number" == enc.labels.sorting_mode

    enc.Sort(Encyclopaedia.SORT_ALPHABETICAL)()
    assert "A to Z" == enc.labels.sorting_mode

    enc.Sort(Encyclopaedia.SORT_REVERSE_ALPHABETICAL)()
    assert "Z to A" == enc.labels.sorting_mode

    enc.Sort(Encyclopaedia.SORT_SUBJECT)()
    assert "Subject" == enc.labels.sorting_mode

    enc.Sort(Encyclopaedia.SORT_UNREAD)()
    assert "Unread" == enc.labels.sorting_mode