Fixed 2/3 compatibility issues in parsing/yaml/test_loader with six.
This commit is contained in:
parent
7e9292c755
commit
77cd7a6e89
1 changed files with 9 additions and 7 deletions
|
@ -20,6 +20,7 @@
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
from six import text_type, binary_type
|
||||||
from six.moves import StringIO
|
from six.moves import StringIO
|
||||||
from collections import Sequence, Set, Mapping
|
from collections import Sequence, Set, Mapping
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ from ansible.compat.tests.mock import patch
|
||||||
|
|
||||||
from ansible.parsing.yaml.loader import AnsibleLoader
|
from ansible.parsing.yaml.loader import AnsibleLoader
|
||||||
|
|
||||||
|
|
||||||
class TestAnsibleLoaderBasic(unittest.TestCase):
|
class TestAnsibleLoaderBasic(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -52,7 +54,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
||||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||||
data = loader.get_single_data()
|
data = loader.get_single_data()
|
||||||
self.assertEqual(data, u'Ansible')
|
self.assertEqual(data, u'Ansible')
|
||||||
self.assertIsInstance(data, unicode)
|
self.assertIsInstance(data, text_type)
|
||||||
|
|
||||||
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
||||||
|
|
||||||
|
@ -63,7 +65,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
||||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||||
data = loader.get_single_data()
|
data = loader.get_single_data()
|
||||||
self.assertEqual(data, u'Cafè Eñyei')
|
self.assertEqual(data, u'Cafè Eñyei')
|
||||||
self.assertIsInstance(data, unicode)
|
self.assertIsInstance(data, text_type)
|
||||||
|
|
||||||
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
||||||
|
|
||||||
|
@ -76,8 +78,8 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
||||||
data = loader.get_single_data()
|
data = loader.get_single_data()
|
||||||
self.assertEqual(data, {'webster': 'daniel', 'oed': 'oxford'})
|
self.assertEqual(data, {'webster': 'daniel', 'oed': 'oxford'})
|
||||||
self.assertEqual(len(data), 2)
|
self.assertEqual(len(data), 2)
|
||||||
self.assertIsInstance(data.keys()[0], unicode)
|
self.assertIsInstance(list(data.keys())[0], text_type)
|
||||||
self.assertIsInstance(data.values()[0], unicode)
|
self.assertIsInstance(list(data.values())[0], text_type)
|
||||||
|
|
||||||
# Beginning of the first key
|
# Beginning of the first key
|
||||||
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
||||||
|
@ -94,7 +96,7 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
||||||
data = loader.get_single_data()
|
data = loader.get_single_data()
|
||||||
self.assertEqual(data, [u'a', u'b'])
|
self.assertEqual(data, [u'a', u'b'])
|
||||||
self.assertEqual(len(data), 2)
|
self.assertEqual(len(data), 2)
|
||||||
self.assertIsInstance(data[0], unicode)
|
self.assertIsInstance(data[0], text_type)
|
||||||
|
|
||||||
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
self.assertEqual(data.ansible_pos, ('myfile.yml', 2, 17))
|
||||||
|
|
||||||
|
@ -204,10 +206,10 @@ class TestAnsibleLoaderPlay(unittest.TestCase):
|
||||||
|
|
||||||
def walk(self, data):
|
def walk(self, data):
|
||||||
# Make sure there's no str in the data
|
# Make sure there's no str in the data
|
||||||
self.assertNotIsInstance(data, str)
|
self.assertNotIsInstance(data, binary_type)
|
||||||
|
|
||||||
# Descend into various container types
|
# Descend into various container types
|
||||||
if isinstance(data, unicode):
|
if isinstance(data, text_type):
|
||||||
# strings are a sequence so we have to be explicit here
|
# strings are a sequence so we have to be explicit here
|
||||||
return
|
return
|
||||||
elif isinstance(data, (Sequence, Set)):
|
elif isinstance(data, (Sequence, Set)):
|
||||||
|
|
Loading…
Reference in a new issue