Commit 2965b338 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test] Port tests to use Asset

parent 851bc579
......@@ -45,7 +45,8 @@ from ..widgets.plotterparameterseditor import PlotterParametersEditor
from ..widgets.protocoltemplateeditor import ProtocolTemplateEditor
from ..widgets.toolchaineditor import ToolchainEditor
from ..backend.assetmodel import AssetType
from ..backend.asset import AssetType
from ..backend.asset import Asset
from ..backend.assetmodel import AssetModel
from .conftest import sync_prefix
......@@ -90,7 +91,8 @@ class TestAssetWidget:
asset_type,
(asset_name, editor_type),
) in asset_type_prefix_entry_map.items():
asset_widget.load_json(asset_type.declaration_path(test_prefix, asset_name))
asset = Asset(test_prefix, asset_type, asset_name)
asset_widget.load_json(asset.declaration_path)
assert isinstance(asset_widget.current_editor, editor_type)
def test_dirty(
......@@ -109,7 +111,8 @@ class TestAssetWidget:
asset_type,
(asset_name, editor_type),
) in asset_type_prefix_entry_map.items():
asset_widget.load_json(asset_type.declaration_path(test_prefix, asset_name))
asset = Asset(test_prefix, asset_type, asset_name)
asset_widget.load_json(asset.declaration_path)
assert not asset_widget.current_editor.isDirty()
with qtbot.waitSignal(asset_widget.json_widget.textChanged):
......@@ -140,8 +143,8 @@ class TestAssetWidget:
asset_type,
(asset_name, editor_type),
) in asset_type_prefix_entry_map.items():
asset_path = asset_type.declaration_path(test_prefix, asset_name)
asset_widget.load_json(asset_path)
asset = Asset(test_prefix, asset_type, asset_name)
asset_widget.load_json(asset.declaration_path)
with qtbot.waitSignal(asset_widget.json_widget.textChanged):
asset_widget.current_editor.description_lineedit.selectAll()
......@@ -156,7 +159,7 @@ class TestAssetWidget:
description_key = "description"
if asset_type == AssetType.DATAFORMAT:
description_key = "#" + description_key
with open(asset_path, "rt") as json_file:
with open(asset.declaration_path, "rt") as json_file:
json_data = json.loads(json_file.read())
assert json_data[description_key] == description
......@@ -298,9 +301,9 @@ class TestAssetWidget:
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
asset_path = asset_type.declaration_path(test_prefix, asset_name)
asset_widget.load_json(asset_path)
asset = Asset(test_prefix, asset_type, asset_name)
asset_widget.load_json(asset.declaration_path)
assert asset_widget.current_editor.asset_type != AssetType.UNKNOWN
asset_widget.deleteAsset(asset_path)
asset_widget.deleteAsset(asset.declaration_path)
assert asset_widget.current_editor.asset_type == AssetType.UNKNOWN
assert not os.path.exists(asset_path)
assert not os.path.exists(asset.declaration_path)
......@@ -32,7 +32,8 @@ from PyQt5 import QtCore
from PyQt5.QtWidgets import QComboBox
from PyQt5.QtWidgets import QInputDialog
from ..backend.assetmodel import AssetType
from ..backend.asset import AssetType
from ..backend.asset import Asset
from ..widgets.databaseeditor import DatabaseEditor
from ..widgets.databaseeditor import ViewEditor
from ..widgets.databaseeditor import ViewsEditor
......@@ -66,9 +67,8 @@ def reference_view_json(request):
@pytest.fixture()
def reference_database_json(test_prefix):
with open(
AssetType.DATABASE.declaration_path(test_prefix, "simple/2"), "rt"
) as json_file:
asset = Asset(test_prefix, AssetType.DATABASE, "simple/2")
with open(asset.declaration_path, "rt") as json_file:
return json.load(json_file)
......@@ -320,9 +320,9 @@ class TestDatabaseEditor:
"""Test that the database editor works correctly"""
def test_load_and_dump(self, qtbot, beat_context, test_prefix, test_database):
with open(
AssetType.DATABASE.declaration_path(test_prefix, test_database), "rt"
) as json_file:
asset = Asset(test_prefix, AssetType.DATABASE, test_database)
with open(asset.declaration_path, "rt") as json_file:
json_data = json.load(json_file)
editor = DatabaseEditor()
editor.set_context(beat_context)
......
......@@ -31,7 +31,8 @@ from PyQt5 import QtCore
from PyQt5.QtWidgets import QInputDialog
from ..backend.assetmodel import AssetType
from ..backend.asset import Asset
from ..backend.asset import AssetType
from ..widgets.parameterwidget import BoolSetupWidget
from ..widgets.parameterwidget import StringSetupWidget
from ..widgets.parameterwidget import NumericalSetupWidget
......@@ -56,9 +57,8 @@ UNSIGNED_TYPES = [InputType.UINT8, InputType.UINT16, InputType.UINT32, InputType
def get_algorithm_declaration(prefix_path, algorithm_name):
with open(
AssetType.ALGORITHM.declaration_path(prefix_path, algorithm_name), "rt"
) as json_file:
asset = Asset(prefix_path, AssetType.ALGORITHM, algorithm_name)
with open(asset.declaration_path, "rt") as json_file:
return json.load(json_file)
......
......@@ -31,8 +31,9 @@ from PyQt5 import QtCore
from PyQt5.QtWidgets import QInputDialog
from ..backend.asset import AssetType
from ..backend.asset import Asset
from ..backend.assetmodel import AssetModel
from ..backend.assetmodel import AssetType
from ..widgets.protocoltemplateeditor import SetWidget
from ..widgets.protocoltemplateeditor import ProtocolTemplateEditor
......@@ -105,10 +106,8 @@ class TestProtocolTemplateEditor:
def test_load_and_dump(self, qtbot, test_prefix):
asset_name = "double/1"
with open(
AssetType.PROTOCOLTEMPLATE.declaration_path(test_prefix, asset_name), "rt"
) as json_file:
asset = Asset(test_prefix, AssetType.PROTOCOLTEMPLATE, asset_name)
with open(asset.declaration_path, "rt") as json_file:
json_data = json.load(json_file)
editor = ProtocolTemplateEditor()
editor.load_json(json_data)
......
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