-
Notifications
You must be signed in to change notification settings - Fork 70
test: add pytest-qt GUI tests #1132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
andychoquette
wants to merge
1
commit into
aws-deadline:mainline
Choose a base branch
from
andychoquette:chore/add-automated-ui-tests
base: mainline
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
|
||
| """Shared fixtures for pytest-qt GUI tests.""" | ||
|
|
||
| import importlib.util | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
| # Load MockDeadlineBackend by file path to avoid sys.path pollution | ||
| # (the test/unit/deadline_client/dataclasses/ package would shadow stdlib). | ||
| _mock_path = os.path.join( | ||
| os.path.dirname(__file__), | ||
| "..", | ||
| "unit", | ||
| "deadline_client", | ||
| "mock_deadline_backend.py", | ||
| ) | ||
| _spec = importlib.util.spec_from_file_location("mock_deadline_backend", os.path.abspath(_mock_path)) | ||
| assert _spec and _spec.loader | ||
| _mod = importlib.util.module_from_spec(_spec) | ||
| _spec.loader.exec_module(_mod) | ||
| MockDeadlineBackend = _mod.MockDeadlineBackend | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_deadline_backend(): | ||
| """Provide a fresh MockDeadlineBackend instance.""" | ||
| return MockDeadlineBackend(validate_params=False) |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
|
||
| """ | ||
| pytest-qt proof-of-concept: GUI submitter bundle tests. | ||
|
|
||
| This is a pytest-qt equivalent of the Squish tst_verify_gui_submitter_bundles test, | ||
| verifying that the Submit to AWS Deadline Cloud dialog correctly loads job bundles | ||
| and displays their settings. | ||
|
|
||
| Run with: | ||
| hatch run gui:test | ||
| """ | ||
|
|
||
| import os | ||
| from configparser import ConfigParser | ||
| from unittest.mock import MagicMock, PropertyMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| try: | ||
| from qtpy.QtWidgets import QWidget | ||
| from deadline.client.ui.dataclasses import JobBundleSettings | ||
| from deadline.client.ui.dialogs.submit_job_to_deadline_dialog import ( | ||
| SubmitJobToDeadlineDialog, | ||
| ) | ||
| from deadline.client.job_bundle.submission import AssetReferences | ||
| except ImportError: | ||
| pytest.skip("GUI dependencies not available", allow_module_level=True) | ||
|
|
||
|
|
||
| # Paths to the sample job bundles shipped with the Squish tests | ||
| _SAMPLES_DIR = os.path.join(os.path.dirname(__file__), "..", "squish", "deadline_gui_test_samples") | ||
| SIMPLE_UI_WITH_JA = os.path.join(_SAMPLES_DIR, "simple_ui_with_ja") | ||
| SIMPLE_UI_NO_JA = os.path.join(_SAMPLES_DIR, "simple_ui_no_ja") | ||
|
|
||
|
|
||
| class MockJobSettingsWidget(QWidget): | ||
| """A minimal job settings widget for testing.""" | ||
|
|
||
| def __init__(self, initial_settings=None, parent=None): | ||
| super().__init__(parent) | ||
| self.initial_settings = initial_settings | ||
| self.parameter_changed = MagicMock() | ||
| self.parameter_changed.connect = MagicMock() | ||
|
|
||
| def update_settings(self, settings): | ||
| pass | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_auth_status(): | ||
| """Mock DeadlineAuthenticationStatus to prevent real API calls.""" | ||
| mock_instance = MagicMock() | ||
| type(mock_instance).api_availability = PropertyMock(return_value=None) | ||
| type(mock_instance).creds_source = PropertyMock(return_value=None) | ||
| type(mock_instance).auth_status = PropertyMock(return_value=None) | ||
| mock_instance.config = ConfigParser() | ||
| mock_instance.api_availability_changed = MagicMock() | ||
| mock_instance.api_availability_changed.connect = MagicMock() | ||
| mock_instance.creds_source_changed = MagicMock() | ||
| mock_instance.creds_source_changed.connect = MagicMock() | ||
| mock_instance.auth_status_changed = MagicMock() | ||
| mock_instance.auth_status_changed.connect = MagicMock() | ||
|
|
||
| import deadline.client.ui.deadline_authentication_status as auth_module | ||
|
|
||
| auth_module._deadline_authentication_status = mock_instance | ||
| yield mock_instance | ||
| auth_module._deadline_authentication_status = None | ||
|
|
||
|
|
||
| def _create_dialog(qtbot, mock_auth_status, *, name, bundle_dir): | ||
| """Helper to create a SubmitJobToDeadlineDialog with a given bundle.""" | ||
| with patch( | ||
| "deadline.client.ui.widgets.deadline_authentication_status_widget" | ||
| ".DeadlineAuthenticationStatus.getInstance", | ||
| return_value=mock_auth_status, | ||
| ), patch( | ||
| "deadline.client.ui.dialogs.submit_job_to_deadline_dialog" | ||
| ".DeadlineAuthenticationStatus.getInstance", | ||
| return_value=mock_auth_status, | ||
| ): | ||
| settings = JobBundleSettings( | ||
| browse_enabled=True, | ||
| input_job_bundle_dir=bundle_dir, | ||
| name=name, | ||
| ) | ||
| dialog = SubmitJobToDeadlineDialog( | ||
| job_setup_widget_type=MockJobSettingsWidget, | ||
| initial_job_settings=settings, | ||
| initial_shared_parameter_values={}, | ||
| auto_detected_attachments=AssetReferences(), | ||
| attachments=AssetReferences(), | ||
| on_create_job_bundle_callback=MagicMock(), | ||
| ) | ||
| qtbot.addWidget(dialog) | ||
| dialog.show() | ||
| return dialog | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def submitter_dialog(qtbot, mock_auth_status): | ||
| """Create a SubmitJobToDeadlineDialog loaded with the simple_ui_with_ja bundle.""" | ||
| return _create_dialog( | ||
| qtbot, | ||
| mock_auth_status, | ||
| name="Simple UI with Job Attachments", | ||
| bundle_dir=SIMPLE_UI_WITH_JA, | ||
| ) | ||
|
|
||
|
|
||
| class TestGuiSubmitterBundles: | ||
| """ | ||
| pytest-qt equivalent of Squish tst_verify_gui_submitter_bundles. | ||
| """ | ||
|
|
||
| def test_submitter_dialog_opens(self, submitter_dialog): | ||
| """Verify the submitter dialog opens with correct title.""" | ||
| assert submitter_dialog.isVisible() | ||
| assert submitter_dialog.windowTitle() == "Submit to AWS Deadline Cloud" | ||
|
|
||
| def test_shared_job_settings_tab_exists(self, submitter_dialog): | ||
| """Verify the Shared job settings tab is present.""" | ||
| tabs = submitter_dialog.tabs | ||
| tab_names = [tabs.tabText(i) for i in range(tabs.count())] | ||
| assert "Shared job settings" in tab_names | ||
|
|
||
| def test_job_specific_settings_tab_exists(self, submitter_dialog): | ||
| """Verify the Job-specific settings tab is present.""" | ||
| tabs = submitter_dialog.tabs | ||
| tab_names = [tabs.tabText(i) for i in range(tabs.count())] | ||
| assert "Job-specific settings" in tab_names | ||
|
|
||
| def test_job_name_matches_bundle_with_ja(self, submitter_dialog): | ||
| """Verify the job name matches the simple_ui_with_ja bundle.""" | ||
| props = submitter_dialog.shared_job_settings.shared_job_properties_box | ||
| assert props.sub_name_edit.text() == "Simple UI with Job Attachments" | ||
|
|
||
| def test_load_bundle_button_exists(self, submitter_dialog): | ||
| """Verify the 'Load Bundle' button exists when browse is enabled.""" | ||
| assert hasattr(submitter_dialog, "load_bundle_button") | ||
| assert submitter_dialog.load_bundle_button.text() == "Load Bundle" | ||
| assert submitter_dialog.load_bundle_button.isEnabled() | ||
|
|
||
| def test_job_name_matches_bundle_no_ja(self, qtbot, mock_auth_status): | ||
| """Verify the job name matches the simple_ui_no_ja bundle.""" | ||
| dialog = _create_dialog( | ||
| qtbot, | ||
| mock_auth_status, | ||
| name="Simple UI - No Job Attachments", | ||
| bundle_dir=SIMPLE_UI_NO_JA, | ||
| ) | ||
| props = dialog.shared_job_settings.shared_job_properties_box | ||
| assert props.sub_name_edit.text() == "Simple UI - No Job Attachments" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these don't actually need a screen or start up a GUI, could we run them with the rest of the unit tests?