test/common.py
def _check_module_exists(name):
    r"""Returns if a top-level module with :attr:`name` exists *without**
    importing it. This is generally safer than try-catch block around a
    `import X`. It avoids third party libraries breaking assumptions of some of
    our tests, e.g., setting multiprocessing start method when imported
    (see librosa/#747, torchvision/#544).
    """
    if not PY3:  # Python 2
        import imp
        try:
            imp.find_module(name)
            return True
        except ImportError:
            return False
    elif PY34:  # Python [3, 3.4)
        import importlib
        loader = importlib.find_loader(name)
        return loader is not None
    else:  # Python >= 3.4
        import importlib
        spec = importlib.util.find_spec(name)
        return spec is not None
r"""Returns if a top-level module with :attr:`name` exists *without**
    importing it. This is generally safer than try-catch block around a
    `import X`. It avoids third party libraries breaking assumptions of some of
    our tests, e.g., setting multiprocessing start method when imported
    (see librosa/#747, torchvision/#544).
    
r"""Returns if a top-level module with :attr:`name` exists *without
importing it. This is generally safer than try-catch block around a
`import X`. It avoids third party libraries breaking assumptions of some of
our tests, e.g., setting multiprocessing start method when imported
.
r " " " Returns if a top - level module with : attr : ` name ` exists * without importing it . This is generally safer than try - catch block around a ` import X ` . It avoids third party libraries breaking assumptions of some of our tests e . g . setting multiprocessing start method when imported .
def _check_module_exists(name):
    if not PY3:  
        import imp
        try:
            imp.find_module(name)
            return True
        except ImportError:
            return False
    elif PY34:  
        import importlib
        loader = importlib.find_loader(name)
        return loader is not None
    else:  
        import importlib
        spec = importlib.util.find_spec(name)
        return spec is not None
def _check_module_exists ( name ) : if not PY3 : import imp try : imp . find_module ( name ) return True except ImportError : return False elif PY34 : import importlib loader = importlib . find_loader ( name ) return loader is not None else : import importlib spec = importlib . util . find_spec ( name ) return spec is not None
r"""Returns if a top-level module with :attr:`name` exists *without
importing it.
r " " " Returns if a top - level module with : attr : ` name ` exists * without importing it .
r"""Returns if a top-level module with :attr:`name` exists *without**
    importing it. This is generally safer than try-catch block around a
    `import X`. It avoids third party libraries breaking assumptions of some of
    our tests, e.g., setting multiprocessing start method when imported
    (see librosa/#747, torchvision/#544).
    """ # Python 2 # Python [3, 3.4) # Python >= 3.4
name