Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51967 from twangboy/add_compat_tests
Add unit tests for _compat.py
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |