Skip to content

Commit

Permalink
TST: add window tree_view manipulation test
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong committed Jul 26, 2024
1 parent 753aa95 commit f52a53a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions superscore/tests/test_window.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
from uuid import UUID

from pytestqt.qtbot import QtBot

from superscore.client import Client
from superscore.widgets.window import Window


def count_visible_items(tree_view):
count = 0
index = tree_view.model().index(0, 0)
while index.isValid():
count += 1
print(type(index.internalPointer()._data).__name__)
index = tree_view.indexBelow(index)
return count


def test_main_window(qtbot: QtBot, mock_client: Client):
"""Pass if main window opens successfully"""
window = Window(client=mock_client)
qtbot.addWidget(window)


def test_sample_window(qtbot: QtBot, sample_client: Client):
window = Window(client=sample_client)
qtbot.addWidget(window)

assert count_visible_items(window.tree_view) == 4

def get_last_index(index):
curr_index = index
while curr_index.isValid():
new_index = window.tree_view.indexBelow(curr_index)
if not new_index.isValid():
break
curr_index = new_index
return curr_index

first_index = window.tree_view.model().index(0, 0)
last_index = get_last_index(first_index)
window.tree_view.expand(last_index)

assert count_visible_items(window.tree_view) == 7

# get new last index after expansion, and signal view has been updated
new_last_index = get_last_index(first_index)
window.tree_view.dataChanged(first_index, new_last_index)

# check that all exposed entries have been filled
index = first_index
while index.isValid():
assert not isinstance(index.internalPointer()._data, UUID)
index = window.tree_view.indexBelow(index)

0 comments on commit f52a53a

Please sign in to comment.