mirror of
https://github.com/gsi-upm/senpy
synced 2025-11-06 10:08:16 +00:00
Several fixes
* Refactored BaseModel for efficiency
* Added plugin metaclass to keep track of plugin types
* Moved plugins to examples dir (in a previous commit)
* Simplified validation in parse_params
* Added convenience methods to mock requests in tests
* Changed help schema to use `.valid_parameters` instead of `.parameters`,
which was used in results to show parameters provided by the user.
* Improved UI
* Added basic parameters
* Fixed bugs in parameter handling
* Refactored and cleaned code
This commit is contained in:
@@ -12,8 +12,8 @@ from senpy.models import (Emotion,
|
||||
Error,
|
||||
Results,
|
||||
Sentiment,
|
||||
SentimentPlugin,
|
||||
Plugins,
|
||||
Plugin,
|
||||
from_string,
|
||||
from_dict)
|
||||
from senpy import plugins
|
||||
@@ -99,19 +99,19 @@ class ModelsTest(TestCase):
|
||||
|
||||
def test_plugins(self):
|
||||
self.assertRaises(Error, plugins.Plugin)
|
||||
p = plugins.Plugin({"name": "dummy",
|
||||
"description": "I do nothing",
|
||||
"version": 0,
|
||||
"extra_params": {
|
||||
"none": {
|
||||
"options": ["es", ],
|
||||
"required": False,
|
||||
"default": "0"
|
||||
}
|
||||
}})
|
||||
p = plugins.SentimentPlugin({"name": "dummy",
|
||||
"description": "I do nothing",
|
||||
"version": 0,
|
||||
"extra_params": {
|
||||
"none": {
|
||||
"options": ["es", ],
|
||||
"required": False,
|
||||
"default": "0"
|
||||
}
|
||||
}})
|
||||
c = p.jsonld()
|
||||
assert '@type' in c
|
||||
assert c['@type'] == 'plugin'
|
||||
assert c['@type'] == 'sentimentPlugin'
|
||||
assert 'info' not in c
|
||||
assert 'repo' not in c
|
||||
assert 'extra_params' in c
|
||||
@@ -173,13 +173,14 @@ class ModelsTest(TestCase):
|
||||
def test_single_plugin(self):
|
||||
"""A response with a single plugin should still return a list"""
|
||||
plugs = Plugins()
|
||||
p = Plugin({'id': str(1),
|
||||
'version': 0,
|
||||
'description': 'dummy'})
|
||||
p = SentimentPlugin({'id': str(1),
|
||||
'version': 0,
|
||||
'description': 'dummy'})
|
||||
plugs.plugins.append(p)
|
||||
assert isinstance(plugs.plugins, list)
|
||||
js = plugs.jsonld()
|
||||
assert isinstance(js['plugins'], list)
|
||||
assert js['plugins'][0]['@type'] == 'sentimentPlugin'
|
||||
|
||||
def test_from_string(self):
|
||||
results = {
|
||||
@@ -192,6 +193,7 @@ class ModelsTest(TestCase):
|
||||
}]
|
||||
}
|
||||
recovered = from_dict(results)
|
||||
assert recovered.id == results['@id']
|
||||
assert isinstance(recovered, Results)
|
||||
assert isinstance(recovered.entries[0], Entry)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user