Use io.StringIO and io.BytesIO instead of StringIO.StringIO for compat with py3

This commit is contained in:
Toshio Kuratomi 2016-02-26 16:42:18 -08:00
parent c29f51804b
commit b70bf3b056
8 changed files with 38 additions and 27 deletions

View file

@ -22,16 +22,16 @@ __metaclass__ = type
import errno
import sys
import time
from io import BytesIO
from ansible.compat.tests import unittest
from ansible.compat.six import StringIO, BytesIO
from ansible.compat.tests.mock import call, MagicMock, Mock, patch, sentinel
from ansible.module_utils import basic
from ansible.module_utils.basic import AnsibleModule
class OpenStringIO(StringIO):
"""StringIO with dummy close() method
class OpenBytesIO(BytesIO):
"""BytesIO with dummy close() method
So that you can inspect the content after close() was called.
"""
@ -77,7 +77,7 @@ class TestAnsibleModuleRunCommand(unittest.TestCase):
self.subprocess = patch('ansible.module_utils.basic.subprocess').start()
self.cmd = Mock()
self.cmd.returncode = 0
self.cmd.stdin = OpenStringIO()
self.cmd.stdin = OpenBytesIO()
self.cmd.stdout.fileno.return_value = sentinel.stdout
self.cmd.stderr.fileno.return_value = sentinel.stderr
self.subprocess.Popen.return_value = self.cmd