Robot Framework
modelobject.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import copy
17 
18 from robot.utils import SetterAwareType
19 
20 
21 class ModelObject(metaclass=SetterAwareType):
22  repr_args = ()
23  __slots__ = []
24 
25 
32  def config(self, **attributes):
33  for name in attributes:
34  setattr(self, name, attributes[name])
35  return self
36 
37 
46  def copy(self, **attributes):
47  copied = copy.copy(self)
48  for name in attributes:
49  setattr(copied, name, attributes[name])
50  return copied
51 
52 
61  def deepcopy(self, **attributes):
62  copied = copy.deepcopy(self)
63  for name in attributes:
64  setattr(copied, name, attributes[name])
65  return copied
66 
67  def __repr__(self):
68  return self._repr_repr(self.repr_argsrepr_args)
69 
70  def _repr(self, repr_args):
71  args = ', '.join(f'{a}={getattr(self, a)!r}' for a in repr_args)
72  return f"{full_name(self)}({args})"
73 
74 
75 def full_name(obj):
76  parts = type(obj).__module__.split('.') + [type(obj).__name__]
77  if len(parts) > 1 and parts[0] == 'robot':
78  parts[2:-1] = []
79  return '.'.join(parts)
def copy(self, **attributes)
Return shallow copy of this object.
Definition: modelobject.py:46
def config(self, **attributes)
Configure model object with given attributes.
Definition: modelobject.py:32
def deepcopy(self, **attributes)
Return deep copy of this object.
Definition: modelobject.py:61