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
d72a995f
Commit
d72a995f
authored
Dec 19, 2016
by
J. Fernando Sánchez
Browse files
New shelf location and better shelf tests
parent
40b67503
Changes
11
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
d72a995f
...
...
@@ -4,5 +4,4 @@
dist
build
README.html
__pycache__
Dockerfile-*
__pycache__
\ No newline at end of file
Dockerfile
0 → 120000
View file @
d72a995f
Dockerfile-3.4
\ No newline at end of file
Makefile
View file @
d72a995f
...
...
@@ -8,7 +8,7 @@ VERSION=$(shell cat $(NAME)/VERSION)
all
:
build run
dockerfiles
:
$(addprefix Dockerfile-
,
$(PYVERSIONS))
ln
-s
Dockerfile-
{
PYMAIN
}
Dockerfile
ln
-s
Dockerfile-
$(
PYMAIN
)
Dockerfile
Dockerfile-%
:
Dockerfile.template
sed
"s/{{PYVERSION}}/
$*
/"
Dockerfile.template
>
Dockerfile-
$*
...
...
@@ -24,8 +24,11 @@ test: $(addprefix test-,$(PYMAIN))
testall
:
$(addprefix test-
,
$(PYVERSIONS))
debug-%
:
build-%
docker run
--rm
-w
/usr/src/app/
-v
$$
PWD:/usr/src/app
--entrypoint
=
/bin/bash
-ti
'
$(REPO)
/
$(NAME)
:
$(VERSION)
-python$*'
;
test-%
:
build-%
docker run
--rm
-w
/usr/src/app/
--entrypoint
=
/usr/local/bin/python
-ti
'
$(REPO)
/
$(NAME)
:
$(VERSION)
-python$*'
setup.py
test
--addopts
"-vvv -s
--pdb
"
;
docker run
--rm
-w
/usr/src/app/
--entrypoint
=
/usr/local/bin/python
-ti
'
$(REPO)
/
$(NAME)
:
$(VERSION)
-python$*'
setup.py
test
--addopts
"-vvv -s"
;
dist/$(NAME)-$(VERSION).tar.gz
:
docker run
--rm
-ti
-v
$$
PWD:/usr/src/app/
-w
/usr/src/app/ python:
$(PYMAIN)
python setup.py sdist
;
...
...
@@ -38,7 +41,7 @@ pip_test-%: sdist
pip_test
:
$(addprefix pip_test-
,
$(PYVERSIONS))
upload-%
:
test-%
docker push
'
$(REPO)
/
$(NAME)
:
$(VERSION)
-python
$
(PYMAIN)
'
docker push
'
$(REPO)
/
$(NAME)
:
$(VERSION)
-python$
*
'
upload
:
testall $(addprefix upload-
,
$(PYVERSIONS))
docker tag
'
$(REPO)
/
$(NAME)
:
$(VERSION)
-python
$(PYMAIN)
'
'
$(REPO)
/
$(NAME)
:
$(VERSION)
'
...
...
senpy/VERSION
View file @
d72a995f
0.6.
1
0.6.
2
senpy/__init__.py
View file @
d72a995f
...
...
@@ -19,7 +19,8 @@ Sentiment analysis server in Python
"""
import
os
VFILE
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"VERSION"
)
with
open
(
VFILE
,
'r'
)
as
f
:
__version__
=
f
.
read
().
strip
()
from
.version
import
__version__
__all__
=
[
'api'
,
'blueprints'
,
'cli'
,
'extensions'
,
'models'
,
'plugins'
]
senpy/__main__.py
View file @
d72a995f
...
...
@@ -88,8 +88,9 @@ def main():
args
.
port
))
http_server
.
serve_forever
()
except
KeyboardInterrupt
:
http_server
.
stop
()
print
(
'Bye!'
)
http_server
.
stop
()
sp
.
deactivate_all
()
if
__name__
==
'__main__'
:
main
()
senpy/cli.py
View file @
d72a995f
...
...
@@ -47,4 +47,3 @@ def main():
if
__name__
==
'__main__'
:
main
()
senpy/plugins.py
View file @
d72a995f
...
...
@@ -5,6 +5,7 @@ import inspect
import
os.path
import
pickle
import
logging
import
tempfile
from
.models
import
Response
,
PluginModel
,
Error
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -83,7 +84,7 @@ class ShelfMixin(object):
if
hasattr
(
self
,
'_info'
)
and
'shelf_file'
in
self
.
_info
:
self
.
__dict__
[
'_shelf_file'
]
=
self
.
_info
[
'shelf_file'
]
else
:
self
.
_shelf_file
=
os
.
path
.
join
(
self
.
get_folde
r
(),
self
.
name
+
'.p'
)
self
.
_shelf_file
=
os
.
path
.
join
(
tempfile
.
gettempdi
r
(),
self
.
name
+
'.p'
)
return
self
.
_shelf_file
def
save
(
self
):
...
...
senpy/version.py
0 → 100644
View file @
d72a995f
import
os
with
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'VERSION'
))
as
f
:
__version__
=
f
.
read
().
strip
()
setup.py
View file @
d72a995f
...
...
@@ -15,8 +15,7 @@ except AttributeError:
install_reqs
=
[
str
(
ir
.
req
)
for
ir
in
install_reqs
]
test_reqs
=
[
str
(
ir
.
req
)
for
ir
in
test_reqs
]
with
open
(
'senpy/VERSION'
)
as
f
:
__version__
=
f
.
read
().
strip
()
from
senpy
import
__version__
setup
(
name
=
'senpy'
,
...
...
tests/test_plugins.py
View file @
d72a995f
...
...
@@ -9,22 +9,29 @@ import tempfile
import
json
import
os
from
unittest
import
TestCase
from
flask
import
Flask
from
senpy.models
import
Results
,
Entry
from
senpy.plugins
import
Sen
py
Plugin
,
ShelfMixin
from
senpy.plugins
import
Sen
timent
Plugin
,
ShelfMixin
class
ShelfDummyPlugin
(
SentimentPlugin
,
ShelfMixin
):
class
ShelfTest
(
ShelfMixin
,
SenpyPlugin
):
def
test
(
self
,
key
=
None
,
value
=
None
):
assert
key
in
self
.
sh
print
(
'Checking: sh[{}] == {}'
.
format
(
key
,
value
))
print
(
'SH[{}]: {}'
.
format
(
key
,
self
.
sh
[
key
]))
assert
self
.
sh
[
key
]
==
value
def
activate
(
self
,
*
args
,
**
kwargs
):
if
'counter'
not
in
self
.
sh
:
self
.
sh
[
'counter'
]
=
0
self
.
save
()
def
deactivate
(
self
,
*
args
,
**
kwargs
):
self
.
save
()
class
ModelsTest
(
TestCase
):
def
analyse
(
self
,
*
args
,
**
kwargs
):
self
.
sh
[
'counter'
]
=
self
.
sh
[
'counter'
]
+
1
e
=
Entry
()
e
.
nif__isString
=
self
.
sh
[
'counter'
]
r
=
Results
()
r
.
entries
.
append
(
e
)
return
r
class
PluginsTest
(
TestCase
):
def
tearDown
(
self
):
if
os
.
path
.
exists
(
self
.
shelf_dir
):
...
...
@@ -37,16 +44,26 @@ class ModelsTest(TestCase):
self
.
shelf_dir
=
tempfile
.
mkdtemp
()
self
.
shelf_file
=
os
.
path
.
join
(
self
.
shelf_dir
,
"shelf"
)
def
test_shelf_file
(
self
):
a
=
ShelfDummyPlugin
(
info
=
{
'name'
:
'default_shelve_file'
,
'version'
:
'test'
})
assert
os
.
path
.
dirname
(
a
.
shelf_file
)
==
tempfile
.
gettempdir
()
a
.
activate
()
assert
os
.
path
.
isfile
(
a
.
shelf_file
)
os
.
remove
(
a
.
shelf_file
)
def
test_shelf
(
self
):
''' A shelf is created and the value is stored '''
a
=
Shelf
Test
(
info
=
{
'name'
:
'shelve'
,
a
=
Shelf
DummyPlugin
(
info
=
{
'name'
:
'shelve'
,
'version'
:
'test'
,
'shelf_file'
:
self
.
shelf_file
})
assert
a
.
sh
==
{}
a
.
activate
()
assert
a
.
sh
==
{
'counter'
:
0
}
assert
a
.
shelf_file
==
self
.
shelf_file
a
.
sh
[
'a'
]
=
'fromA'
a
.
test
(
key
=
'a'
,
value
=
'fromA'
)
a
ssert
a
.
sh
[
'a'
]
==
'fromA'
a
.
save
()
...
...
@@ -54,19 +71,31 @@ class ModelsTest(TestCase):
assert
sh
[
'a'
]
==
'fromA'
def
test_dummy_shelf
(
self
):
a
=
ShelfDummyPlugin
(
info
=
{
'name'
:
'DummyShelf'
,
'shelf_file'
:
self
.
shelf_file
,
'version'
:
'test'
})
a
.
activate
()
res1
=
a
.
analyse
(
input
=
1
)
assert
res1
.
entries
[
0
].
nif__isString
==
1
res2
=
a
.
analyse
(
input
=
1
)
assert
res2
.
entries
[
0
].
nif__isString
==
2
def
test_two
(
self
):
''' Reusing the values of a previous shelf '''
a
=
Shelf
Test
(
info
=
{
'name'
:
'shelve'
,
a
=
Shelf
DummyPlugin
(
info
=
{
'name'
:
'shelve'
,
'version'
:
'test'
,
'shelf_file'
:
self
.
shelf_file
})
a
.
activate
()
print
(
'Shelf file: %s'
%
a
.
shelf_file
)
a
.
sh
[
'a'
]
=
'fromA'
a
.
save
()
b
=
Shelf
Test
(
info
=
{
'name'
:
'shelve'
,
b
=
Shelf
DummyPlugin
(
info
=
{
'name'
:
'shelve'
,
'version'
:
'test'
,
'shelf_file'
:
self
.
shelf_file
})
b
.
test
(
key
=
'a'
,
value
=
'fromA'
)
b
.
activate
()
assert
b
.
sh
[
'a'
]
==
'fromA'
b
.
sh
[
'a'
]
=
'fromB'
assert
b
.
sh
[
'a'
]
==
'fromB'
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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