Commit ee67a66d authored by Samuel GAIST's avatar Samuel GAIST Committed by Flavio TARSETTI
Browse files

[widets][libraryeditor] Make all versions of libraries available to select

A library might be using an older version of another library.

Patch fields "uses" (optional) and "languages" (mandatory)
parent 7749fc21
......@@ -23,26 +23,64 @@
# #
###############################################################################
import pytest
from ..backend.asset import Asset
from ..backend.asset import AssetType
from ..backend.assetmodel import AssetModel
from ..widgets.libraryeditor import LibraryEditor
from .conftest import sync_prefix
from .conftest import prefix
def get_library_declaration(prefix_path, library_name):
asset = Asset(prefix_path, AssetType.LIBRARY, library_name)
return asset.declaration
def get_valid_library(test_prefix):
sync_prefix()
model = AssetModel()
model.asset_type = AssetType.LIBRARY
model.prefix_path = test_prefix
model.setLatestOnlyEnabled(False)
return [
algorithm
for algorithm in model.stringList()
if all(invalid not in algorithm for invalid in ["errors", "invalid"])
]
class TestLibraryEditor:
"""Test that the mock editor works correctly"""
def test_load_and_dump(self, qtbot, beat_context):
reference_json = {"description": "test", "uses": {}}
def test_default_dump(self, qtbot):
editor = LibraryEditor()
qtbot.addWidget(editor)
assert editor.dump_json() == {"language": None}
assert editor.is_valid()
@pytest.mark.parametrize("library", get_valid_library(prefix))
def test_load_and_dump(self, qtbot, beat_context, test_prefix, library):
reference_json = get_library_declaration(test_prefix, library)
editor = LibraryEditor()
qtbot.addWidget(editor)
editor.set_context(beat_context)
editor.load_json(reference_json)
uses = reference_json.get("uses")
if not uses:
reference_json.pop("uses", None)
assert editor.dump_json() == reference_json
assert editor.is_valid()
def test_load_and_dump_wrong(self, qtbot, beat_context):
faulty_json = {"description": "test", "uses": {"alias": "test/dummy/1"}}
reference_json = {"description": "test", "uses": {}}
reference_json = {"description": "test", "language": None}
editor = LibraryEditor()
qtbot.addWidget(editor)
editor.set_context(beat_context)
......
......@@ -46,8 +46,10 @@ class LibraryEditor(AbstractAssetEditor):
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Library"))
self.language = None
self.library_model = AssetModel()
self.library_model.asset_type = AssetType.LIBRARY
self.library_model.setLatestOnlyEnabled(False)
self.libraries_widget = LibrariesWidget()
self.layout().addWidget(self.libraries_widget)
......@@ -60,10 +62,15 @@ class LibraryEditor(AbstractAssetEditor):
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
self.language = json_object.get("language")
self.libraries_widget.set_available_libraries(self.library_model.stringList())
self.libraries_widget.set_used_libraries(json_object.get("uses", {}))
def _dump_json(self):
"""Returns the json representation of the asset"""
return {"uses": self.libraries_widget.get_used_libraries()}
data = {"language": self.language}
used_libraries = self.libraries_widget.get_used_libraries()
if used_libraries:
data["uses"] = used_libraries
return 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