From f7571cb37fcfb854abc8174fc721f8b474191ff2 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Wed, 30 Sep 2015 09:01:09 +0300 Subject: [PATCH] Python 3: there's no __builtin__ module This caused an ImportError in a test module and showed up as one test failure. Now the test module can get imported and many more tests fail (on Python 3). Such is life. ;-) --- test/units/module_utils/test_basic.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/units/module_utils/test_basic.py b/test/units/module_utils/test_basic.py index 1a2fbefd438..faa14dbbb0a 100644 --- a/test/units/module_utils/test_basic.py +++ b/test/units/module_utils/test_basic.py @@ -20,10 +20,9 @@ from __future__ import (absolute_import, division) __metaclass__ = type -import __builtin__ import errno -from nose.tools import timed +from six.moves import builtins from ansible.compat.tests import unittest from ansible.compat.tests.mock import patch, MagicMock, mock_open, Mock @@ -37,16 +36,16 @@ class TestModuleUtilsBasic(unittest.TestCase): pass def test_module_utils_basic_imports(self): - realimport = __builtin__.__import__ + realimport = builtins.__import__ def _mock_import(name, *args, **kwargs): if name == 'json': raise ImportError() realimport(name, *args, **kwargs) - with patch.object(__builtin__, '__import__', _mock_import, create=True) as m: + with patch.object(builtins, '__import__', _mock_import, create=True) as m: m('ansible.module_utils.basic') - __builtin__.__import__('ansible.module_utils.basic') + builtins.__import__('ansible.module_utils.basic') def test_module_utils_basic_get_platform(self): with patch('platform.system', return_value='foo'): @@ -510,7 +509,7 @@ class TestModuleUtilsBasic(unittest.TestCase): m = mock_open() m.side_effect = OSError - with patch('__builtin__.open', m, create=True): + with patch.object(builtins, 'open', m, create=True): self.assertEqual(am.is_special_selinux_path('/some/path/that/should/be/nfs'), (False, None)) mount_data = [ @@ -524,7 +523,7 @@ class TestModuleUtilsBasic(unittest.TestCase): m = mock_open(read_data=''.join(mount_data)) m.return_value.readlines.return_value = mount_data - with patch('__builtin__.open', m, create=True): + with patch.object(builtins, 'open', m, create=True): self.assertEqual(am.is_special_selinux_path('/some/random/path'), (False, None)) self.assertEqual(am.is_special_selinux_path('/some/path/that/should/be/nfs'), (True, ['foo_u', 'foo_r', 'foo_t', 's0'])) self.assertEqual(am.is_special_selinux_path('/weird/random/fstype/path'), (True, ['foo_u', 'foo_r', 'foo_t', 's0']))