Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
senpy
senpy
Commits
603e0866
Commit
603e0866
authored
Mar 14, 2017
by
J. Fernando Sánchez
Browse files
Fix list of plugins
Closes
#17
parent
1a582c08
Changes
5
Hide whitespace changes
Inline
Side-by-side
senpy/plugins/__init__.py
View file @
603e0866
...
...
@@ -13,7 +13,7 @@ from .. import models
logger
=
logging
.
getLogger
(
__name__
)
class
Senpy
Plugin
(
models
.
Plugin
):
class
Plugin
(
models
.
Plugin
):
def
__init__
(
self
,
info
=
None
):
"""
Provides a canonical name for plugins and serves as base for other
...
...
@@ -24,7 +24,7 @@ class SenpyPlugin(models.Plugin):
"information for the plugin."
))
logger
.
debug
(
"Initialising {}"
.
format
(
info
))
id
=
'plugins/{}_{}'
.
format
(
info
[
'name'
],
info
[
'version'
])
super
(
Senpy
Plugin
,
self
).
__init__
(
id
=
id
,
**
info
)
super
(
Plugin
,
self
).
__init__
(
id
=
id
,
**
info
)
self
.
is_activated
=
False
def
get_folder
(
self
):
...
...
@@ -37,7 +37,10 @@ class SenpyPlugin(models.Plugin):
pass
class
AnalysisPlugin
(
SenpyPlugin
):
SenpyPlugin
=
Plugin
class
AnalysisPlugin
(
Plugin
):
def
analyse
(
self
,
*
args
,
**
kwargs
):
raise
NotImplemented
(
...
...
@@ -58,7 +61,7 @@ class AnalysisPlugin(SenpyPlugin):
yield
i
class
ConversionPlugin
(
Senpy
Plugin
):
class
ConversionPlugin
(
Plugin
):
pass
...
...
senpy/schemas/context.jsonld
View file @
603e0866
...
...
@@ -37,6 +37,9 @@
"@type": "@id",
"@container": "@set"
},
"plugins": {
"@container": "@list"
},
"prov:wasGeneratedBy": {
"@type": "@id"
},
...
...
senpy/schemas/plugins.json
View file @
603e0866
...
...
@@ -6,6 +6,7 @@
"properties"
:
{
"plugins"
:
{
"type"
:
"array"
,
"default"
:
[],
"items"
:
{
"$ref"
:
"plugin.json"
}
...
...
tests/plugins/sleep_plugin/sleep.py
View file @
603e0866
from
senpy.plugins
import
Senpy
Plugin
from
senpy.plugins
import
Analysis
Plugin
from
time
import
sleep
class
SleepPlugin
(
Senpy
Plugin
):
class
SleepPlugin
(
Analysis
Plugin
):
def
activate
(
self
,
*
args
,
**
kwargs
):
sleep
(
self
.
timeout
)
...
...
tests/test_models.py
View file @
603e0866
...
...
@@ -11,8 +11,10 @@ from senpy.models import (Emotion,
Entry
,
Error
,
Results
,
Sentiment
)
from
senpy.plugins
import
SenpyPlugin
Sentiment
,
Plugins
,
Plugin
)
from
senpy
import
plugins
from
pprint
import
pprint
...
...
@@ -53,8 +55,8 @@ class ModelsTest(TestCase):
assert
(
received
[
"entries"
][
0
][
"nif:isString"
]
!=
"Not testing"
)
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
()
j
=
r
.
jsonld
()
assert
'@id'
in
j
...
...
@@ -94,8 +96,8 @@ class ModelsTest(TestCase):
r
.
validate
()
def
test_plugins
(
self
):
self
.
assertRaises
(
Error
,
Senpy
Plugin
)
p
=
Senpy
Plugin
({
"name"
:
"dummy"
,
"version"
:
0
})
self
.
assertRaises
(
Error
,
plugins
.
Plugin
)
p
=
plugins
.
Plugin
({
"name"
:
"dummy"
,
"version"
:
0
})
c
=
p
.
jsonld
()
assert
"info"
not
in
c
assert
"repo"
not
in
c
...
...
@@ -107,7 +109,7 @@ class ModelsTest(TestCase):
def
test_str
(
self
):
"""The string representation shouldn't include private variables"""
r
=
Results
()
p
=
Senpy
Plugin
({
"name"
:
"STR test"
,
"version"
:
0
})
p
=
plugins
.
Plugin
({
"name"
:
"STR test"
,
"version"
:
0
})
p
.
_testing
=
0
s
=
str
(
p
)
assert
"_testing"
not
in
s
...
...
@@ -143,3 +145,15 @@ class ModelsTest(TestCase):
print
(
t
)
g
=
rdflib
.
Graph
().
parse
(
data
=
t
,
format
=
'turtle'
)
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
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment