예제 #1
0
def test_path_hook_importerror():
    # ensure that AnsiblePathHookFinder.find_module swallows ImportError from path hook delegation on Py3, eg if the delegated
    # path hook gets passed a file on sys.path (python36.zip)
    reset_collections_loader_state()
    path_to_a_file = os.path.join(default_test_collection_paths[0], 'ansible_collections/testns/testcoll/plugins/action/my_action.py')
    # it's a bug if the following pops an ImportError...
    assert _AnsiblePathHookFinder(_AnsibleCollectionFinder(), path_to_a_file).find_module('foo.bar.my_action') is None
예제 #2
0
def test_find_module_py3():
    dir_to_a_file = os.path.dirname(ping_module.__file__)
    path_hook_finder = _AnsiblePathHookFinder(_AnsibleCollectionFinder(), dir_to_a_file)

    # setuptools may fall back to find_module on Python 3 if find_spec returns None
    # see https://github.com/pypa/setuptools/pull/2918
    assert path_hook_finder.find_spec('missing') is None
    assert path_hook_finder.find_module('missing') is None
예제 #3
0
def test_path_hook_setup():
    with patch.object(sys, 'path_hooks', []):
        found_hook = None
        pathhook_exc = None
        try:
            found_hook = _AnsiblePathHookFinder._get_filefinder_path_hook()
        except Exception as phe:
            pathhook_exc = phe

        if PY3:
            assert str(pathhook_exc) == 'need exactly one FileFinder import hook (found 0)'
        else:
            assert found_hook is None

    assert repr(_AnsiblePathHookFinder(object(), '/bogus/path')) == "_AnsiblePathHookFinder(path='/bogus/path')"