Commit 07bc3aab authored by Samuel GAIST's avatar Samuel GAIST

[test][experimenteditor] Refactor block editor tests

This makes the tests better separated.
parent 3aa2bb38
Pipeline #33487 passed with stage
in 24 minutes and 12 seconds
......@@ -443,84 +443,8 @@ class TestEnvironmentModel:
assert combobox.itemText(i) == visual_name
class TestExecutionPropertiesEditor:
"""Test that the AlgorithmEdior works as expected"""
editor_klass = ExecutionPropertiesEditor
declaration_field = "blocks"
parameter_field = "parameters"
@pytest.fixture()
def properties_editor(self, beat_context, test_prefix, algorithm_model):
environment_model = EnvironmentModel()
environment_model.setContext(beat_context)
editor = self.editor_klass(test_prefix)
editor.setAlgorithmModel(algorithm_model)
editor.setEnvironmentModel(environment_model)
editor.setQueueModel(QStringListModel(["Test"]))
return editor
def test_load_and_dump(
self, qtbot, properties_editor, test_prefix, test_experiment, algorithm_model
):
qtbot.addWidget(properties_editor)
experiment_declaration = get_experiment_declaration(
test_prefix, test_experiment
)
algorithms = experiment_declaration[self.declaration_field]
first_algorithm = next(iter(algorithms))
json_reference = algorithms[first_algorithm]
properties_editor.load(json_reference)
assert properties_editor.dump() == json_reference
def test_edit_environment(
self, qtbot, properties_editor, test_prefix, test_experiment, algorithm_model
):
qtbot.addWidget(properties_editor)
experiment_declaration = get_experiment_declaration(
test_prefix, test_experiment
)
algorithms = experiment_declaration[self.declaration_field]
first_algorithm = next(iter(algorithms))
json_reference = algorithms[first_algorithm]
properties_editor.load(json_reference)
environment_model = properties_editor.environmentModel()
environment = environment_model.environment(environment_model.index(1, 0))
with qtbot.waitSignal(properties_editor.dataChanged):
combobox = properties_editor.findChild(QComboBox, "environments")
combobox.setCurrentIndex(1)
assert properties_editor.dump()["environment"] == environment
def test_edit_algorithm(
self, qtbot, properties_editor, test_prefix, test_experiment, algorithm_model
):
qtbot.addWidget(properties_editor)
experiment_declaration = get_experiment_declaration(
test_prefix, test_experiment
)
algorithms = experiment_declaration[self.declaration_field]
first_algorithm = next(iter(algorithms))
json_reference = algorithms[first_algorithm]
properties_editor.load(json_reference)
combobox = properties_editor.findChild(QComboBox, "algorithms")
with qtbot.waitSignal(properties_editor.dataChanged):
next_index = combobox.currentIndex() + 1
if next_index == combobox.count():
next_index -= 2
combobox.setCurrentIndex(next_index)
assert properties_editor.dump()["algorithm"] == combobox.currentText()
class ParameterTestMixin:
"""Mixin related to editors for blocks that can have parameters"""
def test_edit_parameter(
self, qtbot, properties_editor, test_prefix, test_experiment, algorithm_model
......@@ -589,6 +513,77 @@ class TestExecutionPropertiesEditor:
dump = properties_editor.dump()
assert dump[self.parameter_field] == {label: new_value}
class PropertiesEditorTestMixin:
"""Mixin that provides the common tests to execute for editors related to
block properties
"""
editor_klass = None
declaration_field = ""
parameter_field = ""
def test_load_and_dump(
self, qtbot, properties_editor, test_prefix, test_experiment, algorithm_model
):
qtbot.addWidget(properties_editor)
experiment_declaration = get_experiment_declaration(
test_prefix, test_experiment
)
algorithms = experiment_declaration[self.declaration_field]
first_algorithm = next(iter(algorithms))
json_reference = algorithms[first_algorithm]
properties_editor.load(json_reference)
assert properties_editor.dump() == json_reference
def test_edit_environment(
self, qtbot, properties_editor, test_prefix, test_experiment, algorithm_model
):
qtbot.addWidget(properties_editor)
experiment_declaration = get_experiment_declaration(
test_prefix, test_experiment
)
algorithms = experiment_declaration[self.declaration_field]
first_algorithm = next(iter(algorithms))
json_reference = algorithms[first_algorithm]
properties_editor.load(json_reference)
environment_model = properties_editor.environmentModel()
environment = environment_model.environment(environment_model.index(1, 0))
with qtbot.waitSignal(properties_editor.dataChanged):
combobox = properties_editor.findChild(QComboBox, "environments")
combobox.setCurrentIndex(1)
assert properties_editor.dump()["environment"] == environment
def test_edit_algorithm(
self, qtbot, properties_editor, test_prefix, test_experiment, algorithm_model
):
qtbot.addWidget(properties_editor)
experiment_declaration = get_experiment_declaration(
test_prefix, test_experiment
)
algorithms = experiment_declaration[self.declaration_field]
first_algorithm = next(iter(algorithms))
json_reference = algorithms[first_algorithm]
properties_editor.load(json_reference)
combobox = properties_editor.findChild(QComboBox, "algorithms")
with qtbot.waitSignal(properties_editor.dataChanged):
next_index = combobox.currentIndex() + 1
if next_index == combobox.count():
next_index -= 2
combobox.setCurrentIndex(next_index)
assert properties_editor.dump()["algorithm"] == combobox.currentText()
def test_edit_io_mapping(
self,
qtbot,
......@@ -633,6 +628,25 @@ class TestExecutionPropertiesEditor:
assert properties_editor.dump()["outputs"] == io_mapping_answer["outputs"]
class TestExecutionPropertiesEditor(PropertiesEditorTestMixin, ParameterTestMixin):
"""Test that the AlgorithmEdior works as expected"""
editor_klass = ExecutionPropertiesEditor
declaration_field = "blocks"
parameter_field = "parameters"
@pytest.fixture()
def properties_editor(self, beat_context, test_prefix, algorithm_model):
environment_model = EnvironmentModel()
environment_model.setContext(beat_context)
editor = self.editor_klass(test_prefix)
editor.setAlgorithmModel(algorithm_model)
editor.setEnvironmentModel(environment_model)
editor.setQueueModel(QStringListModel(["Test"]))
return editor
class TestBlockEditor(TestExecutionPropertiesEditor):
"""Test that the editor for blocks works correctly"""
......@@ -651,7 +665,7 @@ class TestBlockEditor(TestExecutionPropertiesEditor):
return editor
class TestAnalyzerBlockEditor(TestExecutionPropertiesEditor):
class TestAnalyzerBlockEditor(PropertiesEditorTestMixin):
"""Test that the editor for analyzer blocks works correctly"""
editor_klass = AnalyzerBlockEditor
......@@ -668,18 +682,6 @@ class TestAnalyzerBlockEditor(TestExecutionPropertiesEditor):
editor.setQueueModel(QStringListModel(["Test"]))
return editor
@pytest.mark.skip(reason="Analyzers don't have properties")
def test_edit_parameter(
self, qtbot, properties_editor, test_prefix, test_experiment, algorithm_model
):
pass
@pytest.mark.skip(reason="Analyzers don't have properties")
def test_edit_parameter_going_back_to_default_value(
self, qtbot, properties_editor, test_prefix, test_experiment, algorithm_model
):
pass
class TestLoopBlockEditor(TestExecutionPropertiesEditor):
"""Test that the editor for the loop blocks works correctly"""
......
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