Skip to content

Commit

Permalink
tests: Update for PortfolioFiles refactoring
Browse files Browse the repository at this point in the history
This is just a minimal port of these tests. Long-term these tests
should be split in two, one for window navigation and another for
files viewer specifics.

Closes #290
  • Loading branch information
tchx84 committed Aug 9, 2023
1 parent d7d7726 commit 11f7fed
Showing 1 changed file with 63 additions and 61 deletions.
124 changes: 63 additions & 61 deletions tests/window.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,83 +69,85 @@ def test_create_window():

def test_load_all():
# should list only "folder" and "file"
assert len(window.sorted) == 2
assert window.sorted[0][window.PATH_COLUMN] == TEST_HOME_FOLDER
assert window.sorted[1][window.PATH_COLUMN] == TEST_HOME_FILE
assert len(window.files.sorted) == 2
assert window.files.sorted[0][window.files.PATH_COLUMN] == TEST_HOME_FOLDER
assert window.files.sorted[1][window.files.PATH_COLUMN] == TEST_HOME_FILE


def test_default_selection():
# nothing should be selected by default
_, treepaths = window.selection.get_selected_rows()
_, treepaths = window.files.selection.get_selected_rows()

assert len(treepaths) == 0


def test_select_all():
# "folder" and "file" should be selected
window._switch_to_selection_mode()
window._select_all()
window.files.switch_to_selection_mode()
window.files.select_all()
update_gtk()
model, treepaths = window.selection.get_selected_rows()
model, treepaths = window.files.selection.get_selected_rows()

assert len(treepaths) == 2
assert model[treepaths[0]][window.PATH_COLUMN] == TEST_HOME_FOLDER
assert model[treepaths[1]][window.PATH_COLUMN] == TEST_HOME_FILE
assert model[treepaths[0]][window.files.PATH_COLUMN] == TEST_HOME_FOLDER
assert model[treepaths[1]][window.files.PATH_COLUMN] == TEST_HOME_FILE


def test_unselect_all():
# nothing should be selected
window._switch_to_selection_mode()
window._unselect_all()
window.files.switch_to_selection_mode()
window.files.unselect_all()
update_gtk()
_, treepaths = window.selection.get_selected_rows()
_, treepaths = window.files.selection.get_selected_rows()

assert len(treepaths) == 0


def test_new_folder():
# "New Folder" should be created and selected
window._unselect_all()
window.files.unselect_all()
update_gtk()
window._on_new_folder(None)
model, treepaths = window.selection.get_selected_rows()
model, treepaths = window.files.selection.get_selected_rows()

assert len(window.sorted) == 3
assert model[0][window.PATH_COLUMN] == TEST_HOME_FOLDER
assert model[1][window.PATH_COLUMN] == os.path.join(TEST_HOME_DIR, TEST_NEW_FOLDER)
assert model[2][window.PATH_COLUMN] == TEST_HOME_FILE
assert len(window.files.sorted) == 3
assert model[0][window.files.PATH_COLUMN] == TEST_HOME_FOLDER
assert model[1][window.files.PATH_COLUMN] == os.path.join(
TEST_HOME_DIR, TEST_NEW_FOLDER
)
assert model[2][window.files.PATH_COLUMN] == TEST_HOME_FILE
assert len(treepaths) == 1
assert model[treepaths[0]][window.PATH_COLUMN] == os.path.join(
assert model[treepaths[0]][window.files.PATH_COLUMN] == os.path.join(
TEST_HOME_DIR, TEST_NEW_FOLDER
)


def test_open_folder():
# "New Folder" should be opened and must be empty
window._unselect_all()
window._on_row_activated(None, 1, None, None)
window.files.unselect_all()
window.files._on_row_activated(None, 1, None, None)
update_gtk()

assert len(window.sorted) == 0
assert len(window.files.sorted) == 0


def test_navigation_previous():
# go back to "folder"
window._on_go_previous(None)
update_gtk()

assert len(window.sorted) == 3
assert window.sorted[0][window.PATH_COLUMN] == TEST_HOME_FOLDER
assert window.sorted[1][window.PATH_COLUMN] == os.path.join(
assert len(window.files.sorted) == 3
assert window.files.sorted[0][window.files.PATH_COLUMN] == TEST_HOME_FOLDER
assert window.files.sorted[1][window.files.PATH_COLUMN] == os.path.join(
TEST_HOME_DIR, TEST_NEW_FOLDER
)
assert window.sorted[2][window.PATH_COLUMN] == TEST_HOME_FILE
assert window.files.sorted[2][window.files.PATH_COLUMN] == TEST_HOME_FILE


def test_copy():
# "file" should be selected and copied
window._switch_to_selection_mode()
window._select_row(window.sorted[2].iter)
window.files.switch_to_selection_mode()
window.files._select_row(window.files.sorted[2].iter)
window._on_copy_clicked(None)

assert len(window._to_copy) == 1
Expand All @@ -157,7 +159,7 @@ def test_navigation_next():
window._on_go_next(None)
update_gtk()

assert len(window.sorted) == 0
assert len(window.files.sorted) == 0


def test_copy_paste():
Expand All @@ -166,17 +168,17 @@ def test_copy_paste():
window._worker.join()
update_gtk()

assert len(window.sorted) == 1
assert window.sorted[0][window.PATH_COLUMN] == os.path.join(
assert len(window.files.sorted) == 1
assert window.files.sorted[0][window.files.PATH_COLUMN] == os.path.join(
TEST_HOME_DIR, TEST_NEW_FOLDER, TEST_NEW_FILE
)


@pytest.mark.timeout(5)
def test_delete_all():
# select all and delete, nothing should remain
window._switch_to_selection_mode()
window._select_all()
window.files.switch_to_selection_mode()
window.files.select_all()
window._on_delete_clicked(None)

update_gtk()
Expand All @@ -196,26 +198,26 @@ def test_delete_all():

update_gtk()

assert len(window.sorted) == 0
assert len(window.files.sorted) == 0


def test_original_file_untouched():
# go to "folder" and the original "file" is intact
window._on_go_previous(None)
update_gtk()

assert len(window.sorted) == 3
assert window.sorted[0][window.PATH_COLUMN] == TEST_HOME_FOLDER
assert window.sorted[1][window.PATH_COLUMN] == os.path.join(
assert len(window.files.sorted) == 3
assert window.files.sorted[0][window.files.PATH_COLUMN] == TEST_HOME_FOLDER
assert window.files.sorted[1][window.files.PATH_COLUMN] == os.path.join(
TEST_HOME_DIR, TEST_NEW_FOLDER
)
assert window.sorted[2][window.PATH_COLUMN] == TEST_HOME_FILE
assert window.files.sorted[2][window.files.PATH_COLUMN] == TEST_HOME_FILE


def test_cut():
# "New Folder" is selected and cut
window._switch_to_selection_mode()
window._select_row(window.sorted[1].iter)
window.files.switch_to_selection_mode()
window.files._select_row(window.files.sorted[1].iter)
window._on_cut_clicked(None)

assert len(window._to_cut) == 1
Expand All @@ -224,40 +226,40 @@ def test_cut():

def test_cut_paste():
# go to "folder" and paste "New Folder"
window._unselect_all()
window._on_row_activated(None, 0, None, None)
window.files.unselect_all()
window.files._on_row_activated(None, 0, None, None)
update_gtk()
window._on_paste_clicked(None)
window._worker.join()
update_gtk()

assert len(window.sorted) == 2
assert window.sorted[0][window.PATH_COLUMN] == os.path.join(
assert len(window.files.sorted) == 2
assert window.files.sorted[0][window.files.PATH_COLUMN] == os.path.join(
TEST_HOME_FOLDER, TEST_NEW_FOLDER
)
assert window.sorted[1][window.PATH_COLUMN] == TEST_HOME_SUB_FILE
assert window.files.sorted[1][window.files.PATH_COLUMN] == TEST_HOME_SUB_FILE


def test_rename():
window._switch_to_selection_mode()
window._select_row(window.sorted[0].iter)
window.files.switch_to_selection_mode()
window.files._select_row(window.files.sorted[0].iter)
window.rename.emit("clicked")
update_gtk()

window.name_cell.emit("edited", 0, TEST_NEW_FOLDER_RENAMED)
window.files.name_cell.emit("edited", 0, TEST_NEW_FOLDER_RENAMED)
update_gtk()

model, treepaths = window.selection.get_selected_rows()
assert model[treepaths[0]][window.PATH_COLUMN] == os.path.join(
model, treepaths = window.files.selection.get_selected_rows()
assert model[treepaths[0]][window.files.PATH_COLUMN] == os.path.join(
TEST_HOME_FOLDER, TEST_NEW_FOLDER_RENAMED
)


@pytest.mark.timeout(5)
def test_delete_one():
# select "Renamed" folder and delete it
window._switch_to_selection_mode()
window._select_row(window.sorted[0].iter)
window.files.switch_to_selection_mode()
window.files._select_row(window.files.sorted[0].iter)
window._on_delete_clicked(None)

update_gtk()
Expand All @@ -277,26 +279,26 @@ def test_delete_one():

update_gtk()

assert len(window.sorted) == 1
assert window.sorted[0][window.PATH_COLUMN] == TEST_HOME_SUB_FILE
assert len(window.files.sorted) == 1
assert window.files.sorted[0][window.files.PATH_COLUMN] == TEST_HOME_SUB_FILE


def test_new_folder_gone():
# "New Folder" must be gone
window._on_go_previous(None)
update_gtk()

assert len(window.sorted) == 2
assert window.sorted[0][window.PATH_COLUMN] == TEST_HOME_FOLDER
assert window.sorted[1][window.PATH_COLUMN] == TEST_HOME_FILE
assert len(window.files.sorted) == 2
assert window.files.sorted[0][window.files.PATH_COLUMN] == TEST_HOME_FOLDER
assert window.files.sorted[1][window.files.PATH_COLUMN] == TEST_HOME_FILE


def test_open_file():
window.open(TEST_HOME_SUB_FILE)
update_gtk()

assert len(window.sorted) == 1
assert window.sorted[0][window.PATH_COLUMN] == TEST_HOME_SUB_FILE
assert len(window.files.sorted) == 1
assert window.files.sorted[0][window.files.PATH_COLUMN] == TEST_HOME_SUB_FILE

model, treepaths = window.selection.get_selected_rows()
assert model[treepaths[0]][window.PATH_COLUMN] == TEST_HOME_SUB_FILE
model, treepaths = window.files.selection.get_selected_rows()
assert model[treepaths[0]][window.files.PATH_COLUMN] == TEST_HOME_SUB_FILE

0 comments on commit 11f7fed

Please sign in to comment.