Remove obsolete unit test builtins compat.

pull/77118/head
Matt Clay 3 years ago
parent 2cd6cdc6a7
commit b613808277

@ -1,33 +0,0 @@
# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
#
# Compat for python2.7
#
# One unittest needs to import builtins via __import__() so we need to have
# the string that represents it
try:
import __builtin__
except ImportError:
BUILTINS = 'builtins'
else:
BUILTINS = '__builtin__'

@ -21,7 +21,6 @@ __metaclass__ = type
from units.compat import unittest from units.compat import unittest
from units.compat.builtins import BUILTINS
from units.compat.mock import mock_open, patch from units.compat.mock import mock_open, patch
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject
@ -87,7 +86,7 @@ class TestErrors(unittest.TestCase):
m = mock_open() m = mock_open()
m.return_value.readlines.return_value = ['this is line 1\n'] m.return_value.readlines.return_value = ['this is line 1\n']
with patch('{0}.open'.format(BUILTINS), m): with patch('builtins.open', m):
# this line will be found in the file # this line will be found in the file
self.obj.ansible_pos = ('foo.yml', 1, 1) self.obj.ansible_pos = ('foo.yml', 1, 1)
e = AnsibleError(self.message, self.obj) e = AnsibleError(self.message, self.obj)
@ -110,7 +109,7 @@ class TestErrors(unittest.TestCase):
m = mock_open() m = mock_open()
m.return_value.readlines.return_value = ['this line has unicode \xf0\x9f\x98\xa8 in it!\n'] m.return_value.readlines.return_value = ['this line has unicode \xf0\x9f\x98\xa8 in it!\n']
with patch('{0}.open'.format(BUILTINS), m): with patch('builtins.open', m):
# this line will be found in the file # this line will be found in the file
self.obj.ansible_pos = ('foo.yml', 1, 1) self.obj.ansible_pos = ('foo.yml', 1, 1)
e = AnsibleError(self.unicode_message, self.obj) e = AnsibleError(self.unicode_message, self.obj)
@ -125,7 +124,7 @@ class TestErrors(unittest.TestCase):
m = mock_open() m = mock_open()
m.return_value.readlines.return_value = ['this is line 1\n', 'this is line 2\n', 'this is line 3\n'] m.return_value.readlines.return_value = ['this is line 1\n', 'this is line 2\n', 'this is line 3\n']
with patch('{0}.open'.format(BUILTINS), m): with patch('builtins.open', m):
# If the error occurs in the last line of the file, use the correct index to get the line # If the error occurs in the last line of the file, use the correct index to get the line
# and avoid the IndexError # and avoid the IndexError
self.obj.ansible_pos = ('foo.yml', 4, 1) self.obj.ansible_pos = ('foo.yml', 4, 1)
@ -141,7 +140,7 @@ class TestErrors(unittest.TestCase):
m = mock_open() m = mock_open()
m.return_value.readlines.return_value = ['this is line 1\n', 'this is line 2\n', 'this is line 3\n', ' \n', ' \n', ' '] m.return_value.readlines.return_value = ['this is line 1\n', 'this is line 2\n', 'this is line 3\n', ' \n', ' \n', ' ']
with patch('{0}.open'.format(BUILTINS), m): with patch('builtins.open', m):
self.obj.ansible_pos = ('foo.yml', 5, 1) self.obj.ansible_pos = ('foo.yml', 5, 1)
e = AnsibleError(self.message, self.obj) e = AnsibleError(self.message, self.obj)
self.assertEqual( self.assertEqual(

@ -23,7 +23,6 @@ __metaclass__ = type
import os import os
from units.compat import unittest from units.compat import unittest
from units.compat.builtins import BUILTINS
from units.compat.mock import patch, MagicMock from units.compat.mock import patch, MagicMock
from ansible.plugins.loader import PluginLoader, PluginPathContext from ansible.plugins.loader import PluginLoader, PluginPathContext
@ -54,7 +53,7 @@ class TestErrors(unittest.TestCase):
bar.bam = bam bar.bam = bam
foo.return_value.bar = bar foo.return_value.bar = bar
pl = PluginLoader('test', 'foo.bar.bam', 'test', 'test_plugin') pl = PluginLoader('test', 'foo.bar.bam', 'test', 'test_plugin')
with patch('{0}.__import__'.format(BUILTINS), foo): with patch('builtins.__import__', foo):
self.assertEqual(pl._get_package_paths(), ['/path/to/my/foo/bar/bam']) self.assertEqual(pl._get_package_paths(), ['/path/to/my/foo/bar/bam'])
def test_plugins__get_paths(self): def test_plugins__get_paths(self):

Loading…
Cancel
Save