2017-04-04 09:53:11 +02:00
|
|
|
from mock import patch
|
|
|
|
from nose.tools import eq_
|
|
|
|
|
|
|
|
|
|
|
|
@patch('pkgutil.get_importer')
|
|
|
|
def test_load_from_pyinstaller(pkgutil_get_importer):
|
2018-08-02 23:30:18 +02:00
|
|
|
sample_toc = set(['pyexcel_io', 'pyexcel_xls', 'blah', 'test.dot.module'])
|
2017-04-04 09:53:11 +02:00
|
|
|
pkgutil_get_importer.return_value.toc = sample_toc
|
2017-04-23 00:10:37 +02:00
|
|
|
from lml.loader import scan_from_pyinstaller
|
2017-04-04 09:53:11 +02:00
|
|
|
module_names = scan_from_pyinstaller('pyexcel_', 'path')
|
|
|
|
expected = ['pyexcel_io', 'pyexcel_xls']
|
2018-08-02 23:30:18 +02:00
|
|
|
eq_(sorted(list(module_names)), sorted(expected))
|
|
|
|
|
|
|
|
|
|
|
|
@patch('pkgutil.get_importer')
|
|
|
|
def test_load_from_pyinstaller_with_regex(pkgutil_get_importer):
|
|
|
|
sample_toc = set(['pyexcel_io', 'pyexcel_xls', 'blah'])
|
|
|
|
pkgutil_get_importer.return_value.toc = sample_toc
|
|
|
|
from lml.loader import scan_from_pyinstaller
|
|
|
|
module_names = scan_from_pyinstaller('^.+cel_.+$', 'path')
|
|
|
|
expected = ['pyexcel_io', 'pyexcel_xls']
|
2017-04-04 09:53:11 +02:00
|
|
|
eq_(sorted(list(module_names)), sorted(expected))
|
|
|
|
|
|
|
|
|
|
|
|
@patch('pkgutil.get_importer')
|
|
|
|
@patch('pkgutil.iter_modules')
|
2017-04-23 00:10:37 +02:00
|
|
|
def test_load_plugins(pkgutil_iter_modules,
|
2017-04-04 09:53:11 +02:00
|
|
|
pkgutil_get_importer):
|
2017-04-23 00:10:37 +02:00
|
|
|
test_module_name = 'pyexcel_test'
|
2017-04-04 09:53:11 +02:00
|
|
|
sample_toc = set(['pyexcel_io'])
|
|
|
|
pkgutil_get_importer.return_value.toc = sample_toc
|
2017-04-23 00:10:37 +02:00
|
|
|
pkgutil_iter_modules.return_value = [('not used', test_module_name, True)]
|
|
|
|
from lml.loader import scan_plugins
|
|
|
|
scan_plugins('pyexcel_', '.', ['pyexcel_io'])
|
|
|
|
from lml.plugin import CACHED_PLUGIN_INFO
|
|
|
|
info = CACHED_PLUGIN_INFO['test_io'][0]
|
2017-05-23 10:00:10 +02:00
|
|
|
eq_(info.plugin_type, 'test_io')
|
2017-04-23 00:10:37 +02:00
|
|
|
eq_(info.absolute_import_path, 'pyexcel_test.x')
|
2017-04-04 09:53:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
@patch('pkgutil.get_importer')
|
|
|
|
@patch('pkgutil.iter_modules')
|
2017-04-23 00:10:37 +02:00
|
|
|
def test_load_plugins_without_pyinstaller(pkgutil_iter_modules,
|
2017-04-04 09:53:11 +02:00
|
|
|
pkgutil_get_importer):
|
2017-04-20 23:26:03 +02:00
|
|
|
test_module_name = 'pyexcel_test'
|
2017-04-04 09:53:11 +02:00
|
|
|
sample_toc = set()
|
|
|
|
pkgutil_get_importer.return_value.toc = sample_toc
|
2017-04-20 23:26:03 +02:00
|
|
|
# mock iter modules
|
|
|
|
pkgutil_iter_modules.return_value = [('not used', test_module_name, True)]
|
2017-04-23 00:10:37 +02:00
|
|
|
from lml.loader import scan_plugins
|
|
|
|
scan_plugins('pyexcel_', '.', ['pyexcel_io'])
|
|
|
|
from lml.plugin import CACHED_PLUGIN_INFO
|
|
|
|
info = CACHED_PLUGIN_INFO['test_io'][0]
|
2017-05-23 10:00:10 +02:00
|
|
|
eq_(info.plugin_type, 'test_io')
|
2017-04-23 00:10:37 +02:00
|
|
|
eq_(info.absolute_import_path, 'pyexcel_test.x')
|
2017-04-04 09:53:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
@patch('pkgutil.get_importer')
|
|
|
|
@patch('pkgutil.iter_modules')
|
2017-05-19 10:51:54 +02:00
|
|
|
@patch('lml.plugin._load_me_later')
|
2017-04-23 00:10:37 +02:00
|
|
|
def test_load_plugins_without_any_plugins(mocked_load_me_later,
|
2017-04-04 09:53:11 +02:00
|
|
|
pkgutil_iter_modules,
|
|
|
|
pkgutil_get_importer):
|
|
|
|
sample_toc = set()
|
|
|
|
pkgutil_get_importer.return_value.toc = sample_toc
|
|
|
|
pkgutil_iter_modules.return_value = []
|
2017-04-23 00:10:37 +02:00
|
|
|
from lml.loader import scan_plugins
|
|
|
|
scan_plugins('pyexcel_', '.', ['pyexcel_io'])
|
|
|
|
assert mocked_load_me_later.called is False
|
2017-04-04 09:53:11 +02:00
|
|
|
|
|
|
|
|
2017-05-30 09:59:18 +02:00
|
|
|
@patch('pkgutil.get_importer')
|
|
|
|
@patch('pkgutil.iter_modules')
|
|
|
|
@patch('lml.plugin._load_me_later')
|
|
|
|
def test_load_plugins_without_black_list(mocked_load_me_later,
|
|
|
|
pkgutil_iter_modules,
|
|
|
|
pkgutil_get_importer):
|
|
|
|
sample_toc = set()
|
|
|
|
pkgutil_get_importer.return_value.toc = sample_toc
|
|
|
|
pkgutil_iter_modules.return_value = []
|
|
|
|
from lml.loader import scan_plugins
|
|
|
|
scan_plugins('pyexcel_', '.')
|
|
|
|
assert mocked_load_me_later.called is False
|
|
|
|
|
|
|
|
|
2017-04-04 09:53:11 +02:00
|
|
|
@patch('pkgutil.get_importer')
|
|
|
|
@patch('pkgutil.iter_modules')
|
2017-05-19 10:51:54 +02:00
|
|
|
@patch('lml.plugin._load_me_later')
|
2017-04-23 00:10:37 +02:00
|
|
|
def test_load_plugins_import_error(mocked_load_me_later,
|
2017-04-04 09:53:11 +02:00
|
|
|
pkgutil_iter_modules,
|
|
|
|
pkgutil_get_importer):
|
|
|
|
sample_toc = set(['test_non_existent_module'])
|
|
|
|
pkgutil_get_importer.return_value.toc = sample_toc
|
|
|
|
pkgutil_iter_modules.return_value = [('not used', 'pyexcel_xls', False)]
|
2017-04-23 00:10:37 +02:00
|
|
|
from lml.loader import scan_plugins
|
|
|
|
scan_plugins('test_', '.', ['pyexcel_io'])
|
|
|
|
assert mocked_load_me_later.called is False
|