diff options
author | Victor Stinner <victor.stinner@enovance.com> | 2014-04-07 12:23:04 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@enovance.com> | 2014-04-07 12:23:04 +0200 |
commit | c7fa1865128de9538458fda72541ae04eba5483c (patch) | |
tree | 6b14b9aa052ac93578d5284845fbcfee3cef9f53 | |
parent | 43a5fa4760d2a44672da6b92b56a8e34fae67ecf (diff) | |
download | oslo-utils-c7fa1865128de9538458fda72541ae04eba5483c.tar.gz |
Partial fix of test_strutils.py on Python 3
StringToBytesTest does not work on Python 3 because it uses testscenarios which
does not work in nosetests, see the bug:
https://bugs.launchpad.net/testscenarios/+bug/872887
Because of this bug, the test_strutils.py is not enabled yet for py33 in
tox.ini.
Change-Id: Ie3a7742dfd802f21c6c7420e3b894122e1dca295
-rw-r--r-- | tests/unit/test_strutils.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/tests/unit/test_strutils.py b/tests/unit/test_strutils.py index 6f3adb7..a6bb679 100644 --- a/tests/unit/test_strutils.py +++ b/tests/unit/test_strutils.py @@ -146,19 +146,22 @@ class StrUtilsTest(test.BaseTestCase): def test_safe_decode(self): safe_decode = strutils.safe_decode self.assertRaises(TypeError, safe_decode, True) - self.assertEqual(six.u('ni\xf1o'), safe_decode("ni\xc3\xb1o", + self.assertEqual(six.u('ni\xf1o'), safe_decode(six.b("ni\xc3\xb1o"), incoming="utf-8")) - self.assertEqual(six.u("test"), safe_decode("dGVzdA==", - incoming='base64')) + if six.PY2: + # In Python 3, bytes.decode() doesn't support anymore + # bytes => bytes encodings like base64 + self.assertEqual(six.u("test"), safe_decode("dGVzdA==", + incoming='base64')) - self.assertEqual(six.u("strange"), safe_decode('\x80strange', + self.assertEqual(six.u("strange"), safe_decode(six.b('\x80strange'), errors='ignore')) - self.assertEqual(six.u('\xc0'), safe_decode('\xc0', + self.assertEqual(six.u('\xc0'), safe_decode(six.b('\xc0'), incoming='iso-8859-1')) # Forcing incoming to ascii so it falls back to utf-8 - self.assertEqual(six.u('ni\xf1o'), safe_decode('ni\xc3\xb1o', + self.assertEqual(six.u('ni\xf1o'), safe_decode(six.b('ni\xc3\xb1o'), incoming='ascii')) self.assertEqual(six.u('foo'), safe_decode(b'foo')) @@ -193,7 +196,7 @@ class StrUtilsTest(test.BaseTestCase): self.assertEqual(six.u("ampserand"), to_slug("&ser$and")) self.assertEqual(six.u("ju5tnum8er"), to_slug("ju5tnum8er")) self.assertEqual(six.u("strip-"), to_slug(" strip - ")) - self.assertEqual(six.u("perche"), to_slug("perch\xc3\xa9")) + self.assertEqual(six.u("perche"), to_slug(six.b("perch\xc3\xa9"))) self.assertEqual(six.u("strange"), to_slug("\x80strange", errors="ignore")) |