Commit b8993f7d authored by J. Fernando Sánchez's avatar J. Fernando Sánchez
Browse files

Added shelve mixin

parent bd2e0f0d
......@@ -71,7 +71,10 @@ class Leaf(dict):
return id
def __delattr__(self, key):
return super(Leaf, self).__delitem__(self._get_key(key))
if key in self.__dict__:
del self.__dict__[key]
super(Leaf, self).__delitem__(self._get_key(key))
def _get_key(self, key):
if key[0] == "_":
import inspect
import os.path
import shelve
import logging
import ConfigParser
from .models import Response, Leaf
......@@ -85,6 +88,9 @@ class SenpyPlugin(Leaf):
self.is_activated = False
self._info = info
def get_folder(self):
return os.path.dirname(inspect.getfile(self.__class__))
def analyse(self, *args, **kwargs):
logger.debug("Analysing with: {} {}".format(, self.version))
......@@ -121,3 +127,29 @@ class EmotionPlugin(SenpyPlugin):
resp = super(EmotionPlugin, self).__init__(info, *args, **kwargs)
self.minEmotionValue = float(info.get("minEmotionValue", 0))
self.maxEmotionValue = float(info.get("maxEmotionValue", 0))
class ShelfMixin(object):
def sh(self):
if not hasattr(self, '_sh') or not self._sh:
self._sh =, writeback=True)
return self._sh
def sh(self):
if hasattr(self, '_sh'):
def shelf_file(self):
if not hasattr(self, '_shelf_file') or not self._shelf_file:
if hasattr(self, '_info') and 'shelf_file' in self._info:
self._shelf_file = self._info['shelf_file']
self._shelf_file = os.path.join(self.get_folder(), + '.db')
return self._shelf_file
def close(self):
import os
import logging
import shelve
import unittest.mock as mock
except ImportError:
import mock
import json
import os
from unittest import TestCase
from senpy.models import Response, Entry
from senpy.plugins import SenpyPlugin, ShelfMixin
class ModelsTest(TestCase):
# def test_shelf(self):
# class ShelfTest(ShelfMixin):
# pass
# a = ShelfTest()
# print(type(
# assert(False)
def test_shelf(self):
class ShelfTest(ShelfMixin, SenpyPlugin):
a = ShelfTest({'name': 'shelve', 'version': 'test'})
a.context = "ohno"
del a.context
print(a)['classifier'] = {'name': 'ohno'}
assert == 'shelve'
assert isinstance(, shelve.Shelf)
b = ShelfTest({'name': 'shelve', 'version': 'test'})
assert == 'shelve'
assert['classifier']['name'] == 'ohno'
assert isinstance(, shelve.Shelf)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment