Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail on pypy3 when berkdb is not installed #320

Open
mgorny opened this issue Jan 16, 2020 · 0 comments
Open

Tests fail on pypy3 when berkdb is not installed #320

mgorny opened this issue Jan 16, 2020 · 0 comments

Comments

@mgorny
Copy link

mgorny commented Jan 16, 2020

==================================================================== FAILURES =====================================================================
____________________________________________________________ test_move_items[dbm_ndbm] ____________________________________________________________

item_name = 'dbm_ndbm'

    @pytest.mark.parametrize("item_name",
                              [item.name for item in six._moved_attributes])
    def test_move_items(item_name):
        """Ensure that everything loads correctly."""
        try:
>           item = getattr(six.moves, item_name)

test_six.py:121: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../six-1.14.0-pypy3/lib/six.py:92: in __get__
    result = self._resolve()
../six-1.14.0-pypy3/lib/six.py:115: in _resolve
    return _import_module(self.mod)
../six-1.14.0-pypy3/lib/six.py:82: in _import_module
    __import__(name)
/usr/lib/pypy3.6/lib-python/3/dbm/ndbm.py:3: in <module>
    from _dbm import *
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    import os
    import sys
    import ctypes.util
    from ctypes import Structure, c_char, c_char_p, c_int, c_void_p, CDLL, POINTER
    
    class error(IOError):
        def __init__(self, msg):
            self.msg = msg
    
        def __str__(self):
            return self.msg
    
    class datum(Structure):
        _fields_ = [
        ('dptr', POINTER(c_char)),
        ('dsize', c_int),
        ]
    
        def __init__(self, text):
            if isinstance(text, str):
                text = text.encode(sys.getdefaultencoding())
            elif not isinstance(text, bytes):
                msg = "dbm mapping keys must be a string or bytes object, not {!r}"
                raise TypeError(msg.format(type(text).__name__))
            Structure.__init__(self, text, len(text))
    
    class dbm(object):
        def __init__(self, dbmobj):
            self._aobj = dbmobj
    
        def close(self):
            if not self._aobj:
                raise error('DBM object has already been closed')
            getattr(lib, funcs['close'])(self._aobj)
            self._aobj = None
    
        def __del__(self):
            if self._aobj:
                self.close()
    
        def keys(self):
            if not self._aobj:
                raise error('DBM object has already been closed')
            allkeys = []
            k = getattr(lib, funcs['firstkey'])(self._aobj)
            while k.dptr:
                allkeys.append(k.dptr[:k.dsize])
                k = getattr(lib, funcs['nextkey'])(self._aobj)
            return allkeys
    
        def get(self, key, default=None):
            if not self._aobj:
                raise error('DBM object has already been closed')
            dat = datum(key)
            k = getattr(lib, funcs['fetch'])(self._aobj, dat)
            if k.dptr:
                return k.dptr[:k.dsize]
            if getattr(lib, funcs['error'])(self._aobj):
                getattr(lib, funcs['clearerr'])(self._aobj)
                raise error("")
            return default
    
        def __len__(self):
            return len(self.keys())
    
        def __getitem__(self, key):
            value = self.get(key)
            if value is None:
                raise KeyError(key)
            return value
    
        def __setitem__(self, key, value):
            if not self._aobj:
                raise error('DBM object has already been closed')
            dat = datum(key)
            data = datum(value)
            status = getattr(lib, funcs['store'])(self._aobj, dat, data, lib.DBM_REPLACE)
            if getattr(lib, funcs['error'])(self._aobj):
                getattr(lib, funcs['clearerr'])(self._aobj)
                raise error("")
            return status
    
        def setdefault(self, key, default=''):
            if not self._aobj:
                raise error('DBM object has already been closed')
            dat = datum(key)
            k = getattr(lib, funcs['fetch'])(self._aobj, dat)
            if k.dptr:
                return k.dptr[:k.dsize]
            data = datum(default)
            status = getattr(lib, funcs['store'])(self._aobj, dat, data, lib.DBM_INSERT)
            if status < 0:
                getattr(lib, funcs['clearerr'])(self._aobj)
                raise error("cannot add item to database")
            return default
    
        def __contains__(self, key):
            if not self._aobj:
                raise error('DBM object has already been closed')
            dat = datum(key)
            k = getattr(lib, funcs['fetch'])(self._aobj, dat)
            if k.dptr:
                return True
            return False
        has_key = __contains__
    
        def __delitem__(self, key):
            if not self._aobj:
                raise error('DBM object has already been closed')
            dat = datum(key)
            status = getattr(lib, funcs['delete'])(self._aobj, dat)
            if status < 0:
                raise KeyError(key)
    
        def __enter__(self):
            return self
    
        def __exit__(self, *exc_info):
            self.close()
    
    
    ### initialization: Berkeley DB versus normal DB
    
    def _init_func(name, argtypes=None, restype=None):
        try:
            func = getattr(lib, '__db_ndbm_' + name)
            funcs[name] = '__db_ndbm_' + name
        except AttributeError:
            func = getattr(lib, 'dbm_' + name)
            funcs[name] = 'dbm_' + name
        if argtypes is not None:
            func.argtypes = argtypes
        if restype is not None:
            func.restype = restype
    
    if sys.platform != 'darwin':
        libpath = ctypes.util.find_library('db')
        if not libpath:
            # XXX this is hopeless...
            for c in ['5.3', '5.2', '5.1', '5.0', '4.9', '4.8', '4.7', '4.6', '4.5']:
                libpath = ctypes.util.find_library('db-%s' % c)
                if libpath:
                    break
            else:
>               raise ImportError("Cannot find dbm library")
E               ImportError: Cannot find dbm library

/usr/lib/pypy3.6/lib_pypy/_dbm.py:145: ImportError
================================================ 1 failed, 183 passed, 16 skipped in 25.82 seconds ================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant