Commit cc298742 authored by J. Fernando Sánchez's avatar J. Fernando Sánchez
Browse files

Merge branch '17-...' into 0.8.x

parents a8614bab 250052fb
...@@ -13,7 +13,7 @@ from .. import models ...@@ -13,7 +13,7 @@ from .. import models
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class SenpyPlugin(models.Plugin): class Plugin(models.Plugin):
def __init__(self, info=None): def __init__(self, info=None):
""" """
Provides a canonical name for plugins and serves as base for other Provides a canonical name for plugins and serves as base for other
...@@ -24,7 +24,7 @@ class SenpyPlugin(models.Plugin): ...@@ -24,7 +24,7 @@ class SenpyPlugin(models.Plugin):
"information for the plugin.")) "information for the plugin."))
logger.debug("Initialising {}".format(info)) logger.debug("Initialising {}".format(info))
id = 'plugins/{}_{}'.format(info['name'], info['version']) id = 'plugins/{}_{}'.format(info['name'], info['version'])
super(SenpyPlugin, self).__init__(id=id, **info) super(Plugin, self).__init__(id=id, **info)
self.is_activated = False self.is_activated = False
def get_folder(self): def get_folder(self):
...@@ -37,7 +37,10 @@ class SenpyPlugin(models.Plugin): ...@@ -37,7 +37,10 @@ class SenpyPlugin(models.Plugin):
pass pass
class AnalysisPlugin(SenpyPlugin): SenpyPlugin = Plugin
class AnalysisPlugin(Plugin):
def analyse(self, *args, **kwargs): def analyse(self, *args, **kwargs):
raise NotImplemented( raise NotImplemented(
...@@ -64,7 +67,7 @@ class AnalysisPlugin(SenpyPlugin): ...@@ -64,7 +67,7 @@ class AnalysisPlugin(SenpyPlugin):
yield result yield result
class ConversionPlugin(SenpyPlugin): class ConversionPlugin(Plugin):
pass pass
......
...@@ -37,6 +37,12 @@ ...@@ -37,6 +37,12 @@
"@type": "@id", "@type": "@id",
"@container": "@set" "@container": "@set"
}, },
"plugins": {
"@container": "@list"
},
"options": {
"@container": "@set"
},
"prov:wasGeneratedBy": { "prov:wasGeneratedBy": {
"@type": "@id" "@type": "@id"
}, },
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"properties": { "properties": {
"plugins": { "plugins": {
"type": "array", "type": "array",
"default": [],
"items": { "items": {
"$ref": "plugin.json" "$ref": "plugin.json"
} }
......
from senpy.plugins import SenpyPlugin from senpy.plugins import AnalysisPlugin
from time import sleep from time import sleep
class SleepPlugin(SenpyPlugin): class SleepPlugin(AnalysisPlugin):
def activate(self, *args, **kwargs): def activate(self, *args, **kwargs):
sleep(self.timeout) sleep(self.timeout)
......
...@@ -11,8 +11,10 @@ from senpy.models import (Emotion, ...@@ -11,8 +11,10 @@ from senpy.models import (Emotion,
Entry, Entry,
Error, Error,
Results, Results,
Sentiment) Sentiment,
from senpy.plugins import SenpyPlugin Plugins,
Plugin)
from senpy import plugins
from pprint import pprint from pprint import pprint
...@@ -53,8 +55,8 @@ class ModelsTest(TestCase): ...@@ -53,8 +55,8 @@ class ModelsTest(TestCase):
assert (received["entries"][0]["nif:isString"] != "Not testing") assert (received["entries"][0]["nif:isString"] != "Not testing")
def test_id(self): def test_id(self):
''' Adding the id after creation should overwrite the automatic ID """ Adding the id after creation should overwrite the automatic ID
''' """
r = Entry() r = Entry()
j = r.jsonld() j = r.jsonld()
assert '@id' in j assert '@id' in j
...@@ -94,8 +96,16 @@ class ModelsTest(TestCase): ...@@ -94,8 +96,16 @@ class ModelsTest(TestCase):
r.validate() r.validate()
def test_plugins(self): def test_plugins(self):
self.assertRaises(Error, SenpyPlugin) self.assertRaises(Error, plugins.Plugin)
p = SenpyPlugin({"name": "dummy", "version": 0}) p = plugins.Plugin({"name": "dummy",
"version": 0,
"extra_params": {
"none": {
"options": ["es", ],
"required": False,
"default": "0"
}
}})
c = p.jsonld() c = p.jsonld()
assert "info" not in c assert "info" not in c
assert "repo" not in c assert "repo" not in c
...@@ -103,11 +113,13 @@ class ModelsTest(TestCase): ...@@ -103,11 +113,13 @@ class ModelsTest(TestCase):
logging.debug("Framed:") logging.debug("Framed:")
logging.debug(c) logging.debug(c)
p.validate() p.validate()
assert "es" in c['extra_params']['none']['options']
assert isinstance(c['extra_params']['none']['options'], list)
def test_str(self): def test_str(self):
"""The string representation shouldn't include private variables""" """The string representation shouldn't include private variables"""
r = Results() r = Results()
p = SenpyPlugin({"name": "STR test", "version": 0}) p = plugins.Plugin({"name": "STR test", "version": 0})
p._testing = 0 p._testing = 0
s = str(p) s = str(p)
assert "_testing" not in s assert "_testing" not in s
...@@ -143,3 +155,15 @@ class ModelsTest(TestCase): ...@@ -143,3 +155,15 @@ class ModelsTest(TestCase):
print(t) print(t)
g = rdflib.Graph().parse(data=t, format='turtle') g = rdflib.Graph().parse(data=t, format='turtle')
assert len(g) == len(triples) assert len(g) == len(triples)
def test_single_plugin(self):
"""A response with a single plugin should still return a list"""
plugs = Plugins()
for i in range(10):
p = Plugin({'id': str(i),
'version': 0,
'description': 'dummy'})
plugs.plugins.append(p)
assert isinstance(plugs.plugins, list)
js = plugs.jsonld()
assert isinstance(js['plugins'], list)
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