mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-22 16:12:29 +00:00
Fixes #3
This commit is contained in:
parent
82496dc8e4
commit
6fe68e3c40
@ -112,6 +112,9 @@ class SenpyPlugin(Leaf):
|
|||||||
def id(self):
|
def id(self):
|
||||||
return "{}_{}".format(self.name, self.version)
|
return "{}_{}".format(self.name, self.version)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
''' Destructor, to make sure all the resources are freed '''
|
||||||
|
self.deactivate()
|
||||||
|
|
||||||
class SentimentPlugin(SenpyPlugin):
|
class SentimentPlugin(SenpyPlugin):
|
||||||
|
|
||||||
@ -139,8 +142,8 @@ class ShelfMixin(object):
|
|||||||
|
|
||||||
@sh.deleter
|
@sh.deleter
|
||||||
def sh(self):
|
def sh(self):
|
||||||
if hasattr(self, '_sh'):
|
if os.path.isfile(self.shelf_file):
|
||||||
del(self._sh)
|
os.remove(self.shelf_file)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def shelf_file(self):
|
def shelf_file(self):
|
||||||
|
2
setup.py
2
setup.py
@ -15,7 +15,7 @@ except AttributeError:
|
|||||||
install_reqs = [str(ir.req) for ir in install_reqs]
|
install_reqs = [str(ir.req) for ir in install_reqs]
|
||||||
test_reqs = [str(ir.req) for ir in test_reqs]
|
test_reqs = [str(ir.req) for ir in test_reqs]
|
||||||
|
|
||||||
VERSION = "0.4.11rc"
|
VERSION = "0.4.11"
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='senpy',
|
name='senpy',
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#!/bin/env python2
|
||||||
|
# -*- py-which-shell: "python2"; -*-
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import shelve
|
import shelve
|
||||||
@ -13,29 +15,56 @@ from senpy.models import Response, Entry
|
|||||||
from senpy.plugins import SenpyPlugin, ShelfMixin
|
from senpy.plugins import SenpyPlugin, ShelfMixin
|
||||||
|
|
||||||
|
|
||||||
class ModelsTest(TestCase):
|
class ShelfTest(ShelfMixin, SenpyPlugin):
|
||||||
|
|
||||||
# def test_shelf(self):
|
def test(self, key=None, value=None):
|
||||||
# class ShelfTest(ShelfMixin):
|
assert isinstance(self.sh, shelve.Shelf)
|
||||||
# pass
|
assert key in self.sh
|
||||||
# a = ShelfTest()
|
print('Checking: sh[{}] == {}'.format(key, value))
|
||||||
# print(type(a.sh))
|
print('SH[{}]: {}'.format(key, self.sh[key]))
|
||||||
# assert(False)
|
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)
|
||||||
|
|
||||||
|
setUp = tearDown
|
||||||
|
|
||||||
def test_shelf(self):
|
def test_shelf(self):
|
||||||
class ShelfTest(ShelfMixin, SenpyPlugin):
|
''' A shelf is created and the value is stored '''
|
||||||
pass
|
a = ShelfTest(info={'name': 'shelve',
|
||||||
a = ShelfTest({'name': 'shelve', 'version': 'test'})
|
'version': 'test',
|
||||||
print(type(a.sh))
|
'shelf_file': self.shelf_file})
|
||||||
a.context = "ohno"
|
assert a.sh == {}
|
||||||
del a.context
|
assert a.shelf_file == self.shelf_file
|
||||||
print(a)
|
|
||||||
a.sh['classifier'] = {'name': 'ohno'}
|
a.sh['a'] = 'fromA'
|
||||||
assert a.name == 'shelve'
|
|
||||||
assert isinstance(a.sh, shelve.Shelf)
|
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()
|
a.close()
|
||||||
b = ShelfTest({'name': 'shelve', 'version': 'test'})
|
|
||||||
assert b.name == 'shelve'
|
b = ShelfTest(info={'name': 'shelve',
|
||||||
assert b.sh['classifier']
|
'version': 'test',
|
||||||
assert b.sh['classifier']['name'] == 'ohno'
|
'shelf_file': self.shelf_file})
|
||||||
assert isinstance(b.sh, shelve.Shelf)
|
b.test(key='a', value='fromA')
|
||||||
|
b.sh['a'] = 'fromB'
|
||||||
|
assert b.sh['a'] == 'fromB'
|
||||||
|
Loading…
Reference in New Issue
Block a user