Commit 5b09a63d authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][dialog] Fix radio button initialisation

Use a QButtonGroup to have proper handling of exclusive
state. The other technique is to pass a common parent to
all the concerned buttons. However in this case it means
that all the buttons would be visible by default which is
not what is wanted.

The tests have also been improved to verify that all types
are handled properly.
parent c4823703
......@@ -32,17 +32,6 @@ from ..backend.asset import AssetType
from ..widgets.dialogs import AssetCreationDialog
@pytest.fixture(
params=[
AssetCreationDialog.NEW,
AssetCreationDialog.NEW_VERSION,
AssetCreationDialog.FORK,
]
)
def creation_type(request):
return request.param
class TestAssetCreationDialog:
"""Test that the asset creation dialog works as expected"""
......@@ -79,8 +68,8 @@ class TestAssetCreationDialog:
assert dialog.fork_combobox.isEnabled()
assert dialog.creationType() == AssetCreationDialog.FORK
def test_create_new(self, qtbot, beat_context):
dialog = AssetCreationDialog(beat_context, AssetType.DATAFORMAT)
def test_create_new(self, qtbot, beat_context, asset_type):
dialog = AssetCreationDialog(beat_context, asset_type)
qtbot.addWidget(dialog)
asset_name = "test_asset"
......@@ -96,8 +85,11 @@ class TestAssetCreationDialog:
assert dialog.creationType() == AssetCreationDialog.NEW
assert dialog.assetInfo() == asset_name
def test_create_new_version(self, qtbot, beat_context):
dialog = AssetCreationDialog(beat_context, AssetType.DATAFORMAT)
@pytest.mark.parametrize(
"asset_type", [item for item in AssetType if item.can_create()]
)
def test_create_new_version(self, qtbot, beat_context, asset_type):
dialog = AssetCreationDialog(beat_context, asset_type)
qtbot.addWidget(dialog)
with qtbot.waitCallback() as cb:
......@@ -110,8 +102,11 @@ class TestAssetCreationDialog:
assert dialog.creationType() == AssetCreationDialog.NEW_VERSION
assert dialog.assetInfo() == dialog.new_version_combobox.currentText()
def test_create_fork(self, qtbot, beat_context):
dialog = AssetCreationDialog(beat_context, AssetType.DATAFORMAT)
@pytest.mark.parametrize(
"asset_type", [item for item in AssetType if item.can_fork()]
)
def test_create_fork(self, qtbot, beat_context, asset_type):
dialog = AssetCreationDialog(beat_context, asset_type)
qtbot.addWidget(dialog)
asset_name = "test_asset"
......
......@@ -26,6 +26,7 @@
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import QButtonGroup
from PyQt5.QtWidgets import QComboBox
from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QDialogButtonBox
......@@ -105,6 +106,11 @@ class AssetCreationDialog(QDialog, CreationType):
self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonbox.button(QDialogButtonBox.Ok).setEnabled(False)
button_group = QButtonGroup(self)
button_group.addButton(self.new_radio_button)
button_group.addButton(self.new_version_radio_button)
button_group.addButton(self.fork_radio_button)
# Layouts
fork_layout = QVBoxLayout()
fork_layout.addWidget(self.fork_combobox)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment