mirror of
https://github.com/gsi-upm/senpy
synced 2025-08-23 10:02:21 +00:00
Prefix handling and bug fixes
This commit is contained in:
@@ -6,7 +6,7 @@ import jsonschema
|
||||
import json
|
||||
import os
|
||||
from unittest import TestCase
|
||||
from senpy.models import Response, Entry, Results, Sentiment, EmotionSet, Error
|
||||
from senpy.models import Response, Entry, Results, Sentiment, EmotionSet, Emotion, Error
|
||||
from senpy.plugins import SenpyPlugin
|
||||
from pprint import pprint
|
||||
|
||||
@@ -15,20 +15,23 @@ class ModelsTest(TestCase):
|
||||
|
||||
def test_jsonld(self):
|
||||
ctx = os.path.normpath(os.path.join(__file__, "..", "..", "..", "senpy", "schemas", "context.jsonld"))
|
||||
prueba = {"@id": "test",
|
||||
prueba = {"id": "test",
|
||||
"analysis": [],
|
||||
"entries": []}
|
||||
r = Results(**prueba)
|
||||
|
||||
print("Response's context: ")
|
||||
pprint(r.context)
|
||||
|
||||
assert r.id == "test"
|
||||
|
||||
j = r.jsonld(with_context=True)
|
||||
print("As JSON:")
|
||||
pprint(j)
|
||||
assert("@context" in j)
|
||||
assert("marl" in j["@context"])
|
||||
assert("entries" in j["@context"])
|
||||
assert(j["@id"] == "test")
|
||||
assert "id" not in j
|
||||
|
||||
r6 = Results(**prueba)
|
||||
r6.entries.append(Entry({"@id":"ohno", "nif:isString":"Just testing"}))
|
||||
@@ -47,6 +50,18 @@ class ModelsTest(TestCase):
|
||||
assert(received["entries"][0]["nif:isString"] == "Just testing")
|
||||
assert(received["entries"][0]["nif:isString"] != "Not testing")
|
||||
|
||||
def test_id(self):
|
||||
''' Adding the id after creation should overwrite the automatic ID
|
||||
'''
|
||||
r = Entry()
|
||||
j = r.jsonld()
|
||||
assert '@id' in j
|
||||
r.id = "test"
|
||||
j2 = r.jsonld()
|
||||
assert j2['@id'] == 'test'
|
||||
assert 'id' not in j2
|
||||
|
||||
|
||||
def test_entries(self):
|
||||
e = Entry()
|
||||
self.assertRaises(jsonschema.ValidationError, e.validate)
|
||||
@@ -67,8 +82,6 @@ class ModelsTest(TestCase):
|
||||
self.assertRaises(jsonschema.ValidationError, e.validate)
|
||||
e.nif__anchorOf = "so much testing"
|
||||
e.prov__wasGeneratedBy = ""
|
||||
self.assertRaises(jsonschema.ValidationError, e.validate)
|
||||
e.onyx__hasEmotion = {}
|
||||
e.validate()
|
||||
|
||||
def test_results(self):
|
||||
@@ -79,9 +92,6 @@ class ModelsTest(TestCase):
|
||||
r.id = ":test_results"
|
||||
r.validate()
|
||||
|
||||
def test_sentiments(self):
|
||||
pass
|
||||
|
||||
def test_plugins(self):
|
||||
self.assertRaises(Error, SenpyPlugin)
|
||||
p = SenpyPlugin({"name": "dummy", "version": 0})
|
||||
|
Reference in New Issue
Block a user