diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-12-06 17:23:15 -0500 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-12-06 17:23:15 -0500 |
| commit | 9fb27abea822541c812e202281d525a163fa00fa (patch) | |
| tree | b423a48400071bac0adfd435cd6e181ed0cd322a /passlib/tests | |
| parent | 9d18d37fc6d1992514c345d70330b57871fb7c93 (diff) | |
| download | passlib-9fb27abea822541c812e202281d525a163fa00fa.tar.gz | |
replaced all #Py3k# conditional includes
Diffstat (limited to 'passlib/tests')
| -rw-r--r-- | passlib/tests/test_utils.py | 65 | ||||
| -rw-r--r-- | passlib/tests/utils.py | 16 |
2 files changed, 32 insertions, 49 deletions
diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py index db56a0e..f309523 100644 --- a/passlib/tests/test_utils.py +++ b/passlib/tests/test_utils.py @@ -16,7 +16,7 @@ from passlib import utils from passlib.utils import h64, des, Undef, bytes, b, \ native_str, to_bytes, to_unicode, to_native_str, to_hash_str, \ is_same_codec, is_ascii_safe, safe_os_crypt, md4 as md4_mod -from passlib.utils.compat import unicode +from passlib.utils.compat import unicode, PY3 from passlib.tests.utils import TestCase, Params as ak, \ enable_option, catch_warnings from passlib.utils.compat import u @@ -138,11 +138,10 @@ class MiscTest(TestCase): #test latin-1 password ret = safe_os_crypt(b('test\xff'), u('aa')) - # Py2k # - self.assertEqual(ret, (True, u('aaOx.5nbTU/.M'))) - # Py3k # - #self.assertEqual(ret, (False, None)) - # end Py3k # + if PY3: + self.assertEqual(ret, (False, None)) + else: + self.assertEqual(ret, (True, u('aaOx.5nbTU/.M'))) def test_consteq(self): "test consteq()" @@ -236,21 +235,21 @@ class CodecTest(TestCase): def test_bytes(self): "test b() helper, bytes and native_str types" - # Py2k # - self.assertIs(bytes, type('')) - self.assertIs(native_str, bytes) - # Py3k # - #self.assertIs(bytes, type(b'')) - #self.assertIs(native_str, unicode) - # end Py3k # + if PY3: + import builtins + self.assertIs(bytes, builtins.bytes) + else: + import __builtin__ as builtins + self.assertIs(bytes, builtins.str) + + self.assertIs(native_str, builtins.str) self.assertIsInstance(b(''), bytes) self.assertIsInstance(b('\x00\xff'), bytes) - # Py2k # - self.assertEqual(b('\x00\xff'), "\x00\xff") - # Py3k # - #self.assertEqual(b('\x00\xff'), b"\x00\xff") - # end Py3k # + if PY3: + self.assertEqual(b('\x00\xff').encode("latin-1"), "\x00\xff") + else: + self.assertEqual(b('\x00\xff'), "\x00\xff") def test_to_bytes(self): "test to_bytes()" @@ -311,23 +310,14 @@ class CodecTest(TestCase): self.assertEqual(to_native_str(b('abc')), 'abc') self.assertRaises(TypeError, to_native_str, None) - # Py2k # - self.assertEqual(to_native_str(u('\x00\xff')), b('\x00\xc3\xbf')) - self.assertEqual(to_native_str(b('\x00\xc3\xbf')), b('\x00\xc3\xbf')) - self.assertEqual(to_native_str(u('\x00\xff'), 'latin-1'), - b('\x00\xff')) - self.assertEqual(to_native_str(b('\x00\xff'), 'latin-1'), - b('\x00\xff')) - - # Py3k # - #self.assertEqual(to_native_str(u'\x00\xff'), '\x00\xff') - #self.assertEqual(to_native_str(b('\x00\xc3\xbf')), '\x00\xff') - #self.assertEqual(to_native_str(u'\x00\xff', 'latin-1'), - # '\x00\xff') - #self.assertEqual(to_native_str(b('\x00\xff'), 'latin-1'), - # '\x00\xff') - # - # end Py3k # + self.assertEqual(to_native_str(u('\x00\xff'), 'latin-1'), '\x00\xff') + self.assertEqual(to_native_str(b('\x00\xff'), 'latin-1'), '\x00\xff') + if PY3: + self.assertEqual(to_native_str(u('\x00\xff')), '\x00\xff') + self.assertEqual(to_native_str(b('\x00\xc3\xbf')), '\x00\xff') + else: + self.assertEqual(to_native_str(u('\x00\xff')), '\x00\xc3\xbf') + self.assertEqual(to_native_str(b('\x00\xc3\xbf')), '\x00\xc3\xbf') #TODO: test to_hash_str() @@ -580,9 +570,8 @@ class _MD4_Test(TestCase): #NOTE: under py2, hashlib methods try to encode to ascii, # though shouldn't rely on that. - # Py3k # - #self.assertRaises(TypeError, h.update, u'x') - # end Py3k # + if PY3: + self.assertRaises(TypeError, h.update, u('x')) h.update(b('a')) self.assertEqual(h.hexdigest(), "bde52cb31de33e46245e05fbdbd6fb24") diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index 99bf10d..058f98e 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -10,21 +10,17 @@ import re import os import sys import tempfile -from passlib.utils.compat import u +from passlib.utils.compat import u, PY27, PY_MIN_32, PY3 try: import unittest2 as unittest ut_version = 2 except ImportError: import unittest - # Py2k # - if sys.version_info < (2,7): - # Py3k # - #if sys.version_info < (3,2): - # end Py3k # - ut_version = 1 - else: + if PY27 or PY_MIN_32: ut_version = 2 + else: + ut_version = 1 import warnings from warnings import warn @@ -532,10 +528,8 @@ class HandlerCase(TestCase): hash = h.genhash(secret, hash) finally: h.set_backend(tmp) - # Py2k # - if isinstance(hash, unicode): + if not PY3 and isinstance(hash, unicode): hash = hash.encode("ascii") - # end Py2k # return hash utils.os_crypt = crypt_stub h.set_backend(backend) |
