mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #51967 from twangboy/add_compat_tests
Add unit tests for _compat.py
This commit is contained in:
commit
2ebfa22f87
1 changed files with 71 additions and 0 deletions
71
tests/unit/test__compat.py
Normal file
71
tests/unit/test__compat.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Unit tests for salt._compat
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import sys
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
# Import Salt libs
|
||||
import salt._compat as compat
|
||||
|
||||
# Import 3rd Party libs
|
||||
from salt.ext.six import binary_type, text_type
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
PY3 = sys.version_info.major == 3
|
||||
|
||||
|
||||
class CompatTestCase(TestCase):
|
||||
def test_text(self):
|
||||
ret = compat.text_('test string')
|
||||
self.assertTrue(isinstance(ret, text_type))
|
||||
|
||||
def test_text_binary(self):
|
||||
ret = compat.text_(b'test string')
|
||||
self.assertTrue(isinstance(ret, text_type))
|
||||
|
||||
def test_bytes(self):
|
||||
ret = compat.bytes_('test string')
|
||||
self.assertTrue(isinstance(ret, binary_type))
|
||||
|
||||
def test_bytes_binary(self):
|
||||
ret = compat.bytes_(b'test string')
|
||||
self.assertTrue(isinstance(ret, binary_type))
|
||||
|
||||
def test_ascii_native(self):
|
||||
ret = compat.ascii_native_('test string')
|
||||
self.assertTrue(isinstance(ret, str))
|
||||
|
||||
def test_ascii_native_binary(self):
|
||||
ret = compat.ascii_native_(b'test string')
|
||||
self.assertTrue(isinstance(ret, str))
|
||||
|
||||
def test_native(self):
|
||||
ret = compat.native_('test string')
|
||||
self.assertTrue(isinstance(ret, str))
|
||||
|
||||
def test_native_binary(self):
|
||||
ret = compat.native_(b'test string')
|
||||
self.assertTrue(isinstance(ret, str))
|
||||
|
||||
def test_string_io(self):
|
||||
ret = compat.string_io('test string')
|
||||
if PY3:
|
||||
expected = 'io.StringIO object'
|
||||
else:
|
||||
expected = 'cStringIO.StringI object'
|
||||
self.assertTrue(expected in repr(ret))
|
||||
|
||||
def test_string_io_unicode(self):
|
||||
ret = compat.string_io(u'test string \xf8')
|
||||
if PY3:
|
||||
expected = 'io.StringIO object'
|
||||
else:
|
||||
expected = 'StringIO.StringIO instance'
|
||||
self.assertTrue(expected in repr(ret))
|
Loading…
Add table
Reference in a new issue