Commit 2b2d84e8 authored by André Anjos's avatar André Anjos 💬

Merge branch '64_add_protocoltemplate_prototype' into 'master'

Implement support for protocol template prototype

See merge request !71
parents 1a1a8c49 6735c859
Pipeline #29849 passed with stages
in 18 minutes and 44 seconds
...@@ -48,6 +48,7 @@ Forward importing from :py:mod:`beat.backend.python.protocoltemplate`: ...@@ -48,6 +48,7 @@ Forward importing from :py:mod:`beat.backend.python.protocoltemplate`:
import six import six
from . import schema from . import schema
from . import prototypes
from beat.backend.python.protocoltemplate import Storage from beat.backend.python.protocoltemplate import Storage
from beat.backend.python.protocoltemplate import ( from beat.backend.python.protocoltemplate import (
...@@ -106,18 +107,22 @@ class ProtocolTemplate(BackendProtocolTemplate): ...@@ -106,18 +107,22 @@ class ProtocolTemplate(BackendProtocolTemplate):
self.storage = None self.storage = None
self.dataformats = {} # preloaded dataformats self.dataformats = {} # preloaded dataformats
if isinstance(data, six.string_types): # user has passed a file pointer if data is None: # loads prototype and validates it
self.data, self.errors = prototypes.load("protocoltemplate")
self._name = data assert not self.errors, "\n * %s" % "\n *".join(self.errors) # nosec
self.storage = Storage(self.prefix, self._name) else:
data = self.storage.json.path if isinstance(data, six.string_types): # user has passed a file pointer
if not self.storage.json.exists():
self.errors.append( self._name = data
"Protocol template declaration file not found: %s" % data self.storage = Storage(self.prefix, self._name)
) data = self.storage.json.path
return if not self.storage.json.exists():
self.errors.append(
# this runs basic validation, including JSON loading if required "Protocol template declaration file not found: %s" % data
self.data, self.errors = schema.validate("protocoltemplate", data) )
if self.errors: return
return # don't proceed with the rest of validation
# this runs basic validation, including JSON loading if required
self.data, self.errors = schema.validate("protocoltemplate", data)
if self.errors:
return # don't proceed with the rest of validation
{
"schema_version": 1,
"sets": [
{
"name": "name",
"outputs": {
"out": "user/single_integer/1"
}
}
]
}
...@@ -41,6 +41,12 @@ from . import prefix, tmp_prefix ...@@ -41,6 +41,12 @@ from . import prefix, tmp_prefix
from .utils import cleanup from .utils import cleanup
def test_default():
obj = ProtocolTemplate(prefix, data=None)
nose.tools.assert_true(obj.valid, "\n * %s" % "\n * ".join(obj.errors))
def test_export(): def test_export():
for protocol_name in [ for protocol_name in [
"double", "double",
......
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