-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding plugin support * Adding an empty __init__.py
- Loading branch information
Showing
9 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
import sys | ||
import importlib | ||
|
||
class PluginLoader(object): | ||
folder_cache = [] | ||
|
||
def load_path(self, path): | ||
parent_dir = os.path.dirname(path) | ||
if parent_dir not in self.folder_cache: | ||
self.folder_cache.append(parent_dir) | ||
sys.path.append(parent_dir) | ||
|
||
def get_class(self, namespace_class): | ||
[namespace, class_name] = namespace_class.split('.') | ||
my_module = importlib.import_module(namespace) | ||
return getattr(my_module, class_name) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import imp | ||
import sys | ||
import pkgutil | ||
import importlib | ||
import unittest | ||
import os | ||
from datetime import timedelta, datetime | ||
from mock import patch, MagicMock | ||
from pokemongo_bot.plugin_loader import PluginLoader | ||
from pokemongo_bot.test.resources.plugin_fixture import FakeTask | ||
|
||
class PluginLoaderTest(unittest.TestCase): | ||
def setUp(self): | ||
self.plugin_loader = PluginLoader() | ||
|
||
def test_load_namespace_class(self): | ||
package_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'resources', 'plugin_fixture') | ||
self.plugin_loader.load_path(package_path) | ||
loaded_class = self.plugin_loader.get_class('plugin_fixture.FakeTask') | ||
self.assertEqual(loaded_class({}, {}).work(), 'FakeTask') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from fake_task import FakeTask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pokemongo_bot.cell_workers import BaseTask | ||
|
||
class FakeTask(BaseTask): | ||
def work(self): | ||
return 'FakeTask' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters