Skip to content

Commit

Permalink
Fix failing unit tests (#106)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
lauramurgatroyd and pre-commit-ci[bot] authored Nov 24, 2023
1 parent e400a09 commit d476c13
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 47 deletions.
7 changes: 6 additions & 1 deletion eqt/ui/SessionDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ def __init__(self, parent=None, app_name=None):

self.app_name = app_name

if app_name is not None:
app_name_label = ' ' + app_name
else:
app_name_label = ''

label_text = ("Select a session directory to save and retrieve all"
f" {app_name or ''} Sessions:")
f"{app_name_label} Sessions:")

self.addSpanningWidget(QLabel(label_text), 'select_session_directory')

Expand Down
2 changes: 1 addition & 1 deletion test/dialog_example_2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def openFormDialog(self):
# store a reference
self.dialog = dialog

dialog.exec()
dialog.open()

def accepted(self):
print("accepted")
Expand Down
46 changes: 1 addition & 45 deletions test/test_MainWindowWithSessionManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,57 +228,13 @@ def tearDown(self):
shutil.rmtree("Test Folder")


@skip_ci
class TestMainWindowWithSessionManagementCreateLoadSessionDialog(unittest.TestCase):
'''
Tests the createLoadSessionDialog method of the MainWindowWithSessionManagement class
This method is responsible for creating the load session dialog
and populating it with the available sessions
'''
def setUp(self):
self.title = "title"
self.app_name = "app_name"
self.smw = MainWindowWithSessionManagement(self.title, self.app_name)
self.smw.sessions_directory = mock.MagicMock()
self.zip_folders = ["zip_folder_1", "zip_folder_2"]

def test_createLoadSessionDialog_populates_session_dropdown(self):
dialog = self.smw.createLoadSessionDialog(self.zip_folders)
assert dialog is not None
assert isinstance(dialog, eqt.ui.SessionDialogs.LoadSessionDialog)
select_session_combo = dialog.getWidget('select_session')
assert select_session_combo is not None
items_in_combo = [
select_session_combo.itemText(i) for i in range(select_session_combo.count())]
assert items_in_combo == self.zip_folders

def test_createLoadSessionDialog_connections(self):
dialog = self.smw.createLoadSessionDialog(self.zip_folders)

self.smw.loadSessionLoad = mock.MagicMock()
self.smw.selectLoadSessionsDirectorySelectedInSessionSelector = mock.MagicMock()
self.smw.loadSessionNew = mock.MagicMock()

dialog = self.smw.createLoadSessionDialog(self.zip_folders)

dialog.Ok.click()
self.smw.loadSessionLoad.assert_called_once()

dialog.Select.click()
self.smw.selectLoadSessionsDirectorySelectedInSessionSelector.assert_called_with(dialog)

dialog.Cancel.click()
self.smw.loadSessionNew.assert_called_once()


@skip_ci
class TestSelectLoadSessionsDirectorySelectedInSessionSelector(unittest.TestCase):
'''
Tests the `selectLoadSessionsDirectorySelectedInSessionSelector` method of the
`MainWindowWithSessionManagement` class
This method sould close the passed dialog, and call
This method should close the passed dialog, and call
`createSessionsDirectorySelectionDialog(new_session=True)`
'''
def setUp(self):
Expand Down
54 changes: 54 additions & 0 deletions test/test_MainWindowWithSessionManagementDialogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import unittest
from unittest import mock

from eqt.ui.MainWindowWithSessionManagement import MainWindowWithSessionManagement
from eqt.ui.SessionDialogs import LoadSessionDialog

from . import skip_ci

# Unit tests for the MainWindowWithSessionManagement class
# methods which create dialogs


@skip_ci
class TestMainWindowWithSessionManagementCreateLoadSessionDialog(unittest.TestCase):
'''
Tests the createLoadSessionDialog method of the MainWindowWithSessionManagement class
This method is responsible for creating the load session dialog
and populating it with the available sessions
'''
def setUp(self):
self.title = "title"
self.app_name = "app_name"
self.smw = MainWindowWithSessionManagement(self.title, self.app_name)
self.smw.sessions_directory = mock.MagicMock()
self.zip_folders = ["zip_folder_1", "zip_folder_2"]

def test_createLoadSessionDialog_populates_session_dropdown(self):
dialog = self.smw.createLoadSessionDialog(self.zip_folders)
assert dialog is not None
assert isinstance(dialog, LoadSessionDialog)
select_session_combo = dialog.getWidget('select_session')
assert select_session_combo is not None
items_in_combo = [
select_session_combo.itemText(i) for i in range(select_session_combo.count())]
assert items_in_combo == self.zip_folders

def test_createLoadSessionDialog_connections(self):
dialog = self.smw.createLoadSessionDialog(self.zip_folders)

self.smw.loadSessionLoad = mock.MagicMock()
self.smw.selectLoadSessionsDirectorySelectedInSessionSelector = mock.MagicMock()
self.smw.loadSessionNew = mock.MagicMock()

dialog = self.smw.createLoadSessionDialog(self.zip_folders)

dialog.Ok.click()
self.smw.loadSessionLoad.assert_called_once()

dialog.Select.click()
self.smw.selectLoadSessionsDirectorySelectedInSessionSelector.assert_called_with(dialog)

dialog.Cancel.click()
self.smw.loadSessionNew.assert_called_once()

0 comments on commit d476c13

Please sign in to comment.