<commit_before>""" Tests to quickly see if the backends look good.
This tests only to see if all the necessary methods are implemented,
whether all the right events are mentioned, and whether the keymap 
contains all keys that should be supported.

This test basically checks whether nothing was forgotten, not that the
implementation is corect.
 
"""

import sys

import vispy
from vispy import keys

class BaseTestmodule:
    
    def __init__(self, module=None):
        self._module = module
        if module is None:
            print("Skipping %s." % self.__class__.__name__)
            self.test_events = lambda : None
            self.test_keymap = lambda : None
            self.test_methods = lambda : None
    
    
    def test_keymap(self):
        """ Test that the keymap contains all keys supported by vispy.
        """
        keymap = self._module.KEYMAP
        vispy_keys = keymap.values()
        for keyname in dir(keys):
            if keyname.upper() != keyname:
                continue
            key = getattr(keys, keyname)
            assert key in vispy_keys
    
    
    def test_methods(self):
        """ Test that all _vispy_x methods are there.
        """
        exceptions = '_vispy_get_native_canvas', '_vispy_get_native_timer', '_vispy_get_native_app'
        
        Klass = self._module.CanvasBackend
        KlassRef = vispy.app.canvas.CanvasBackend
        for key in dir(KlassRef):
            if not key.startswith('__'):
                method = getattr(Klass, key)
                if key not in exceptions:
                    if hasattr(method, '__module__'): 
                        assert method.__module__ == self._module.__name__ # Py3k
                    else:
                        assert method.im_func.__module__ == self._module.__name__
        
        Klass = self._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__'): 
                        assert method.__module__ == self._module.__name__ # Py3k
                    else:
                        assert method.im_func.__module__ == self._module.__name__
        
        Klass = self._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__'): 
                        assert method.__module__ == self._module.__name__ # Py3k
                    else:
                        assert method.im_func.__module__ == self._module.__name__
    
    
    def test_events(self):
        """ Test that all events seem to be emitted.
        """
        # Get text
        fname = self._module.__file__.strip('c')
        text = open(fname, 'rb').read().decode('utf-8')
        
        canvas = vispy.app.Canvas(native=None)
        eventNames = set(canvas.events._emitters.keys())
        eventNames.discard('stylus'); eventNames.discard('touch') # Leave this for now
        
        for name in eventNames:
            assert 'events.%s'%name in text



class Test_TemplateBackend(BaseTestmodule):
    def __init__(self):
        from vispy.app.backends import template
        BaseTestmodule.__init__(self, template)

class Test_QtBackend(BaseTestmodule):<commit_msg>updated backend tests to exclude new mouse methods.<commit_after>""" Tests to quickly see if the backends look good.
This tests only to see if all the necessary methods are implemented,
whether all the right events are mentioned, and whether the keymap 
contains all keys that should be supported.

This test basically checks whether nothing was forgotten, not that the
implementation is corect.
 
"""

import sys

import vispy
from vispy import keys

class BaseTestmodule:
    
    def __init__(self, module=None):
        self._module = module
        if module is None:
            print("Skipping %s." % self.__class__.__name__)
            self.test_events = lambda : None
            self.test_keymap = lambda : None
            self.test_methods = lambda : None
    
    
    def test_keymap(self):
        """ Test that the keymap contains all keys supported by vispy.
        """
        keymap = self._module.KEYMAP
        vispy_keys = keymap.values()
        for keyname in dir(keys):
            if keyname.upper() != keyname:
                continue
            key = getattr(keys, keyname)
            assert key in vispy_keys
    
    
    def test_methods(self):
        """ Test that all _vispy_x methods are there.
        """
        exceptions = ('_vispy_get_native_canvas', '_vispy_get_native_timer', '_vispy_get_native_app', 
                      '_vispy_mouse_move', '_vispy_mouse_press', '_vispy_mouse_release')
        
        Klass = self._module.CanvasBackend
        KlassRef = vispy.app.canvas.CanvasBackend
        for key in dir(KlassRef):
            if not key.startswith('__'):
                method = getattr(Klass, key)
                if key not in exceptions:
                    if hasattr(method, '__module__'):
                        mod_str = method.__module__ # Py3k
                    else:
                        mod_str = method.im_func.__module__
                    assert mod_str == self._module.__name__, "Method %s.%s not defined in %s"%(Klass, key, self._module.__name__)
        
        Klass = self._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__'): 
                        assert method.__module__ == self._module.__name__ # Py3k
                    else:
                        assert method.im_func.__module__ == self._module.__name__
        
        Klass = self._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__'): 
                        assert method.__module__ == self._module.__name__ # Py3k
                    else:
                        assert method.im_func.__module__ == self._module.__name__
    
    
    def test_events(self):
        """ Test that all events seem to be emitted.
        """
        # Get text
        fname = self._module.__file__.strip('c')
        text = open(fname, 'rb').read().decode('utf-8')
        
        canvas = vispy.app.Canvas(native=None)
        # 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', 'mouse_move', 'mouse_release'])
        eventNames = set(canvas.events._emitters.keys()) - ignore
        
        for name in eventNames:
            assert 'events.%s'%name in text, 'events.%s does not appear in %s'%(name, fname)



class Test_TemplateBackend(BaseTestmodule):
    def __init__(self):
        from vispy.app.backends import template
        BaseTestmodule.__init__(self, template)

class Test_QtBackend(BaseTestmodule):
{'fraction_non_alphanumeric': 0.08352114543285165, 'fraction_numerical': 0.001060585973750497, 'mean_word_length': 1.8993082244427364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5980310', 'n_tokens_mistral': 2045, 'n_tokens_neox': 2009, 'n_words': 578}