mirror of
https://github.com/gsi-upm/senpy
synced 2025-08-23 10:02:21 +00:00
Added random plugin and other features
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import os
|
||||
import logging
|
||||
|
||||
|
40
tests/context.jsonld
Normal file
40
tests/context.jsonld
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"dc": "http://purl.org/dc/terms/",
|
||||
"dc:subject": {
|
||||
"@type": "@id"
|
||||
},
|
||||
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
||||
"marl": "http://www.gsi.dit.upm.es/ontologies/marl/ns#",
|
||||
"nif": "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#",
|
||||
"onyx": "http://www.gsi.dit.upm.es/ontologies/onyx/ns#",
|
||||
"emotions": {
|
||||
"@container": "@set",
|
||||
"@id": "onyx:hasEmotionSet"
|
||||
},
|
||||
"opinions": {
|
||||
"@container": "@set",
|
||||
"@id": "marl:hasOpinion"
|
||||
},
|
||||
"prov": "http://www.w3.org/ns/prov#",
|
||||
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
||||
"analysis": {
|
||||
"@container": "@set",
|
||||
"@id": "prov:wasInformedBy"
|
||||
},
|
||||
"entries": {
|
||||
"@container": "@set",
|
||||
"@id": "prov:generated"
|
||||
},
|
||||
"strings": {
|
||||
"@container": "@set",
|
||||
"@reverse": "nif:hasContext"
|
||||
},
|
||||
"date":
|
||||
{
|
||||
"@id": "dc:date",
|
||||
"@type": "xsd:dateTime"
|
||||
},
|
||||
"text": { "@id": "nif:isString" },
|
||||
"wnaffect": "http://www.gsi.dit.upm.es/ontologies/wnaffect#",
|
||||
"xsd": "http://www.w3.org/2001/XMLSchema#"
|
||||
}
|
@@ -2,7 +2,5 @@ from senpy.plugins import SentimentPlugin
|
||||
from senpy.models import Response
|
||||
|
||||
class DummyPlugin(SentimentPlugin):
|
||||
pass
|
||||
|
||||
def analyse(self, *args, **kwargs):
|
||||
return Response()
|
@@ -52,11 +52,12 @@ class ExtensionsTest(TestCase):
|
||||
|
||||
def test_analyse(self):
|
||||
""" Using a plugin """
|
||||
with mock.patch.object(self.senpy.plugins["Dummy"], "analyse") as mocked:
|
||||
self.senpy.analyse(algorithm="Dummy", input="tupni", output="tuptuo")
|
||||
self.senpy.analyse(input="tupni", output="tuptuo")
|
||||
mocked.assert_any_call(input="tupni", output="tuptuo", algorithm="Dummy")
|
||||
mocked.assert_any_call(input="tupni", output="tuptuo")
|
||||
# I was using mock until plugin started inheriting Leaf (defaultdict with
|
||||
# __setattr__ and __getattr__.
|
||||
r1 = self.senpy.analyse(algorithm="Dummy", input="tupni", output="tuptuo")
|
||||
r2 = self.senpy.analyse(input="tupni", output="tuptuo")
|
||||
assert r1.analysis[0].id[:5] == "Dummy"
|
||||
assert r2.analysis[0].id[:5] == "Dummy"
|
||||
for plug in self.senpy.plugins:
|
||||
self.senpy.deactivate_plugin(plug, sync=True)
|
||||
resp = self.senpy.analyse(input="tupni")
|
||||
|
36
tests/models_test/__init__.py
Normal file
36
tests/models_test/__init__.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
try:
|
||||
import unittest.mock as mock
|
||||
except ImportError:
|
||||
import mock
|
||||
import json
|
||||
import os
|
||||
from unittest import TestCase
|
||||
from senpy.models import Response
|
||||
from senpy.plugins import SenpyPlugin
|
||||
|
||||
class ModelsTest(TestCase):
|
||||
def test_response(self):
|
||||
r = Response(context=os.path.normpath(os.path.join(__file__, "..", "..", "context.jsonld")))
|
||||
assert("@context" in r)
|
||||
assert("marl" in r.context)
|
||||
r2 = Response(context=json.loads('{"test": "roger"}'))
|
||||
assert("test" in r2.context)
|
||||
r3 = Response(context=None)
|
||||
del r3.context
|
||||
assert("@context" not in r3)
|
||||
assert("entries" in r3)
|
||||
assert("analysis" in r3)
|
||||
|
||||
def test_opinions(self):
|
||||
pass
|
||||
|
||||
def test_frame_plugin(self):
|
||||
p = SenpyPlugin({"name": "dummy", "version": 0})
|
||||
c = p.frame()
|
||||
assert "info" not in c
|
||||
|
||||
def test_frame_response(self):
|
||||
pass
|
@@ -1,4 +1,5 @@
|
||||
from senpy.plugins import SenpyPlugin
|
||||
from senpy.models import Response
|
||||
from time import sleep
|
||||
|
||||
class SleepPlugin(SenpyPlugin):
|
||||
@@ -8,3 +9,6 @@ class SleepPlugin(SenpyPlugin):
|
||||
|
||||
def activate(self, *args, **kwargs):
|
||||
sleep(self.timeout)
|
||||
|
||||
def analyse(self, *args, **kwargs):
|
||||
return Response()
|
||||
|
Reference in New Issue
Block a user