Commit fb56e8f3 authored by Samuel GAIST's avatar Samuel GAIST

[backend][assetmodel] Add defaultFormat method

This method simplify the code to retrive the format
to put as default value when, for example, creating
a new input or output for an algorithm as well as
values for tests.
parent 79c5d20d
Pipeline #41880 passed with stage
in 11 minutes and 51 seconds
......@@ -280,6 +280,14 @@ class DataFormatModel(AbstractAssetModel):
return os.path.join(self.prefix_path, self.__asset_type.path)
def defaultFormat(self):
"""Returns a format used to setup a default value
:returns: the default format
"""
return self.index(0).data()
def setFullListEnabled(self, enabled):
"""Enable/disable the full list mode
......
......@@ -46,13 +46,17 @@ def dataformat_model(test_prefix):
@pytest.fixture()
def reference_set_json():
return {"name": "test", "outputs": {"out1": "int8"}}
def reference_set_json(dataformat_model):
return {"name": "test", "outputs": {"out1": dataformat_model.defaultFormat()}}
@pytest.fixture()
def reference_pt_json():
return {"sets": [{"name": "original", "outputs": {"a": "int8"}}]}
def reference_pt_json(dataformat_model):
return {
"sets": [
{"name": "original", "outputs": {"a": dataformat_model.defaultFormat()}}
]
}
class TestSetWidget:
......@@ -68,7 +72,7 @@ class TestSetWidget:
def test_add_output(self, qtbot, dataformat_model, reference_set_json):
edited_json = copy.deepcopy(reference_set_json)
edited_json["outputs"]["Change_me"] = "int8"
edited_json["outputs"]["Change_me"] = dataformat_model.defaultFormat()
set_widget = SetWidget(dataformat_model)
set_widget.load(reference_set_json)
......@@ -114,11 +118,16 @@ class TestProtocolTemplateEditor:
assert editor.dump_json() == json_data
def test_add_set(self, qtbot, monkeypatch, beat_context, reference_pt_json):
def test_add_set(
self, qtbot, monkeypatch, beat_context, reference_pt_json, dataformat_model
):
edited_json = copy.deepcopy(reference_pt_json)
edited_json["schema_version"] = 1
edited_json["sets"].append(
{"name": "test_set", "outputs": {"Change_me": "int8"}}
{
"name": "test_set",
"outputs": {"Change_me": dataformat_model.defaultFormat()},
}
)
monkeypatch.setattr(
......
......@@ -462,7 +462,7 @@ class IOWidget(QGroupBox):
new_row = self.tablewidget.rowCount()
self.tablewidget.setRowCount(new_row + 1)
name_item = QTableWidgetItem(self.tr("Name_me"))
type_item = QTableWidgetItem(self.dataformat_model.index(0).data())
type_item = QTableWidgetItem(self.dataformat_model.defaultFormat())
self.tablewidget.setItem(new_row, 0, name_item)
self.tablewidget.setItem(new_row, 1, type_item)
self.tablewidget.scrollToItem(name_item)
......
......@@ -116,7 +116,7 @@ class SetWidget(QWidget):
new_row = self.outputs_tablewidget.rowCount()
self.outputs_tablewidget.setRowCount(new_row + 1)
name_item = QTableWidgetItem(self.tr("Change_me"))
type_item = QTableWidgetItem(self.dataformat_model.index(0).data())
type_item = QTableWidgetItem(self.dataformat_model.defaultFormat())
self.outputs_tablewidget.setItem(new_row, 0, name_item)
self.outputs_tablewidget.setItem(new_row, 1, type_item)
self.outputs_tablewidget.scrollToItem(type_item)
......@@ -235,7 +235,7 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
{
"name": name,
"outputs": {
"Change_me": self.dataformat_model.index(0).data()
"Change_me": self.dataformat_model.defaultFormat()
},
}
]
......
Markdown is supported
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