def test_import_classes_failed_import_module(ns, mocker, recwarn): import importlib mocker.patch.object(importlib, 'import_module', side_effect=Exception('mocked error')) depend_tree = import_classes(namespace=ns) assert len(depend_tree) == 0 assert len(recwarn) == 1 assert 'You can use `jina check` to list all executors and drivers' in recwarn[ 0].message.args[0]
def test_import_classes_failed_load_default_exc_config(ns, print_table, mocker, recwarn, capsys): mocker.patch('pkg_resources.resource_stream', side_effect=Exception('mocked error')) _ = import_classes(namespace=ns, show_import_table=print_table) if print_table: captured = capsys.readouterr() assert '✗' in captured.out else: assert len(recwarn) == 1 assert 'You can use `jina check` to list all executors and drivers' in recwarn[ 0].message.args[0]
from jina.types.request import Request, Response from jina.types.message import Message from jina.types.querylang import QueryLang from jina.types.document import Document from jina.types.document.multimodal import MultimodalDocument from jina.types.sets import DocumentSet, QueryLangSet # ADD GLOBAL NAMESPACE VARIABLES JINA_GLOBAL = _types.SimpleNamespace() JINA_GLOBAL.logserver = _types.SimpleNamespace() import jina.importer as _ji # driver first, as executor may contain driver _ji.import_classes('jina.drivers', show_import_table=False, import_once=True) _ji.import_classes('jina.executors', show_import_table=False, import_once=True) _ji.import_classes('jina.hub', show_import_table=False, import_once=True) _signal.signal(_signal.SIGINT, _signal.default_int_handler) def _set_nofile(nofile_atleast=4096): """ sets nofile soft limit to at least 4096, useful for running matlplotlib/seaborn on parallel executing plot generators vs. Ubuntu default ulimit -n 1024 or OS X El Captian 256 temporary setting extinguishing with Python session. """ try: import resource as res
def test_import_classes_failed_find_package(ns, mocker): mocker.patch('pkgutil.get_loader', return_value=None) depend_tree = import_classes(namespace=ns) assert len(depend_tree) == 0
def test_import_classes_import_once_exception(import_once): with pytest.raises(TypeError): _ = import_classes(namespace='dummy', import_once=import_once)
def test_import_classes_import_once(ns, import_once): depend_tree = import_classes(namespace=ns, import_once=import_once) assert (not depend_tree) == import_once