diff options
Diffstat (limited to 'pym/portage/tests/unicode/test_string_format.py')
-rw-r--r-- | pym/portage/tests/unicode/test_string_format.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/pym/portage/tests/unicode/test_string_format.py b/pym/portage/tests/unicode/test_string_format.py index fb6e8e02e..9d4366a91 100644 --- a/pym/portage/tests/unicode/test_string_format.py +++ b/pym/portage/tests/unicode/test_string_format.py @@ -1,15 +1,18 @@ -# Copyright 2010 Gentoo Foundation +# Copyright 2010-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import unicode_literals + import sys -from portage import _encodings, _unicode_decode +from portage import _encodings, _unicode_encode from portage.exception import PortageException from portage.tests import TestCase from _emerge.DependencyArg import DependencyArg from _emerge.UseFlagDisplay import UseFlagDisplay if sys.hexversion >= 0x3000000: + # pylint: disable=W0622 basestring = str STR_IS_UNICODE = sys.hexversion >= 0x3000000 @@ -20,27 +23,25 @@ class StringFormatTestCase(TestCase): which may be either python2 or python3. """ - # In order to get some unicode test strings in a way that works in - # both python2 and python3, write them here as byte strings and - # decode them before use. This assumes _encodings['content'] is - # utf_8. + # We need unicode_literals in order to get some unicode test strings + # in a way that works in both python2 and python3. unicode_strings = ( - b'\xE2\x80\x98', - b'\xE2\x80\x99', + '\u2018', + '\u2019', ) def testDependencyArg(self): self.assertEqual(_encodings['content'], 'utf_8') - for arg_bytes in self.unicode_strings: - arg_unicode = _unicode_decode(arg_bytes, encoding=_encodings['content']) + for arg_unicode in self.unicode_strings: + arg_bytes = _unicode_encode(arg_unicode, encoding=_encodings['content']) dependency_arg = DependencyArg(arg=arg_unicode) - # Force unicode format string so that __unicode__() is - # called in python2. - formatted_str = _unicode_decode("%s") % (dependency_arg,) + # Use unicode_literals for unicode format string so that + # __unicode__() is called in Python 2. + formatted_str = "%s" % (dependency_arg,) self.assertEqual(formatted_str, arg_unicode) if STR_IS_UNICODE: @@ -52,20 +53,20 @@ class StringFormatTestCase(TestCase): else: # Test the __str__ method which returns encoded bytes in python2 - formatted_bytes = "%s" % (dependency_arg,) + formatted_bytes = b"%s" % (dependency_arg,) self.assertEqual(formatted_bytes, arg_bytes) def testPortageException(self): self.assertEqual(_encodings['content'], 'utf_8') - for arg_bytes in self.unicode_strings: - arg_unicode = _unicode_decode(arg_bytes, encoding=_encodings['content']) + for arg_unicode in self.unicode_strings: + arg_bytes = _unicode_encode(arg_unicode, encoding=_encodings['content']) e = PortageException(arg_unicode) - # Force unicode format string so that __unicode__() is - # called in python2. - formatted_str = _unicode_decode("%s") % (e,) + # Use unicode_literals for unicode format string so that + # __unicode__() is called in Python 2. + formatted_str = "%s" % (e,) self.assertEqual(formatted_str, arg_unicode) if STR_IS_UNICODE: @@ -77,7 +78,7 @@ class StringFormatTestCase(TestCase): else: # Test the __str__ method which returns encoded bytes in python2 - formatted_bytes = "%s" % (e,) + formatted_bytes = b"%s" % (e,) self.assertEqual(formatted_bytes, arg_bytes) def testUseFlagDisplay(self): @@ -86,13 +87,12 @@ class StringFormatTestCase(TestCase): for enabled in (True, False): for forced in (True, False): - for arg_bytes in self.unicode_strings: - arg_unicode = _unicode_decode(arg_bytes, encoding=_encodings['content']) + for arg_unicode in self.unicode_strings: e = UseFlagDisplay(arg_unicode, enabled, forced) - # Force unicode format string so that __unicode__() is - # called in python2. - formatted_str = _unicode_decode("%s") % (e,) + # Use unicode_literals for unicode format string so that + # __unicode__() is called in Python 2. + formatted_str = "%s" % (e,) self.assertEqual(isinstance(formatted_str, basestring), True) if STR_IS_UNICODE: @@ -104,5 +104,5 @@ class StringFormatTestCase(TestCase): else: # Test the __str__ method which returns encoded bytes in python2 - formatted_bytes = "%s" % (e,) + formatted_bytes = b"%s" % (e,) self.assertEqual(isinstance(formatted_bytes, bytes), True) |