def check_parameters_match(func, doc=None):
    """Helper to check docstring, returns list of incorrect results"""
    from numpydoc import docscrape
    incorrect = []
    name_ = get_name(func)
    if not name_.startswith('vispy.'):
        return incorrect
    if inspect.isdatadescriptor(func):
        return incorrect
    args = _get_args(func)
    # drop self
    if len(args) > 0 and args[0] in ('self', 'cls'):
        args = args[1:]

    if doc is None:
        with warnings.catch_warnings(record=True) as w:
            doc = docscrape.FunctionDoc(func)
        if len(w):
            raise RuntimeError('Error for %s:\n%s' % (name_, w[0]))
    # check set
    param_names = [name for name, _, _ in doc['Parameters']]
    # clean up some docscrape output:
    param_names = [name.split(':')[0].strip('` ') for name in param_names]
    param_names = [name for name in param_names if '*' not in name]
    if len(param_names) != len(args):
        bad = str(sorted(list(set(param_names) - set(args)) +
                         list(set(args) - set(param_names))))
        if not any(d in name_ for d in _ignores):
            incorrect += [name_ + ' arg mismatch: ' + bad]
    else:
        for n1, n2 in zip(param_names, args):
            if n1 != n2:
                incorrect += [name_ + ' ' + n1 + ' != ' + n2]
    return incorrect
def check_parameters_match(func, doc=None):
    """Helper to check docstring, returns list of incorrect results"""
    from numpydoc import docscrape
    incorrect = []
    name_ = get_name(func)
    if not name_.startswith('vispy.'):
        return incorrect
    if inspect.isdatadescriptor(func):
        return incorrect
    args = _get_args(func)
    # drop self
    if len(args) > 0 and args[0] in ('self', 'cls'):
        args = args[1:]

    if doc is None:
        with warnings.catch_warnings(record=True) as w:
            doc = docscrape.FunctionDoc(func)
        if len(w):
            raise RuntimeError('Error for %s:\n%s' % (name_, w[0]))
    # check set
    param_names = [name for name, _, _ in doc['Parameters']]
    # clean up some docscrape output:
    param_names = [name.split(':')[0].strip('` ') for name in param_names]
    param_names = [name for name in param_names if '*' not in name]
    if len(param_names) != len(args):
        bad = str(
            sorted(
                list(set(param_names) - set(args)) +
                list(set(args) - set(param_names))))
        if not any(d in name_ for d in _ignores):
            incorrect += [name_ + ' arg mismatch: ' + bad]
    else:
        for n1, n2 in zip(param_names, args):
            if n1 != n2:
                incorrect += [name_ + ' ' + n1 + ' != ' + n2]
    return incorrect
Exemple #3
0
def _test_module_properties(_module=None):
    """Test application module"""
    if _module is None:
        app = use_app()
        _module = app.backend_module

    # Test that the keymap contains all keys supported by vispy.
    module_fname = _module.__name__.split('.')[-1]
    if module_fname not in ('_egl', '_osmesa'):  # skip keys for EGL, osmesa
        keymap = _module.KEYMAP
        vispy_keys = keymap.values()
        for keyname in dir(keys):
            if keyname.upper() != keyname:
                continue
            key = getattr(keys, keyname)
            assert_in(key, vispy_keys)

    # For Qt backend, we have a common implementation
    alt_modname = ''
    if module_fname in ('_pyside', '_pyqt4', '_pyqt5', '_pyqt6', '_pyside2',
                        '_pyside6'):
        alt_modname = _module.__name__.rsplit('.', 1)[0] + '._qt'

    # Test that all _vispy_x methods are there.
    exceptions = ('_vispy_get_native_canvas', '_vispy_get_native_timer',
                  '_vispy_get_native_app', '_vispy_reuse', '_vispy_mouse_move',
                  '_vispy_mouse_press', '_vispy_mouse_release',
                  '_vispy_mouse_double_click', '_vispy_detect_double_click',
                  '_vispy_get_fb_bind_location', '_vispy_get_geometry',
                  '_vispy_get_physical_size', '_vispy_sleep',
                  '_process_backend_kwargs')  # defined in base class

    class KlassRef(vispy.app.base.BaseCanvasBackend):
        def __init__(self, *args, **kwargs):
            pass  # Do not call the base class, since it will check for Canvas

    Klass = _module.CanvasBackend
    base = KlassRef()
    for key in dir(KlassRef):
        if not key.startswith('__'):
            method = getattr(Klass, key)
            if key not in exceptions:
                print(key)
                args = [None] * (len(_get_args(method)) - 1)
                assert_raises(NotImplementedError, getattr(base, key), *args)
                if hasattr(method, '__module__'):
                    mod_str = method.__module__  # Py3k
                else:
                    mod_str = method.im_func.__module__
                assert_in(
                    mod_str, (_module.__name__, alt_modname),
                    "Method %s.%s not defined in %s" %
                    (Klass, key, _module.__name__))

    Klass = _module.TimerBackend
    KlassRef = vispy.app.timer.TimerBackend
    for key in dir(KlassRef):
        if not key.startswith('__'):
            method = getattr(Klass, key)
            if key not in exceptions:
                if hasattr(method, '__module__'):
                    # Py3k
                    assert_in(method.__module__,
                              (_module.__name__, alt_modname))
                else:
                    t = method.im_func.__module__ == _module.__name__
                    assert t

    Klass = _module.ApplicationBackend
    KlassRef = vispy.app.application.ApplicationBackend
    for key in dir(KlassRef):
        if not key.startswith('__'):
            method = getattr(Klass, key)
            if key not in exceptions:
                if hasattr(method, '__module__'):
                    # Py3k
                    assert_in(method.__module__,
                              (_module.__name__, alt_modname))
                else:
                    t = method.im_func.__module__ == _module.__name__
                    assert t

    # Test that all events seem to be emitted.
    # Get text
    fname = _module.__file__.rstrip('c')  # "strip" will break windows!
    with open(fname, 'rb') as fid:
        text = fid.read().decode('utf-8')

    canvas = vispy.app.Canvas(create_native=False, app=DummyApplication())
    # Stylus and touch are ignored because they are not yet implemented.
    # Mouse events are emitted from the CanvasBackend base class.
    ignore = set([
        'stylus', 'touch', 'mouse_press', 'paint', 'mouse_move',
        'mouse_release', 'mouse_double_click', 'detect_double_click', 'close'
    ])
    if module_fname in ('_egl', '_osmesa'):
        ignore = ignore.union(['mouse_wheel', 'key_release', 'key_press'])
    eventNames = set(canvas.events._emitters.keys()) - ignore

    if not alt_modname:  # Only check for non-proxy modules
        for name in eventNames:
            assert_in('events.%s' % name, text,
                      'events.%s does not appear in %s' % (name, fname))
Exemple #4
0
def _test_module_properties(_module=None):
    """Test application module"""
    if _module is None:
        app = use_app()
        _module = app.backend_module

    # Test that the keymap contains all keys supported by vispy.
    module_fname = _module.__name__.split('.')[-1]
    if module_fname not in ('_egl', '_osmesa'):  # skip keys for EGL, osmesa
        keymap = _module.KEYMAP
        vispy_keys = keymap.values()
        for keyname in dir(keys):
            if keyname.upper() != keyname:
                continue
            key = getattr(keys, keyname)
            assert_in(key, vispy_keys)

    # For Qt backend, we have a common implementation
    alt_modname = ''
    if module_fname in ('_pyside', '_pyqt4', '_pyqt5'):
        alt_modname = _module.__name__.rsplit('.', 1)[0] + '._qt'

    # Test that all _vispy_x methods are there.
    exceptions = (
        '_vispy_get_native_canvas',
        '_vispy_get_native_timer',
        '_vispy_get_native_app',
        '_vispy_reuse',
        '_vispy_mouse_move',
        '_vispy_mouse_press',
        '_vispy_mouse_release',
        '_vispy_mouse_double_click',
        '_vispy_detect_double_click',
        '_vispy_get_geometry',
        '_vispy_get_physical_size',
        '_vispy_sleep',
        '_process_backend_kwargs')  # defined in base class

    class KlassRef(vispy.app.base.BaseCanvasBackend):
        def __init__(self, *args, **kwargs):
            pass  # Do not call the base class, since it will check for Canvas
    Klass = _module.CanvasBackend
    base = KlassRef()
    for key in dir(KlassRef):
        if not key.startswith('__'):
            method = getattr(Klass, key)
            if key not in exceptions:
                print(key)
                args = [None] * (len(_get_args(method)) - 1)
                assert_raises(NotImplementedError, getattr(base, key), *args)
                if hasattr(method, '__module__'):
                    mod_str = method.__module__  # Py3k
                else:
                    mod_str = method.im_func.__module__
                assert_in(mod_str, (_module.__name__, alt_modname),
                          "Method %s.%s not defined in %s"
                          % (Klass, key, _module.__name__))

    Klass = _module.TimerBackend
    KlassRef = vispy.app.timer.TimerBackend
    for key in dir(KlassRef):
        if not key.startswith('__'):
            method = getattr(Klass, key)
            if key not in exceptions:
                if hasattr(method, '__module__'):
                    # Py3k
                    assert_in(method.__module__,
                              (_module.__name__, alt_modname))
                else:
                    t = method.im_func.__module__ == _module.__name__
                    assert t

    Klass = _module.ApplicationBackend
    KlassRef = vispy.app.application.ApplicationBackend
    for key in dir(KlassRef):
        if not key.startswith('__'):
            method = getattr(Klass, key)
            if key not in exceptions:
                if hasattr(method, '__module__'):
                    # Py3k
                    assert_in(method.__module__,
                              (_module.__name__, alt_modname))
                else:
                    t = method.im_func.__module__ == _module.__name__
                    assert t

    # Test that all events seem to be emitted.
    # Get text
    fname = _module.__file__.rstrip('c')  # "strip" will break windows!
    with open(fname, 'rb') as fid:
        text = fid.read().decode('utf-8')

    canvas = vispy.app.Canvas(create_native=False, app=DummyApplication())
    # Stylus and touch are ignored because they are not yet implemented.
    # Mouse events are emitted from the CanvasBackend base class.
    ignore = set(['stylus', 'touch', 'mouse_press', 'paint',
                  'mouse_move', 'mouse_release', 'mouse_double_click',
                  'detect_double_click', 'close'])
    if module_fname in ('_egl', '_osmesa'):
        ignore = ignore.union(['mouse_wheel', 'key_release', 'key_press'])
    eventNames = set(canvas.events._emitters.keys()) - ignore

    if not alt_modname:  # Only check for non-proxy modules
        for name in eventNames:
            assert_in('events.%s' % name, text,
                      'events.%s does not appear in %s' % (name, fname))