class ModelObject(with_metaclass(SetterAwareType, object)): __slots__ = [] def __unicode__(self): return self.name def __repr__(self): return repr(str(self))
class ModelObject(with_metaclass(SetterAwareType, object)): repr_args = () __slots__ = [] def config(self, **attributes): """Configure model object with given attributes. ``obj.config(name='Example', doc='Something')`` is equivalent to setting ``obj.name = 'Example'`` and ``obj.doc = 'Something'``. New in Robot Framework 4.0. """ for name in attributes: setattr(self, name, attributes[name]) return self def copy(self, **attributes): """Return shallow copy of this object. :param attributes: Attributes to be set for the returned copy automatically. For example, ``test.copy(name='New name')``. See also :meth:`deepcopy`. The difference between these two is the same as with the standard ``copy.copy`` and ``copy.deepcopy`` functions that these methods also use internally. New in Robot Framework 3.0.1. """ copied = copy.copy(self) for name in attributes: setattr(copied, name, attributes[name]) return copied def deepcopy(self, **attributes): """Return deep copy of this object. :param attributes: Attributes to be set for the returned copy automatically. For example, ``test.deepcopy(name='New name')``. See also :meth:`copy`. The difference between these two is the same as with the standard ``copy.copy`` and ``copy.deepcopy`` functions that these methods also use internally. New in Robot Framework 3.0.1. """ copied = copy.deepcopy(self) for name in attributes: setattr(copied, name, attributes[name]) return copied def __repr__(self): args = ['%s=%r' % (n, getattr(self, n)) for n in self.repr_args] module = type(self).__module__.split('.') if len(module) > 1 and module[0] == 'robot': module = module[:2] return '%s.%s(%s)' % ('.'.join(module), type(self).__name__, ', '.join(args))
class ModelObject(with_metaclass(SetterAwareType, object)): __slots__ = [] def copy(self, **attributes): """Return shallow copy of this object. :param attributes: Attributes to be set for the returned copy automatically. For example, ``test.copy(name='New name')``. See also :meth:`deepcopy`. The difference between these two is the same as with the standard ``copy.copy`` and ``copy.deepcopy`` functions that these methods also use internally. New in Robot Framework 3.0.1. """ copied = copy.copy(self) for name in attributes: setattr(copied, name, attributes[name]) return copied def deepcopy(self, **attributes): """Return deep copy of this object. :param attributes: Attributes to be set for the returned copy automatically. For example, ``test.deepcopy(name='New name')``. See also :meth:`copy`. The difference between these two is the same as with the standard ``copy.copy`` and ``copy.deepcopy`` functions that these methods also use internally. New in Robot Framework 3.0.1. """ copied = copy.deepcopy(self) for name in attributes: setattr(copied, name, attributes[name]) return copied def __unicode__(self): return self.name def __repr__(self): return repr(str(self)) def __setstate__(self, state): """Customize attribute updating when using the `copy` module. This may not be needed in the future if we fix the mess we have with different timeout types. """ # We have __slots__ so state is always a two-tuple. # Refer to: https://www.python.org/dev/peps/pep-0307 dictstate, slotstate = state if dictstate is not None: self.__dict__.update(dictstate) for name in slotstate: # If attribute is defined in __slots__ and overridden by @setter # (this is the case at least with 'timeout' of 'running.TestCase') # we must not set the "real" attribute value because that would run # the setter method and that would recreate the object when it # should not. With timeouts recreating object using the object # itself would also totally fail. setter_name = '_setter__' + name if setter_name not in slotstate: setattr(self, name, slotstate[name])
class ModelObject(with_metaclass(SetterAwareType, object)): repr_args = () __slots__ = [] def config(self, **attributes): """Configure model object with given attributes. ``obj.config(name='Example', doc='Something')`` is equivalent to setting ``obj.name = 'Example'`` and ``obj.doc = 'Something'``. New in Robot Framework 4.0. """ for name in attributes: setattr(self, name, attributes[name]) return self def copy(self, **attributes): """Return shallow copy of this object. :param attributes: Attributes to be set for the returned copy automatically. For example, ``test.copy(name='New name')``. See also :meth:`deepcopy`. The difference between these two is the same as with the standard ``copy.copy`` and ``copy.deepcopy`` functions that these methods also use internally. New in Robot Framework 3.0.1. """ copied = copy.copy(self) for name in attributes: setattr(copied, name, attributes[name]) return copied def deepcopy(self, **attributes): """Return deep copy of this object. :param attributes: Attributes to be set for the returned copy automatically. For example, ``test.deepcopy(name='New name')``. See also :meth:`copy`. The difference between these two is the same as with the standard ``copy.copy`` and ``copy.deepcopy`` functions that these methods also use internally. New in Robot Framework 3.0.1. """ copied = copy.deepcopy(self) for name in attributes: setattr(copied, name, attributes[name]) return copied def __repr__(self): args = ['%s=%r' % (n, getattr(self, n)) for n in self.repr_args] module = type(self).__module__.split('.') if len(module) > 1 and module[0] == 'robot': module = module[:2] return '%s.%s(%s)' % ('.'.join(module), type(self).__name__, ', '.join(args)) def __setstate__(self, state): """Customize attribute updating when using the `copy` module. This may not be needed in the future if we fix the mess we have with different timeout types. """ # We have __slots__ so state is always a two-tuple. # Refer to: https://www.python.org/dev/peps/pep-0307 dictstate, slotstate = state if dictstate is not None: self.__dict__.update(dictstate) for name in slotstate: # If attribute is defined in __slots__ and overridden by @setter # (this is the case at least with 'timeout' of 'running.TestCase') # we must not set the "real" attribute value because that would run # the setter method and that would recreate the object when it # should not. With timeouts recreating object using the object # itself would also totally fail. setter_name = '_setter__' + name if setter_name not in slotstate: setattr(self, name, slotstate[name])