Commit 4afd5bbb authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][editor] Code cleanup

- Moved test into a class
- Use fixture for model creation
parent fa0464e5
......@@ -22,6 +22,7 @@
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import pytest
from PyQt5 import QtCore
......@@ -36,7 +37,7 @@ from ..widgets.field import Field
class MockAssetEditor(AbstractAssetEditor):
"""
Base class of all asset editors
Mock editor to show how to test an editor
"""
def __init__(self, parent=None):
......@@ -56,6 +57,7 @@ class MockAssetEditor(AbstractAssetEditor):
def load_json(self, json_object):
"""Load the json object passed as parameter"""
for name, type_ in json_object.items():
field = Field(self.dataformat_model)
field.format_name = name
......@@ -64,6 +66,7 @@ class MockAssetEditor(AbstractAssetEditor):
def dump_json(self):
"""Returns the json representation of the asset"""
field_list = self.findChildren(Field)
json_data = {}
......@@ -74,10 +77,16 @@ class MockAssetEditor(AbstractAssetEditor):
return json_data
def test_json_load_and_dump(qtbot):
json_reference = {"value32": "float32", "value64": "float64"}
@pytest.fixture()
def dataformat_model():
return QStringListModel(["float32", "float64", "int32", "int64"])
dataformat_model = QStringListModel(["float32", "float64", "int32", "int64"])
class TestMockEditor:
"""Test that the mock editor works correctly"""
def test_json_load_and_dump(self, qtbot, dataformat_model):
json_reference = {"value32": "float32", "value64": "float64"}
widget = MockAssetEditor()
widget.set_dataformat_model(dataformat_model)
......@@ -85,12 +94,7 @@ def test_json_load_and_dump(qtbot):
assert widget.dump_json() == json_reference
def test_dataformat_creation(qtbot):
# json_reference = {"value32": "float32", "value64": "float64"}
dataformat_model = QStringListModel(["float32", "float64", "int32", "int64"])
def test_dataformat_creation(self, qtbot, dataformat_model):
widget = MockAssetEditor()
widget.set_dataformat_model(dataformat_model)
......@@ -101,4 +105,19 @@ def test_dataformat_creation(qtbot):
field = fields[0]
qtbot.mouseClick(field.dataformat_box, QtCore.Qt.LeftButton)
field.format_name = "value32"
field.format_type = "float32"
assert widget.dump_json() == {"value32": "float32"}
qtbot.mouseClick(widget.add_field_button, QtCore.Qt.LeftButton)
fields = widget.findChildren(Field)
assert len(fields) == 2
field = fields[1]
field.format_name = "value64"
field.format_type = "float64"
assert widget.dump_json() == {"value32": "float32", "value64": "float64"}
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