1
0
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:
J. Fernando Sánchez
2018-01-01 13:13:17 +01:00
parent f93eed2cf5
commit bfc588a915
35 changed files with 845 additions and 445 deletions

View File

@@ -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)