Ejemplo n.º 1
0
 def __getattribute__(self, name):
     Q = type(self).Q
     if name == 'Q':
         return Q
     try:
         _qclass.__getattribute__(self, 'set' + camelize(name))
     except AttributeError:
         attr = _qclass.__getattribute__(self, name)
         if name.endswith('Event'):
             try:
                 event = self.__dict__[name]
             except KeyError:
                 event = self.__dict__[name] = Event(name, attr)
             return event
         if isinstance(attr, Q.qboundsignalclass):
             try:
                 signal = self.__dict__[name]
             except KeyError:
                 signal = self.__dict__[name] = Signal(name, attr)
                 attr.connect(signal.run)
             return signal
         return attr
     try:
         getter = _qclass.__getattribute__(self, name)
     except AttributeError:
         getter = _qclass.__getattribute__(self,
                                           'is' + camelize(name))
     value = getter()
     if isinstance(value, (Q.QtCore.QObject, Q.qbaseclass)):
         return Q(value)
     return value
Ejemplo n.º 2
0
 def __getattribute__(self, name):
     Q = type(self).Q
     if name == 'Q':
         return Q
     try:
         _qclass.__getattribute__(self, 'set' + camelize(name))
     except AttributeError:
         attr = _qclass.__getattribute__(self, name)
         if name.endswith('Event'):
             try:
                 event = self.__dict__[name]
             except KeyError:
                 event = self.__dict__[name] = Event(name, attr)
             return event
         if isinstance(attr, Q.qboundsignalclass):
             try:
                 signal = self.__dict__[name]
             except KeyError:
                 signal = self.__dict__[name] = Signal(
                   name, attr)
                 attr.connect(signal.run)
             return signal
         return attr
     try:
         getter = _qclass.__getattribute__(self, name)
     except AttributeError:
         getter = _qclass.__getattribute__(
           self, 'is' + camelize(name))
     value = getter()
     if isinstance(value, (Q.QtCore.QObject, Q.qbaseclass)):
         return Q(value)
     return value
Ejemplo n.º 3
0
 def test__iter__(self, inspector, stdlib, stdlib_kwfuncnames):
     kwnames = [camelize(n, joiner=' ') for n in stdlib_kwfuncnames]
     for keyword in iter(inspector):
         assert isinstance(keyword,
                           robottools.library.inspector.KeywordInspector)
         kwnames.remove(keyword.name)
     assert not kwnames
Ejemplo n.º 4
0
            def __setattr__(self, name, value):
                Q = type(self).Q
                try:
                    setter = getattr(self, 'set' + camelize(name))
                except AttributeError:
                    pass
                else:
                    setter(value)
                    return

                try:
                    attr = _qclass.__getattribute__(self, name)
                except AttributeError:
                    pass
                else:
                    if isinstance(attr, Q.qboundsignalclass):
                        try:
                            signal = self.__dict__[name]
                        except KeyError:
                            signal = self.__dict__[name] = Signal(
                              name, attr)
                            attr.connect(signal.run)
                        if value is not signal:
                            if callable(value):
                                signal.slots = [value]
                            else:
                                signal.slots = value
                        return

                _qclass.__setattr__(self, name, value)
Ejemplo n.º 5
0
            def __setattr__(self, name, value):
                Q = type(self).Q
                try:
                    setter = getattr(self, 'set' + camelize(name))
                except AttributeError:
                    pass
                else:
                    setter(value)
                    return

                try:
                    attr = _qclass.__getattribute__(self, name)
                except AttributeError:
                    pass
                else:
                    if isinstance(attr, Q.qboundsignalclass):
                        try:
                            signal = self.__dict__[name]
                        except KeyError:
                            signal = self.__dict__[name] = Signal(name, attr)
                            attr.connect(signal.run)
                        if value is not signal:
                            if callable(value):
                                signal.slots = [value]
                            else:
                                signal.slots = value
                        return

                _qclass.__setattr__(self, name, value)
Ejemplo n.º 6
0
 def __setattr__(self, name, value):
     if name == 'qlist':
         object.__setattr__(self, name, value)
     for q in self.qlist:
         try:
             setter = getattr(q, 'set' + camelize(name))
         except AttributeError:
             object.__setattr__(self, name, value)
             break
         else:
             setter(value)
 def test__getattr__(self, inspector, stdlib):
     # filter keyword methods from directly instantiated stdlib
     kwfuncnames = [name for name, obj in getmembers(stdlib) if name[0] != "_" and ismethod(obj)]
     # and check that __getattr__ works with with keyword method names
     # as well as with normalized and camelized keyword names
     for name, normalized, camelized in zip(kwfuncnames, map(normalize, kwfuncnames), map(camelize, kwfuncnames)):
         keyword, from_normalized, from_camelized = (getattr(inspector, n) for n in [name, normalized, camelized])
         assert keyword == from_normalized == from_camelized
         for keyword in [keyword, from_normalized, from_camelized]:
             assert isinstance(keyword, robottools.library.inspector.KeywordInspector)
             assert keyword.name == camelize(name, joiner=" ")
Ejemplo n.º 8
0
 def __getattr__(self, name):
     Q = self.Q
     values = []
     for q in self.qlist:
         obj = object.__getattribute__(q, name)
         if hasattr(q, 'set' + camelize(name)):
             values.append(obj())
         else:
             values.append(obj)
     try:
         return Q(values)
     except TypeError:
         return tuple(values)
 def check__getattr__Keyword(self, robot, libname, kwfuncnames):
     """Helper method to check that access to all Keywords
     given by their original function names works
     in different name formats.
     """
     for funcname, camelized, normalized in zip(kwfuncnames,
                                                map(camelize, kwfuncnames),
                                                map(normalize,
                                                    kwfuncnames)):
         for name in funcname, camelized, normalized:
             keyword = getattr(robot, name)
             assert isinstance(keyword, robottools.testrobot.Keyword)
             assert keyword.name == camelize(funcname, joiner=' ')
             assert keyword.libname == libname
Ejemplo n.º 10
0
    def __call__(self, func=None, id=None, text=None, **props):
        if not func:
            if id:
                self.id = id
            if text:
                self.text = text
            return self

        props['text'] = text or self.text or camelize(
          func.__name__, joiner=' ')
        props['clicked'] = lambda arg: func()
        id = id or self.id
        if id:
            if id is True:
                id = func.__name__ + 'Button'
            props['id'] = id
        return self.Q.PushButton(**props)
Ejemplo n.º 11
0
            def __init__(self, *args, **kwargs):
                Q = self.Q
                if args and args[0] is self:
                    return

                self.qclass.__init__(self, *args)
                self.q = self
                self.qxclass.__init__(self, kwargs)
                for name, value in kwargs.items():
                    if name == "id":
                        self.id = value
                        continue
                    try:
                        setter = _qclass.__getattribute__(
                            self, 'set' + camelize(name))
                    except AttributeError:
                        attr = _qclass.__getattribute__(self, name)
                        if name.endswith('Event'):
                            try:
                                event = self.__dict__[name]
                            except KeyError:
                                event = self.__dict__[name] = Event(name, attr)
                            if callable(value):
                                event.slots = [value]
                            else:
                                event.slots = value
                        elif isinstance(attr, Q.qboundsignalclass):
                            try:
                                signal = self.__dict__[name]
                            except KeyError:
                                signal = self.__dict__[name] = Signal(
                                    name, attr)
                                attr.connect(signal.run)
                            if value is not signal:
                                if callable(value):
                                    signal.slots = [value]
                                else:
                                    signal.slots = value
                    else:
                        setter(value)

                @self.signal
                def slot(partial):
                    partial()

                self.emit = Emitter(q=self)
Ejemplo n.º 12
0
    def __call__(self, func=None, id=None, text=None, **props):
        if not func:
            if id:
                self.id = id
            if text:
                self.text = text
            return self

        props['text'] = text or self.text or camelize(func.__name__,
                                                      joiner=' ')
        props['clicked'] = lambda arg: func()
        id = id or self.id
        if id:
            if id is True:
                id = func.__name__ + 'Button'
            props['id'] = id
        return self.Q.PushButton(**props)
Ejemplo n.º 13
0
            def __init__(self, *args, **kwargs):
                Q = self.Q
                if args and args[0] is self:
                    return

                self.qclass.__init__(self, *args)
                self.q = self
                self.qxclass.__init__(self, kwargs)
                for name, value in kwargs.items():
                    if name == "id":
                        self.id = value
                        continue
                    try:
                        setter = _qclass.__getattribute__(
                          self, 'set' + camelize(name))
                    except AttributeError:
                        attr = _qclass.__getattribute__(self, name)
                        if name.endswith('Event'):
                            try:
                                event = self.__dict__[name]
                            except KeyError:
                                event = self.__dict__[name] = Event(name, attr)
                            if callable(value):
                                event.slots = [value]
                            else:
                                event.slots = value
                        elif isinstance(attr, Q.qboundsignalclass):
                            try:
                                signal = self.__dict__[name]
                            except KeyError:
                                signal = self.__dict__[name] = Signal(
                                  name, attr)
                                attr.connect(signal.run)
                            if value is not signal:
                                if callable(value):
                                    signal.slots = [value]
                                else:
                                    signal.slots = value
                    else:
                        setter(value)

                @self.signal
                def slot(partial):
                    partial()

                self.emit = Emitter(q=self)
Ejemplo n.º 14
0
 def test__getattr__(self, inspector, stdlib):
     # filter keyword methods from directly instantiated stdlib
     kwfuncnames = [
         name for name, obj in getmembers(stdlib)
         if name[0] != '_' and ismethod(obj)
     ]
     # and check that __getattr__ works with with keyword method names
     # as well as with normalized and camelized keyword names
     for name, normalized, camelized in zip(kwfuncnames,
                                            map(normalize, kwfuncnames),
                                            map(camelize, kwfuncnames)):
         keyword, from_normalized, from_camelized = (getattr(
             inspector, n) for n in [name, normalized, camelized])
         assert keyword == from_normalized == from_camelized
         for keyword in [keyword, from_normalized, from_camelized]:
             assert isinstance(
                 keyword, robottools.library.inspector.KeywordInspector)
             assert keyword.name == camelize(name, joiner=' ')
Ejemplo n.º 15
0
def test_camelize():
    """Test the string camelize() function.
    """
    for lower_case, CamelCase in CAMELIZED:
        assert camelize(lower_case) == CamelCase
Ejemplo n.º 16
0
 def __getattr__(self, name):
     value = getattr(self.com, camelize(name))
     if isinstance(value, DispatchBaseClass):
         return type(self)(value)
     return value
 def test__iter__(self, inspector, stdlib, stdlib_kwfuncnames):
     kwnames = [camelize(n, joiner=" ") for n in stdlib_kwfuncnames]
     for keyword in iter(inspector):
         assert isinstance(keyword, robottools.library.inspector.KeywordInspector)
         kwnames.remove(keyword.name)
     assert not kwnames
Ejemplo n.º 18
0
 def __new__(cls, name='', convert=True):
     if convert and type(name) is not KeywordName:
         name = camelize(name, joiner=' ')
     return str.__new__(cls, name)
Ejemplo n.º 19
0
    def __init__(self, handlerclsname=None, options=None):
        """Generate several variants of a session handler name
           for use in identifiers and message strings.

        - Based on the `handlerclsname`
          and/or the attributes of the optional
          `Handler.Meta` class in `options`,
          which can define name (variant) prefixes/suffixes
          and/or explicit name variants.
        """
        # Check all prefix definitions and generate actual prefix strings
        prefixes = {}

        def gen_prefix(key, default, append=''):
            """Check the prefix definition
               for name variant identified by `key`.

            - Set to `default` if not defined.
            - Always `append` the given extra string.
            """
            try:
                prefix = getattr(
                  options, (key and key + '_') + 'name_prefix')
            except AttributeError:
                prefix = default
            else:
                prefix = prefix and str(prefix) or ''
            if prefix and not prefix.endswith(append):
                prefix += append
            # Finally add to the prefixes dictionary
            prefixes[key] = prefix

        def gen_plural_prefix(key, append=''):
            """Check the prefix definition
               for plural name variant identified by plural_`key`.

            - Set to singular `key` prefix if not defined.
            - Always `append` the given extra string.
            """
            plural_key = 'plural' + (key and '_' + key)
            default = prefixes[key]
            gen_prefix(plural_key, default, append)

        # Base name prefixes
        gen_prefix('', '', '_')
        gen_plural_prefix('', '_')
        gen_prefix('upper', camelize(prefixes['']))
        gen_plural_prefix('upper')
        # Identifier name prefixes
        gen_prefix('identifier', '', '_')
        gen_plural_prefix('identifier', '_')
        gen_prefix('upper_identifier', camelize(prefixes['identifier']))
        # Verbose name prefixes
        gen_prefix('verbose', '', ' ')
        gen_plural_prefix('verbose', ' ')

        # Check all suffix definitions and generate actual suffix strings
        suffixes = {}

        def gen_suffix(key, default, prepend=''):
            """Check the suffix definition
               for name variant identified by `key`.

            - Set to `default` if not defined.
            - Always `prepend` the given extra string.
            """
            try:
                suffix = getattr(options, key + '_name_suffix')
            except AttributeError:
                suffix = default
            else:
                suffix = suffix and str(suffix) or ''
            if suffix and not suffix.startswith(prepend):
                suffix = prepend + suffix
            # Finally add to the suffixes dictionary
            suffixes[key] = suffix

        def gen_plural_suffix(key, prepend=''):
            """Check the suffix definition
               for plural name variant identified by plural_`key`.

            - Set to singular `key` suffix + 's' if not defined.
            - Always `prepend` the given extra string.
            """
            plural_key = 'plural' + (key and '_' + key)
            default = suffixes[key] and suffixes[key] + 's'
            gen_suffix(plural_key, default, prepend)

        # Identifier name suffixes
        gen_suffix('', '', '_')
        gen_plural_suffix('', '_')
        gen_suffix('upper', camelize(suffixes['']))
        gen_plural_suffix('upper')
        # Identifier name suffixes
        ## gen_suffix('identifier', 'session', '_')
        gen_suffix('identifier', '', '_')
        gen_plural_suffix('identifier', '_')
        gen_suffix('upper_identifier', camelize(suffixes['identifier']))
        # Verbose name suffixes
        ## gen_suffix('verbose', 'Session', ' ')
        gen_suffix('verbose', '', ' ')
        gen_plural_suffix('verbose', ' ')

        # Check explicit name variant definitions
        variants = {}
        for variantkey in (
          '', 'plural', 'upper', 'plural_upper',
          'identifier', 'plural_identifier', 'upper_identifier',
          'verbose', 'plural_verbose'
          ):
            defname = (variantkey and variantkey + '_') + 'name'
            variant = getattr(options, defname, None)
            # Non-empty string or None
            variant = variant and (str(variant) or None) or None
            variants[variantkey] = variant

        # Create final base name (helper) variants
        # (NOT stored in final meta object (self))
        key = ''
        name = (
          variants[key]
          or prefixes[key] + decamelize(handlerclsname) + suffixes[key])
        key = 'plural'
        plural_name = (
          variants[key] and prefixes[key] + variants[key] + suffixes[key]
          or None)
        key = 'upper'
        upper_name = (
          variants[key]
          or variants[''] and camelize(variants[''])
          or prefixes[key] + handlerclsname + suffixes[key])
        key = 'plural_upper'
        plural_upper_name = (
          variants[key]
          or variants['plural']
          and prefixes[key] + camelize(variants['plural']) + (
            suffixes[key] or (not variants['plural'] and 's' or ''))
          or None)

        # Create final identifier/verbose name variants
        # (stored in final meta object (self))
        key = 'identifier'
        self.identifier_name = (
          variants[key]
          or prefixes[key] + name + suffixes[key])
        key = 'plural_identifier'
        self.plural_identifier_name = (
          variants[key]
          or prefixes[key] + (plural_name or name) + (
            suffixes[key] or (not plural_name and 's' or '')))
        key = 'upper_identifier'
        self.upper_identifier_name = (
          variants[key]
          or prefixes[key] + upper_name + suffixes[key])
        key = 'verbose'
        self.verbose_name = (
          variants[key]
          or prefixes[key] + upper_name + suffixes[key])
        key = 'plural_verbose'
        self.plural_verbose_name = (
          variants[key]
          or prefixes[key] + (plural_upper_name or upper_name) + (
            suffixes[key] or (not plural_upper_name and 's' or '')))
Ejemplo n.º 20
0
 def __new__(cls, name, convert=True):
     if convert and type(name) is not KeywordName:
         name = camelize(name, joiner=' ')
     return str.__new__(cls, name)
Ejemplo n.º 21
0
def test_camelize():
    """Test the string camelize() function.
    """
    for lower_case, CamelCase in CAMELIZED:
        assert camelize(lower_case) == CamelCase
Ejemplo n.º 22
0
    def __init__(self, handlerclsname=None, options=None):
        """Generate several variants of the session handler name
           for use in identifiers and message strings
           and store additional general `options`
           given as ``Handler.Meta`` class object.

        - Name generation is based on the `handlerclsname`
          and/or related `options` attributes,
          which can define name (variant) prefixes/suffixes
          and/or explicit name variants.
        """
        self.auto_explicit = bool(getattr(options, 'auto_explicit', False))

        # Check all prefix definitions and generate actual prefix strings
        prefixes = {}

        def gen_prefix(key, default, append=''):
            """Check the prefix definition
               for name variant identified by `key`.

            - Set to `default` if not defined.
            - Always `append` the given extra string.
            """
            try:
                prefix = getattr(options, (key and key + '_') + 'name_prefix')
            except AttributeError:
                prefix = default
            else:
                prefix = prefix and str(prefix) or ''
            if prefix and not prefix.endswith(append):
                prefix += append
            # Finally add to the prefixes dictionary
            prefixes[key] = prefix

        def gen_plural_prefix(key, append=''):
            """Check the prefix definition
               for plural name variant identified by plural_`key`.

            - Set to singular `key` prefix if not defined.
            - Always `append` the given extra string.
            """
            plural_key = 'plural' + (key and '_' + key)
            default = prefixes[key]
            gen_prefix(plural_key, default, append)

        # Base name prefixes
        gen_prefix('', '', '_')
        gen_plural_prefix('', '_')
        gen_prefix('upper', camelize(prefixes['']))
        gen_plural_prefix('upper')
        # Identifier name prefixes
        gen_prefix('identifier', '', '_')
        gen_plural_prefix('identifier', '_')
        gen_prefix('upper_identifier', camelize(prefixes['identifier']))
        # Verbose name prefixes
        gen_prefix('verbose', '', ' ')
        gen_plural_prefix('verbose', ' ')

        # Check all suffix definitions and generate actual suffix strings
        suffixes = {}

        def gen_suffix(key, default, prepend=''):
            """Check the suffix definition
               for name variant identified by `key`.

            - Set to `default` if not defined.
            - Always `prepend` the given extra string.
            """
            try:
                suffix = getattr(options, key + '_name_suffix')
            except AttributeError:
                suffix = default
            else:
                suffix = suffix and str(suffix) or ''
            if suffix and not suffix.startswith(prepend):
                suffix = prepend + suffix
            # Finally add to the suffixes dictionary
            suffixes[key] = suffix

        def gen_plural_suffix(key, prepend=''):
            """Check the suffix definition
               for plural name variant identified by plural_`key`.

            - Set to singular `key` suffix + 's' if not defined.
            - Always `prepend` the given extra string.
            """
            plural_key = 'plural' + (key and '_' + key)
            default = suffixes[key] and suffixes[key] + 's'
            gen_suffix(plural_key, default, prepend)

        # Identifier name suffixes
        gen_suffix('', '', '_')
        gen_plural_suffix('', '_')
        gen_suffix('upper', camelize(suffixes['']))
        gen_plural_suffix('upper')
        # Identifier name suffixes
        ## gen_suffix('identifier', 'session', '_')
        gen_suffix('identifier', '', '_')
        gen_plural_suffix('identifier', '_')
        gen_suffix('upper_identifier', camelize(suffixes['identifier']))
        # Verbose name suffixes
        ## gen_suffix('verbose', 'Session', ' ')
        gen_suffix('verbose', '', ' ')
        gen_plural_suffix('verbose', ' ')

        # Check explicit name variant definitions
        variants = {}
        for variantkey in ('', 'plural', 'upper', 'plural_upper', 'identifier',
                           'plural_identifier', 'upper_identifier', 'verbose',
                           'plural_verbose'):
            defname = (variantkey and variantkey + '_') + 'name'
            variant = getattr(options, defname, None)
            # Non-empty string or None
            variant = variant and (str(variant) or None) or None
            variants[variantkey] = variant

        # Create final base name (helper) variants
        # (NOT stored in final meta object (self))
        key = ''
        name = (variants[key]
                or prefixes[key] + decamelize(handlerclsname) + suffixes[key])
        key = 'plural'
        plural_name = (variants[key]
                       and prefixes[key] + variants[key] + suffixes[key]
                       or None)
        key = 'upper'
        upper_name = (variants[key] or variants[''] and camelize(variants[''])
                      or prefixes[key] + handlerclsname + suffixes[key])
        key = 'plural_upper'
        plural_upper_name = (variants[key] or variants['plural']
                             and prefixes[key] + camelize(variants['plural']) +
                             (suffixes[key] or
                              (not variants['plural'] and 's' or '')) or None)

        # Create final identifier/verbose name variants
        # (stored in final meta object (self))
        key = 'identifier'
        self.identifier_name = (variants[key]
                                or prefixes[key] + name + suffixes[key])
        key = 'plural_identifier'
        self.plural_identifier_name = (variants[key] or prefixes[key] +
                                       (plural_name or name) +
                                       (suffixes[key] or
                                        (not plural_name and 's' or '')))
        key = 'upper_identifier'
        self.upper_identifier_name = (variants[key] or prefixes[key] +
                                      upper_name + suffixes[key])
        key = 'verbose'
        self.verbose_name = (variants[key]
                             or prefixes[key] + upper_name + suffixes[key])
        key = 'plural_verbose'
        self.plural_verbose_name = (variants[key] or prefixes[key] +
                                    (plural_upper_name or upper_name) +
                                    (suffixes[key] or
                                     (not plural_upper_name and 's' or '')))