Test suite failure if os_crypt backend unavailable

Issue #58 resolved
Paul Howarth
created an issue
======================================================================
ERROR: des_crypt (os_crypt backend): test per-call crypt() fallback
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 2065, in test_81_crypt_fallback
    if self.find_crypt_replacement(fallback=True):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 781, in find_crypt_replacement
    idx = handler.backends.index("os_crypt") + 1
AttributeError: 'tuple' object has no attribute 'index'

======================================================================
ERROR: ldap_md5_crypt (os_crypt backend): test per-call crypt() fallback
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 2065, in test_81_crypt_fallback
    if self.find_crypt_replacement(fallback=True):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 781, in     find_crypt_replacement
    idx = handler.backends.index("os_crypt") + 1
AttributeError: 'tuple' object has no attribute 'index'

======================================================================
ERROR: md5_crypt (os_crypt backend): test per-call crypt() fallback
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 2065, in test_81_crypt_fallback
    if self.find_crypt_replacement(fallback=True):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 781, in find_crypt_replacement
    idx = handler.backends.index("os_crypt") + 1
AttributeError: 'tuple' object has no attribute 'index'

======================================================================
ERROR: sha256_crypt (os_crypt backend): test per-call crypt() fallback
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 2065, in test_81_crypt_fallback
    if self.find_crypt_replacement(fallback=True):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 781, in find_crypt_replacement
    idx = handler.backends.index("os_crypt") + 1
AttributeError: 'tuple' object has no attribute 'index'

======================================================================
ERROR: sha512_crypt (os_crypt backend): test per-call crypt() fallback
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 2065, in test_81_crypt_fallback
    if self.find_crypt_replacement(fallback=True):
  File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 781, in find_crypt_replacement
    idx = handler.backends.index("os_crypt") + 1
AttributeError: 'tuple' object has no attribute 'index'

----------------------------------------------------------------------
Ran 2391 tests in 186.628s

FAILED (errors=5)

This change fixes it for me:

--- passlib/tests/utils.py
+++ passlib/tests/utils.py
@@ -777,7 +777,7 @@
     def find_crypt_replacement(cls, fallback=False):
         """find other backend which can be used to mock the os_crypt backend"""
         handler = cls.handler
-        if fallback:
+        if fallback and handler.has_backend("os_crypt"):
             idx = handler.backends.index("os_crypt") + 1
         else:
             idx = 0

Comments (6)

  1. Eli Collins repo owner

    Actually, it looks like the error is that tuple().index doesn't exist in your python version. (I'm guessing you're using python 2.5? It looks like that method was added in python 2.6 / 3.0).

    I've pushed a fix to the stable branch that should take care of it, let me know if you still have errors.

  2. Paul Howarth reporter

    I'm building for a variety of different targets, but you're right about this coming up with python 2.5. Your fix works for me. Whilst I'm here though, I still have one last issue with python 2.5 (not 2.5.1 or later):

    ======================================================================
    ERROR: Failure: SyntaxError (invalid syntax (test_ext_django.py, line 731))
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/builddir/build/BUILD/passlib-1.6.4/nose-1.3.7-py2.5.egg/nose/loader.py", line 418, in loadTestsFromName
        addr.filename, addr.module)
      File "/builddir/build/BUILD/passlib-1.6.4/nose-1.3.7-py2.5.egg/nose/importer.py", line 47, in importFromPath
        return self.importFromDir(dir_path, fqname)
      File "/builddir/build/BUILD/passlib-1.6.4/nose-1.3.7-py2.5.egg/nose/importer.py", line 94, in importFromDir
        mod = load_module(part_fqname, fh, filename, desc)
      File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/test_ext_django.py", line 731
        with self.assertWarningList("PASSLIB_CONFIG=None is deprecated"):
                ^
    SyntaxError: invalid syntax
    
    ======================================================================
    ERROR: django_des_crypt: test random passwords and options
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 1733, in test_77_fuzz_input
        verifiers = self.get_fuzz_verifiers()
      File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/utils.py", line 1820, in get_fuzz_verifiers
        func = getattr(self, name)()
      File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/test_handlers_django.py", line 39, in fuzz_verifier_django
        from passlib.tests.test_ext_django import DJANGO_VERSION
      File "/builddir/build/BUILD/passlib-1.6.4/passlib/tests/test_ext_django.py", line 731
        with self.assertWarningList("PASSLIB_CONFIG=None is deprecated"):
                ^
    SyntaxError: invalid syntax
    
    ======================================================================
    

    There are a total of 16 errors reported like this, all at the same line number. Any ideas?

  3. Eli Collins repo owner

    Ok, that's just bizarre. It's like python isn't recognizing the with statement... that's the exact error py2.5 gives if you omit the future import. But from __future__ import with_statement is at the top of test_ext_django.py, so it should be working. Maybe there's some weird parsing bug in 2.5.0 that was fixed in a later patch release? I can't find reference to one though (The earliest version I have is 2.5.6, which is running fine after the previous fix).

  4. Paul Howarth reporter

    You're right about the weird parsing bug in 2.5.0; this workaround gets the test suite working:

    Workaround for python 2.5.0 support, addressing parser bug
    
    http://bytes.com/topic/python/answers/539963-strange-__future__-behavior-python-2-5-a
    
    Fixed in python svn revision 42395:
    https://hg.python.org/cpython-fullhistory/rev/25bcdf3cd194
    
    --- passlib/tests/test_ext_django.py
    +++ passlib/tests/test_ext_django.py
    @@ -2,7 +2,8 @@
     #=============================================================================
     # imports
     #=============================================================================
    -from __future__ import with_statement, absolute_import
    +from __future__ import with_statement
    +from __future__ import absolute_import
     # core
     import logging; log = logging.getLogger(__name__)
     import sys
    
  5. Log in to comment