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

Change data loading logic. Bugs senpy.testing

parent 7a8abf18
...@@ -95,12 +95,22 @@ class Plugin(with_metaclass(PluginMeta, models.Plugin)): ...@@ -95,12 +95,22 @@ class Plugin(with_metaclass(PluginMeta, models.Plugin)):
self.id = 'plugins/{}_{}'.format(self['name'], self['version']) self.id = 'plugins/{}_{}'.format(self['name'], self['version'])
self.is_activated = False self.is_activated = False
self._lock = threading.Lock() self._lock = threading.Lock()
self.data_folder = data_folder or os.getcwd()
self._directory = os.path.abspath(os.path.dirname(inspect.getfile(self.__class__))) self._directory = os.path.abspath(os.path.dirname(inspect.getfile(self.__class__)))
self._data_paths = ['',
data_folder = data_folder or os.getcwd()
subdir = os.path.join(data_folder, self.name)
self._data_paths = [
data_folder,
subdir,
self._directory, self._directory,
os.path.join(self._directory, 'data'), os.path.join(self._directory, 'data'),
self.data_folder] ]
if os.path.exists(subdir):
data_folder = subdir
self.data_folder = data_folder
self._log = logging.getLogger('{}.{}'.format(__name__, self.name)) self._log = logging.getLogger('{}.{}'.format(__name__, self.name))
@property @property
......
...@@ -41,7 +41,7 @@ class Sentiment140Plugin(SentimentPlugin): ...@@ -41,7 +41,7 @@ class Sentiment140Plugin(SentimentPlugin):
To avoid calling the sentiment140 API, we will mock the results To avoid calling the sentiment140 API, we will mock the results
from requests. from requests.
''' '''
from senpy.test import patch_requests from senpy.testing import patch_requests
expected = {"data": [{"polarity": 4}]} expected = {"data": [{"polarity": 4}]}
with patch_requests(expected) as (request, response): with patch_requests(expected) as (request, response):
super(Sentiment140Plugin, self).test(*args, **kwargs) super(Sentiment140Plugin, self).test(*args, **kwargs)
......
from unittest import TestCase from unittest import TestCase
from senpy.test import patch_requests from senpy.testing import patch_requests
from senpy.client import Client from senpy.client import Client
from senpy.models import Results, Plugins, Error from senpy.models import Results, Plugins, Error
from senpy.plugins import AnalysisPlugin from senpy.plugins import AnalysisPlugin
......
...@@ -2,7 +2,7 @@ from unittest import TestCase ...@@ -2,7 +2,7 @@ from unittest import TestCase
import requests import requests
import json import json
from senpy.test import patch_requests from senpy.testing import patch_requests
from senpy.models import Results from senpy.models import Results
......
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