Commit 90cabb18 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][assetwidget] Implement error hinting for experiment editor

parent 8b95ff9b
Pipeline #40507 passed with stage
in 23 minutes and 8 seconds
......@@ -591,3 +591,24 @@ class TestAssetWidget:
asset_widget.loadAsset(asset)
assert asset_widget.current_asset.name == "v1/sum/2"
def test_experiment_error_hinting(self, qtbot, test_prefix, beat_context):
asset_widget = AssetWidget()
qtbot.addWidget(asset_widget)
asset_widget.set_context(beat_context)
asset_name = "user/user/two_loops/1/two_loops"
asset = Asset(test_prefix, AssetType.EXPERIMENT, asset_name)
with qtbot.waitSignal(asset_widget.currentAssetChanged):
asset_widget.loadAsset(asset)
BLOCK_TO_CHANGE = "offsetter_for_loop_evaluator"
ALGORITHM_TO_SELECT = "user/string_offsetter/1"
editor = asset_widget.current_editor.findEditor(BLOCK_TO_CHANGE)
with qtbot.waitSignal(editor.dataChanged):
editor.properties_editor.algorithm_combobox.setCurrentText(
ALGORITHM_TO_SELECT
)
assert editor.error_label.toolTip() != ""
......@@ -46,6 +46,7 @@ from PyQt5.QtWidgets import QWidget
from ..backend.asset import Asset
from ..backend.asset import AssetType
from ..backend.experimentmodel import ExperimentModel
from ..backend.resourcemodels import experiment_resources
from ..decorators import frozen
from .algorithmeditor import AlgorithmEditor
......@@ -135,6 +136,7 @@ class AssetWidget(QWidget):
super().__init__(parent)
self.experiment_model = ExperimentModel()
self.context = None
self.current_asset = None
self.watcher = QFileSystemWatcher()
......@@ -189,6 +191,8 @@ class AssetWidget(QWidget):
for action in self.create_actions():
action.triggered.connect(self.__onCreateActionTriggered)
experiment_editor = self.type_editor_map[AssetType.EXPERIMENT]
experiment_editor.blockChanged.connect(self.__onBlockChanged)
self.set_current_editor(AssetType.UNKNOWN)
@property
......@@ -221,6 +225,10 @@ class AssetWidget(QWidget):
editor = self.type_editor_map[self.current_asset.type]
editor.load_json(json_data)
if self.current_asset.type == AssetType.EXPERIMENT:
editor.loadToolchainData("/".join(self.current_asset.name.split("/")[1:4]))
editor.dataChanged.connect(self.update_timer.start)
self.set_current_editor(self.current_asset.type)
self.__updateJsonWidget()
......@@ -292,6 +300,13 @@ class AssetWidget(QWidget):
elif asset:
self.loadAsset(asset)
@pyqtSlot(str, dict)
def __onBlockChanged(self, block_name, configuration):
self.experiment_model.update_block(block_name, configuration)
errors_map = self.experiment_model.check_all_blocks()
experiment_editor = self.type_editor_map[AssetType.EXPERIMENT]
experiment_editor.setBlockErrors(errors_map)
@pyqtSlot()
def __updateJsonWidget(self):
self.json_widget.setText(self.current_editor.dump_as_string())
......@@ -404,7 +419,7 @@ class AssetWidget(QWidget):
message_box = QMessageBox(
QMessageBox.Critical,
self.tr("Invalid asset"),
self.tr(f"The asset you are trying to load is invalid."),
self.tr("The asset you are trying to load is invalid."),
)
message_box.setDetailedText(f"{errors}")
message_box.addButton(QMessageBox.Cancel)
......@@ -477,6 +492,8 @@ class AssetWidget(QWidget):
self.tr("Failed to create new version"),
)
return
elif asset.type == AssetType.EXPERIMENT:
self.experiment_model.load_experiment(asset)
self.watcher.addPath(asset.declaration_path)
self.current_asset = asset
......
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