-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST: add window tree_view manipulation test
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |