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
703fb68b
Commit
703fb68b
authored
Dec 14, 2015
by
Ignacio Corcuera
Browse files
Merge branch 'master' of github.com:gsi-upm/senpy into nacho
parents
7b9f8a8b
6fe68e3c
Changes
3
Hide whitespace changes
Inline
Side-by-side
senpy/plugins.py
View file @
703fb68b
...
...
@@ -112,6 +112,9 @@ class SenpyPlugin(Leaf):
def
id
(
self
):
return
"{}_{}"
.
format
(
self
.
name
,
self
.
version
)
def
__del__
(
self
):
''' Destructor, to make sure all the resources are freed '''
self
.
deactivate
()
class
SentimentPlugin
(
SenpyPlugin
):
...
...
@@ -139,8 +142,8 @@ class ShelfMixin(object):
@
sh
.
deleter
def
sh
(
self
):
if
hasattr
(
self
,
'_sh'
):
del
(
self
.
_
sh
)
if
os
.
path
.
isfile
(
self
.
shelf_file
):
os
.
remove
(
self
.
sh
elf_file
)
@
property
def
shelf_file
(
self
):
...
...
setup.py
View file @
703fb68b
...
...
@@ -15,7 +15,7 @@ except AttributeError:
install_reqs
=
[
str
(
ir
.
req
)
for
ir
in
install_reqs
]
test_reqs
=
[
str
(
ir
.
req
)
for
ir
in
test_reqs
]
VERSION
=
"0.4.11
rc
"
VERSION
=
"0.4.11"
setup
(
name
=
'senpy'
,
...
...
tests/plugins_test/__init__.py
View file @
703fb68b
#!/bin/env python2
# -*- py-which-shell: "python2"; -*-
import
os
import
logging
import
shelve
...
...
@@ -13,29 +15,56 @@ from senpy.models import Response, Entry
from
senpy.plugins
import
SenpyPlugin
,
ShelfMixin
class
ShelfTest
(
ShelfMixin
,
SenpyPlugin
):
def
test
(
self
,
key
=
None
,
value
=
None
):
assert
isinstance
(
self
.
sh
,
shelve
.
Shelf
)
assert
key
in
self
.
sh
print
(
'Checking: sh[{}] == {}'
.
format
(
key
,
value
))
print
(
'SH[{}]: {}'
.
format
(
key
,
self
.
sh
[
key
]))
assert
self
.
sh
[
key
]
==
value
class
ModelsTest
(
TestCase
):
shelf_file
=
'shelf_test.db'
def
tearDown
(
self
):
if
os
.
path
.
isfile
(
self
.
shelf_file
):
os
.
remove
(
self
.
shelf_file
)
# def test_shelf(self):
# class ShelfTest(ShelfMixin):
# pass
# a = ShelfTest()
# print(type(a.sh))
# assert(False)
setUp
=
tearDown
def
test_shelf
(
self
):
class
ShelfTest
(
ShelfMixin
,
SenpyPlugin
):
pass
a
=
ShelfTest
({
'name'
:
'shelve'
,
'version'
:
'test'
})
print
(
type
(
a
.
sh
))
a
.
context
=
"ohno"
del
a
.
context
print
(
a
)
a
.
sh
[
'classifier'
]
=
{
'name'
:
'ohno'
}
assert
a
.
name
==
'shelve'
assert
isinstance
(
a
.
sh
,
shelve
.
Shelf
)
''' A shelf is created and the value is stored '''
a
=
ShelfTest
(
info
=
{
'name'
:
'shelve'
,
'version'
:
'test'
,
'shelf_file'
:
self
.
shelf_file
})
assert
a
.
sh
==
{}
assert
a
.
shelf_file
==
self
.
shelf_file
a
.
sh
[
'a'
]
=
'fromA'
a
.
test
(
key
=
'a'
,
value
=
'fromA'
)
del
(
a
)
assert
os
.
path
.
isfile
(
self
.
shelf_file
)
sh
=
shelve
.
open
(
self
.
shelf_file
)
assert
sh
[
'a'
]
==
'fromA'
def
test_two
(
self
):
''' Reusing the values of a previous shelf '''
a
=
ShelfTest
(
info
=
{
'name'
:
'shelve'
,
'version'
:
'test'
,
'shelf_file'
:
self
.
shelf_file
})
print
(
'Shelf file: %s'
%
a
.
shelf_file
)
a
.
sh
[
'a'
]
=
'fromA'
a
.
close
()
b
=
ShelfTest
({
'name'
:
'shelve'
,
'version'
:
'test'
})
assert
b
.
name
==
'shelve'
assert
b
.
sh
[
'classifier'
]
assert
b
.
sh
[
'classifier'
][
'name'
]
==
'ohno'
assert
isinstance
(
b
.
sh
,
shelve
.
Shelf
)
b
=
ShelfTest
(
info
=
{
'name'
:
'shelve'
,
'version'
:
'test'
,
'shelf_file'
:
self
.
shelf_file
})
b
.
test
(
key
=
'a'
,
value
=
'fromA'
)
b
.
sh
[
'a'
]
=
'fromB'
assert
b
.
sh
[
'a'
]
==
'fromB'
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