* [gentoo-commits] proj/portage:master commit in: pym/portage/tests/unicode/
@ 2013-01-18 20:47 Zac Medico
0 siblings, 0 replies; only message in thread
From: Zac Medico @ 2013-01-18 20:47 UTC (permalink / raw
To: gentoo-commits
commit: 0d732def5d30b29ab2941f0c66919a3ec4e8eb02
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 18 20:46:51 2013 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Jan 18 20:46:51 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0d732def
test_string_format: use unicode_literals
---
pym/portage/tests/unicode/test_string_format.py | 51 +++++++++++------------
1 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/pym/portage/tests/unicode/test_string_format.py b/pym/portage/tests/unicode/test_string_format.py
index fb6e8e0..6723883 100644
--- a/pym/portage/tests/unicode/test_string_format.py
+++ b/pym/portage/tests/unicode/test_string_format.py
@@ -1,9 +1,11 @@
-# Copyright 2010 Gentoo Foundation
+# Copyright 2010-2013 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
@@ -20,27 +22,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 +52,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 +77,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 +86,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 +103,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)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-01-18 20:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-18 20:47 [gentoo-commits] proj/portage:master commit in: pym/portage/tests/unicode/ Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox