Commit c4bf477e authored by Samuel GAIST's avatar Samuel GAIST

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

A library might be using an older version of another library.
parent 0ba94264
Pipeline #31623 passed with stage
in 24 minutes and 12 seconds
......@@ -23,20 +23,58 @@
# #
###############################################################################
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", "language": "python"}
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()
......
......@@ -49,6 +49,7 @@ class LibraryEditor(AbstractAssetEditor):
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)
......
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