[PATCH 3/4] Python 3 compatibility fixes for the Unicode test
Vratislav Podzimek
vpodzime at redhat.com
Mon Mar 30 15:31:43 UTC 2015
On Mon, 2015-03-30 at 16:01 +0200, Jiří Konečný wrote:
> On Mon, 2015-03-30 at 15:38 +0200, Martin Kolman wrote:
> > Signed-off-by: Martin Kolman <mkolman at redhat.com>
> > ---
> > tests/handle_unicode.py | 11 +++++++++--
> > 1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/tests/handle_unicode.py b/tests/handle_unicode.py
> > index 971ead6..3ff4ca9 100644
> > --- a/tests/handle_unicode.py
> > +++ b/tests/handle_unicode.py
> > @@ -1,5 +1,6 @@
> > # -*- coding: utf-8 -*-
> > import tempfile
> > +import six
> >
> > from tests.baseclass import BaseTestCase
> > from meh import Config
> > @@ -19,7 +20,10 @@ class UnicodeExample(object):
> > class HandleUnicode_TestCase(BaseTestCase):
> > def setUp(self):
> > # write UTF-8 and ASCII files for testing
> > - (fobj, self.uni_file_path) = self.openFile()
> > + if six.PY2:
> > + (fobj, self.uni_file_path) = self.openFile()
> > + else:
> > + (fobj, self.uni_file_path) = self.openFile(mode="wt")
> > try:
> > fobj.write(UNICODE_LINE)
> > except UnicodeEncodeError:
> > @@ -42,7 +46,10 @@ class HandleUnicode_TestCase(BaseTestCase):
> >
> > self.assertIn("_str: " + str(UNICODE_STR.encode("utf-8")), dump)
> > self.assertIn("encoded_str: " + str(UNICODE_STR.encode("utf-8")), dump)
> > - self.assertIn(str(UNICODE_LINE.encode("utf-8")), dump)
> > + if six.PY2:
> > + self.assertIn(str(UNICODE_LINE.encode("utf-8")), dump)
> > + else:
> > + self.assertIn(UNICODE_LINE, dump)
> >
> > self.assertIn("ascii_str: " + ASCII_STR, dump)
> > self.assertIn(ASCII_LINE.rstrip(), dump)
>
> It's good for me. I only thinking if there would be better use instead
> of 'if - else' use:
>
> if six.PY2:
> ...
> else if six.PY3:
> ...
>
> But maybe I'm only too paranoiac :D
I think we are safe if this all works until Python 4 starts to be
used. :)
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list