From cc1c32da8866bdcc65bee916cd202f660b0cd88e Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Tue, 6 Oct 2020 13:57:45 -0400 Subject: cleanup old python compat -- removed PY26 conditional, and unittest2 imports. removing unittest2 also allowed removing "passlib.tests.backports" --- passlib/tests/backports.py | 66 ----------------------------------- passlib/tests/test_apache.py | 2 +- passlib/tests/test_context.py | 8 ++--- passlib/tests/test_handlers_django.py | 3 +- passlib/tests/utils.py | 15 ++++---- passlib/utils/compat/__init__.py | 11 +++--- 6 files changed, 16 insertions(+), 89 deletions(-) delete mode 100644 passlib/tests/backports.py (limited to 'passlib') diff --git a/passlib/tests/backports.py b/passlib/tests/backports.py deleted file mode 100644 index 8187741..0000000 --- a/passlib/tests/backports.py +++ /dev/null @@ -1,66 +0,0 @@ -"""backports of needed unittest2 features""" -#============================================================================= -# imports -#============================================================================= -# core -import logging; log = logging.getLogger(__name__) -import re -import sys -##from warnings import warn -# site -# pkg -from passlib.utils.compat import PY26 -# local -__all__ = [ - "TestCase", - "unittest", - # TODO: deprecate these exports in favor of "unittest.XXX" - "skip", "skipIf", "skipUnless", -] - -#============================================================================= -# import latest unittest module available -#============================================================================= -try: - import unittest2 as unittest -except ImportError: - if PY26: - raise ImportError("Passlib's tests require 'unittest2' under Python 2.6 (as of Passlib 1.7)") - # python 2.7 and python 3.2 both have unittest2 features (at least, the ones we use) - import unittest - -#============================================================================= -# unittest aliases -#============================================================================= -skip = unittest.skip -skipIf = unittest.skipIf -skipUnless = unittest.skipUnless -SkipTest = unittest.SkipTest - -#============================================================================= -# custom test harness -#============================================================================= -class TestCase(unittest.TestCase): - """backports a number of unittest2 features in TestCase""" - - #=================================================================== - # backport some unittest2 names - #=================================================================== - - #--------------------------------------------------------------- - # backport assertRegex() alias from 3.2 to 2.7 - # was present in 2.7 under an alternate name - #--------------------------------------------------------------- - if not hasattr(unittest.TestCase, "assertRegex"): - assertRegex = unittest.TestCase.assertRegexpMatches - - if not hasattr(unittest.TestCase, "assertRaisesRegex"): - assertRaisesRegex = unittest.TestCase.assertRaisesRegexp - - #=================================================================== - # eoc - #=================================================================== - -#============================================================================= -# eof -#============================================================================= diff --git a/passlib/tests/test_apache.py b/passlib/tests/test_apache.py index f37c727..b380232 100644 --- a/passlib/tests/test_apache.py +++ b/passlib/tests/test_apache.py @@ -4,6 +4,7 @@ #============================================================================= # core from logging import getLogger +import unittest import os import subprocess # site @@ -11,7 +12,6 @@ import subprocess from passlib import apache, registry from passlib.exc import MissingBackendError from passlib.utils.compat import irange -from passlib.tests.backports import unittest from passlib.tests.utils import TestCase, get_file, set_file, ensure_mtime_changed from passlib.utils import to_bytes from passlib.utils.handlers import to_unicode_for_identify diff --git a/passlib/tests/test_context.py b/passlib/tests/test_context.py index 56cddd7..7e5996f 100644 --- a/passlib/tests/test_context.py +++ b/passlib/tests/test_context.py @@ -19,7 +19,7 @@ from passlib import hash from passlib.context import CryptContext, LazyCryptContext from passlib.exc import PasslibConfigWarning, PasslibHashWarning from passlib.utils import tick, to_unicode -from passlib.utils.compat import irange, unicode, str_to_uascii, PY2, PY26 +from passlib.utils.compat import irange, unicode, str_to_uascii, PY2 import passlib.utils.handlers as uh from passlib.tests.utils import (TestCase, set_file, TICK_RESOLUTION, quicksleep, time_call, handler_derived_from) @@ -846,11 +846,7 @@ sha512_crypt__min_rounds = 45000 dump = ctx.to_string() # check ctx->string returns canonical format. - # NOTE: ConfigParser for PY26 doesn't use OrderedDict, - # making to_string()'s ordering unpredictable... - # so we skip this test under PY26. - if not PY26: - self.assertEqual(dump, self.sample_1_unicode) + self.assertEqual(dump, self.sample_1_unicode) # check ctx->string->ctx->dict returns original ctx2 = CryptContext.from_string(dump) diff --git a/passlib/tests/test_handlers_django.py b/passlib/tests/test_handlers_django.py index 02d5e55..d5ed9c6 100644 --- a/passlib/tests/test_handlers_django.py +++ b/passlib/tests/test_handlers_django.py @@ -5,12 +5,13 @@ # core import logging; log = logging.getLogger(__name__) import re +from unittest import skipUnless, SkipTest import warnings # site # pkg from passlib import hash from passlib.utils import repeat_string -from passlib.tests.utils import TestCase, HandlerCase, skipUnless, SkipTest +from passlib.tests.utils import TestCase, HandlerCase from passlib.tests.test_handlers import UPASS_USD, UPASS_TABLE from passlib.tests.test_ext_django import DJANGO_VERSION, MIN_DJANGO_VERSION, \ check_django_hasher_has_backend diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index 9c1b218..9fb97f7 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -15,6 +15,7 @@ import sys import tempfile import threading import time +import unittest from passlib.exc import PasslibHashWarning, PasslibConfigWarning from passlib.utils.compat import PY3, JYTHON import warnings @@ -24,7 +25,6 @@ from warnings import warn from passlib import exc from passlib.exc import MissingBackendError import passlib.registry as registry -from passlib.tests.backports import TestCase as _TestCase, skip, skipIf, skipUnless, SkipTest from passlib.utils import has_rounds_info, has_salt_info, rounds_cost_values, \ rng as sys_rng, getrandstr, is_ascii_safe, to_native_str, \ repeat_string, tick, batch @@ -297,7 +297,7 @@ def run_with_fixed_seeds(count=128, master_seed=0x243F6A8885A308D3): # custom test harness #============================================================================= -class TestCase(_TestCase): +class TestCase(unittest.TestCase): """passlib-specific test case class this class adds a number of features to the standard TestCase... @@ -332,7 +332,7 @@ class TestCase(_TestCase): #--------------------------------------------------------------- @classproperty def __unittest_skip__(cls): - # NOTE: this attr is technically a unittest2 internal detail. + # NOTE: this attr is technically a unittest internal detail. name = cls.__name__ return name.startswith("_") or \ getattr(cls, "_%s__unittest_skip" % name, False) @@ -409,7 +409,7 @@ class TestCase(_TestCase): # forbid a bunch of deprecated aliases so I stop using them #--------------------------------------------------------------- def assertEquals(self, *a, **k): - raise AssertionError("this alias is deprecated by unittest2") + raise AssertionError("this alias is deprecated by stdlib unittest") assertNotEquals = assertRegexMatches = assertEquals #=================================================================== @@ -716,8 +716,7 @@ class HandlerCase(TestCase): .. note:: - This is subclass of :class:`unittest.TestCase` - (or :class:`unittest2.TestCase` if available). + This is subclass of :class:`unittest.TestCase`. """ #=================================================================== # class attrs - should be filled in by subclass @@ -2547,7 +2546,7 @@ class HandlerCase(TestCase): def require_parsehash(self): if not hasattr(self.handler, "parsehash"): - raise SkipTest("parsehash() not implemented") + raise self.skipTest("parsehash() not implemented") def test_70_parsehash(self): """ @@ -2735,7 +2734,7 @@ class HandlerCase(TestCase): def wrapper(): try: self.test_77_fuzz_input(threaded=True) - except SkipTest: + except unittest.SkipTest: pass except: with failed_lock: diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py index b2aaf5b..9e58d58 100644 --- a/passlib/utils/compat/__init__.py +++ b/passlib/utils/compat/__init__.py @@ -14,8 +14,6 @@ PY3 = sys.version_info >= (3,0) if sys.version_info < (3, 5): raise RuntimeError("Passlib requires Python >= 3.5 (as of passlib 1.8)") -PY26 = sys.version_info < (2,7) - #------------------------------------------------------------------------ # python implementation #------------------------------------------------------------------------ @@ -48,7 +46,7 @@ def add_doc(obj, doc): #============================================================================= __all__ = [ # python versions - 'PY2', 'PY3', 'PY26', + 'PY2', 'PY3', # io 'BytesIO', 'StringIO', 'NativeStringIO', 'SafeConfigParser', @@ -328,10 +326,9 @@ else: #============================================================================= # collections #============================================================================= -if PY26: - _lazy_attrs['OrderedDict'] = 'passlib.utils.compat._ordered_dict.OrderedDict' -else: - _lazy_attrs['OrderedDict'] = 'collections.OrderedDict' + +# TODO: remove backport +_lazy_attrs['OrderedDict'] = 'collections.OrderedDict' #============================================================================= # context managers -- cgit v1.2.1