mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Use io.StringIO and io.BytesIO instead of StringIO.StringIO for compat with py3
This commit is contained in:
parent
c29f51804b
commit
b70bf3b056
8 changed files with 38 additions and 27 deletions
|
@ -20,8 +20,9 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from io import StringIO
|
||||
|
||||
from six import text_type, binary_type
|
||||
from six.moves import StringIO
|
||||
from collections import Sequence, Set, Mapping
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
|
@ -44,7 +45,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
pass
|
||||
|
||||
def test_parse_number(self):
|
||||
stream = StringIO("""
|
||||
stream = StringIO(u"""
|
||||
1
|
||||
""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
|
@ -53,7 +54,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
# No line/column info saved yet
|
||||
|
||||
def test_parse_string(self):
|
||||
stream = StringIO("""
|
||||
stream = StringIO(u"""
|
||||
Ansible
|
||||
""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
|
@ -64,7 +65,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
||||
|
||||
def test_parse_utf8_string(self):
|
||||
stream = StringIO("""
|
||||
stream = StringIO(u"""
|
||||
Cafè Eñyei
|
||||
""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
|
@ -75,7 +76,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
||||
|
||||
def test_parse_dict(self):
|
||||
stream = StringIO("""
|
||||
stream = StringIO(u"""
|
||||
webster: daniel
|
||||
oed: oxford
|
||||
""")
|
||||
|
@ -93,7 +94,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
self.assertEqual(data[u'oed'].ansible_pos, ('myfile.yml', 3, 22))
|
||||
|
||||
def test_parse_list(self):
|
||||
stream = StringIO("""
|
||||
stream = StringIO(u"""
|
||||
- a
|
||||
- b
|
||||
""")
|
||||
|
@ -109,7 +110,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
self.assertEqual(data[1].ansible_pos, ('myfile.yml', 3, 19))
|
||||
|
||||
def test_parse_short_dict(self):
|
||||
stream = StringIO("""{"foo": "bar"}""")
|
||||
stream = StringIO(u"""{"foo": "bar"}""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
data = loader.get_single_data()
|
||||
self.assertEqual(data, dict(foo=u'bar'))
|
||||
|
@ -117,7 +118,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
self.assertEqual(data.ansible_pos, ('myfile.yml', 1, 1))
|
||||
self.assertEqual(data[u'foo'].ansible_pos, ('myfile.yml', 1, 9))
|
||||
|
||||
stream = StringIO("""foo: bar""")
|
||||
stream = StringIO(u"""foo: bar""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
data = loader.get_single_data()
|
||||
self.assertEqual(data, dict(foo=u'bar'))
|
||||
|
@ -126,12 +127,12 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
self.assertEqual(data[u'foo'].ansible_pos, ('myfile.yml', 1, 6))
|
||||
|
||||
def test_error_conditions(self):
|
||||
stream = StringIO("""{""")
|
||||
stream = StringIO(u"""{""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
self.assertRaises(ParserError, loader.get_single_data)
|
||||
|
||||
def test_front_matter(self):
|
||||
stream = StringIO("""---\nfoo: bar""")
|
||||
stream = StringIO(u"""---\nfoo: bar""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
data = loader.get_single_data()
|
||||
self.assertEqual(data, dict(foo=u'bar'))
|
||||
|
@ -140,7 +141,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
self.assertEqual(data[u'foo'].ansible_pos, ('myfile.yml', 2, 6))
|
||||
|
||||
# Initial indent (See: #6348)
|
||||
stream = StringIO(""" - foo: bar\n baz: qux""")
|
||||
stream = StringIO(u""" - foo: bar\n baz: qux""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
data = loader.get_single_data()
|
||||
self.assertEqual(data, [{u'foo': u'bar', u'baz': u'qux'}])
|
||||
|
@ -154,7 +155,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
class TestAnsibleLoaderPlay(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
stream = StringIO("""
|
||||
stream = StringIO(u"""
|
||||
- hosts: localhost
|
||||
vars:
|
||||
number: 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue