Merge pull request #15656 from abadger/ziploader-namespace

Fix ziploader for the cornercase of ansible invoking ansible.
This commit is contained in:
Toshio Kuratomi
2016-04-29 11:12:11 -07:00
11 changed files with 53 additions and 22 deletions

View File

@@ -33,7 +33,7 @@ try:
except ImportError:
import __builtin__ as builtins
from ansible import __version__ as ansible_version
from ansible.release import __version__ as ansible_version
from ansible import constants as C
from ansible.compat.six import text_type
from ansible.compat.tests import unittest

View File

@@ -53,11 +53,15 @@ class TestErrors(unittest.TestCase):
# python library, and then uses the __file__ attribute of
# the result for that to get the library path, so we mock
# that here and patch the builtin to use our mocked result
m = MagicMock()
m.return_value.__file__ = '/path/to/my/test.py'
foo = MagicMock()
bar = MagicMock()
bam = MagicMock()
bam.__file__ = '/path/to/my/foo/bar/bam/__init__.py'
bar.bam = bam
foo.return_value.bar = bar
pl = PluginLoader('test', 'foo.bar.bam', 'test', 'test_plugin')
with patch('{0}.__import__'.format(BUILTINS), m):
self.assertEqual(pl._get_package_paths(), ['/path/to/my/bar/bam'])
with patch('{0}.__import__'.format(BUILTINS), foo):
self.assertEqual(pl._get_package_paths(), ['/path/to/my/foo/bar/bam'])
def test_plugins__get_paths(self):
pl = PluginLoader('test', '', 'test', 'test_plugin')