Commit 17dc2805 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][algorithmeditor] Add helper method for migration from v1 API

parent 56574fcd
...@@ -39,6 +39,7 @@ from ..widgets.algorithmeditor import AlgorithmEditor ...@@ -39,6 +39,7 @@ from ..widgets.algorithmeditor import AlgorithmEditor
from ..widgets.algorithmeditor import ALGORITHM_TYPE from ..widgets.algorithmeditor import ALGORITHM_TYPE
from ..widgets.algorithmeditor import DEFAULT_SCHEMA_VERSION from ..widgets.algorithmeditor import DEFAULT_SCHEMA_VERSION
from ..widgets.algorithmeditor import DEFAULT_API_VERSION from ..widgets.algorithmeditor import DEFAULT_API_VERSION
from ..widgets.algorithmeditor import migrate_to_api_v2
from .conftest import sync_prefix from .conftest import sync_prefix
from .conftest import prefix from .conftest import prefix
...@@ -73,6 +74,30 @@ def dataformat_model(test_prefix): ...@@ -73,6 +74,30 @@ def dataformat_model(test_prefix):
return model return model
@pytest.fixture(autouse=True)
def synced_prefix():
"""Re sync the prefix between test"""
sync_prefix()
class TestHelperMethods:
def test_migration(self, test_prefix):
algorithm = "v1/sum/1"
asset = Asset(test_prefix, AssetType.ALGORITHM, algorithm)
result, new_asset = migrate_to_api_v2(asset)
assert result
assert new_asset.name != asset.name
v1_declaration = asset.declaration
v2_declaration = new_asset.declaration
assert v1_declaration != v2_declaration
assert v2_declaration["schema_version"] == 2
assert v2_declaration["api_version"] == 2
assert v2_declaration["type"] == "legacy"
class TestPropertyEditor: class TestPropertyEditor:
"""Test that the algorithm properties editor works as expected""" """Test that the algorithm properties editor works as expected"""
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# # # #
############################################################################### ###############################################################################
import os
from PyQt5.QtCore import pyqtSignal from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QSortFilterProxyModel from PyQt5.QtCore import QSortFilterProxyModel
...@@ -43,6 +45,7 @@ from PyQt5.QtWidgets import QVBoxLayout ...@@ -43,6 +45,7 @@ from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QWidget
from ..backend.asset import AssetType from ..backend.asset import AssetType
from ..backend.asset import Asset
from ..backend.assetmodel import AssetModel from ..backend.assetmodel import AssetModel
from ..backend.delegates import AssetItemDelegate from ..backend.delegates import AssetItemDelegate
...@@ -59,6 +62,39 @@ ALGORITHM_TYPE = "algorithm_type" ...@@ -59,6 +62,39 @@ ALGORITHM_TYPE = "algorithm_type"
DEFAULT_SCHEMA_VERSION = 2 DEFAULT_SCHEMA_VERSION = 2
DEFAULT_API_VERSION = 2 DEFAULT_API_VERSION = 2
ALGORITHM_PROCESS_METHOD_MAP = {
"legacy": "def process(self, inputs, outputs):",
"sequential": "def process(self, inputs, data_loaders, outputs):",
"autonomous": "def process(self, data_loaders, outputs):",
"loop_user": "def process(self, data_loaders, channel):",
}
ANALYZER_PROCESS_METHOD_MAP = {
"legacy": "def process(self, inputs, output):",
"sequential": "def process(self, inputs, data_loaders, output):",
"autonomous": "def process(self, data_loaders, output):",
}
LOOP_VALIDATE_METHOD = "def validate(self, result):"
def migrate_to_api_v2(asset):
status = asset.type.create_new_version(asset.prefix, asset.name)
new_asset = None
if status:
version_number = int(asset.storage().version) + 1
name = os.sep.join(asset.name.split(os.sep)[:-1] + [""])
name += str(version_number)
new_asset = Asset(asset.prefix, asset.type, name)
declaration = new_asset.declaration
declaration["api_version"] = 2
declaration["schema_version"] = 2
declaration["type"] = "legacy"
new_asset.declaration = declaration
return status, new_asset
class PropertyEditor(QWidget): class PropertyEditor(QWidget):
......
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