Best Python code snippet using autotest_python
net_tc.py
Source:net_tc.py
...43 self._minor = minor44 def get_leaf_qdisc(self):45 return self._leaf_qdisc46 def set_leaf_qdisc(self, leaf_qdisc):47 leaf_qdisc.set_parent_class(self)48 self._leaf_qdisc = leaf_qdisc49 def get_parent_class(self):50 return self._parent_class51 def set_parent_class(self, parent_class):52 self._parent_class = parent_class53 def get_minor(self):54 return self._minor55 def id(self):56 return '%s:%s' % (self._handle, self._minor)57 def add_child(self, child_class):58 child_class.set_parent_class(self)59 if child_class not in self._children:60 self._child.append(child_class)61 def setup(self, netif):62 # setup leaf qdisc63 if self._leaf_qdisc:64 self._leaf_qdisc.setup(netif)65 # setup child classes66 for child in self._children:67 child.setup()68 def restore(self, netif):69 # restore child classes70 children_copy = list(self._children)71 children_copy.reverse()72 for child in children_copy:73 child.restore()74 # restore leaf qdisc75 if self._leaf_qdisc:76 self._leaf_qdisc.restore(netif)77class tcfilter(object):78 _tc_cmd = 'tc filter %(cmd)s dev %(dev)s parent %(parent)s protocol ' \79 '%(protocol)s prio %(priority)s %(filtertype)s \\\n ' \80 '%(rules)s \\\n flowid %(flowid)s'81 conf_device = 'dev'82 conf_parent = 'parent'83 conf_type = 'filtertype'84 conf_protocol = 'protocol'85 conf_priority = 'priority'86 conf_flowid = 'flowid'87 conf_command = 'cmd'88 conf_rules = 'cmd'89 conf_qdiscid = 'qdiscid'90 conf_name = 'name'91 conf_params = 'params'92 def __init__(self):93 self._parent_qdisc = None94 self._dest_qdisc = None95 self._protocol = 'ip'96 self._priority = 197 self._handle = None98 self._tc_conf = None99 def get_parent_qdisc(self):100 return self._parent_qdisc101 def set_parent_qdisc(self, parent_qdisc):102 self._parent_qdisc = parent_qdisc103 def get_dest_qdisc(self):104 return self._dest_qdisc105 def set_dest_qdisc(self, dest_qdisc):106 self._dest_qdisc = dest_qdisc107 def get_protocol(self):108 return self._protocol109 def set_protocol(self, protocol):110 self._protocol = protocol111 def get_priority(self):112 return self._priority113 def set_priority(self, priority):114 self._priority = priority115 def get_handle(self):116 return self._handle117 def set_handle(self, handle):118 self._handle = handle119 def _get_tc_conf(self, netif):120 if self._tc_conf:121 return self._tc_conf122 self._tc_conf = dict()123 self._tc_conf[tcfilter.conf_device] = netif.get_name()124 self._tc_conf[tcfilter.conf_parent] = self._parent_qdisc.id()125 self._tc_conf[tcfilter.conf_type] = self.filtertype126 self._tc_conf[tcfilter.conf_protocol] = self._protocol127 self._tc_conf[tcfilter.conf_priotity] = self._priority128 self._tc_conf[tcfilter.conf_flowid] = (129 self._dest_qdisc.get_parent_class().id())130 return self._tc_conf131 def tc_cmd(self, tc_conf):132 print self._tc_cmd % tc_conf133 def setup(self, netif):134 pass135 def restore(self, netif):136 pass137class u32filter(tcfilter):138 filtertype = 'u32'139 def __init__(self):140 super(u32filter, self).__init__()141 self._rules = []142 def _filter_rules(self):143 return ' \\\n '.join(self._rules)144 def add_rule(self, rule):145 self._rules.append(rule)146 def setup(self, netif):147 tc_conf = self._get_tc_conf(netif)148 tc_conf[tcfilter.conf_cmd] = 'add'149 tc_conf[tcfilter.conf_rules] = self._filter_rules()150 self.tc_cmd(tc_conf)151 def restore(self, netif):152 tc_conf = self._get_tc_conf(netif)153 tc_conf[tcfilter.conf_cmd] = 'del'154 tc_conf[tcfilter.conf_rules] = self._filter_rules()155 self.tc_cmd(tc_conf)156#TODO (ncrao): generate some typical rules: ack, syn, synack,157# dport/sport, daddr/sddr, etc.158class qdisc(object):159 # tc command160 _tc_cmd = 'tc qdisc %(cmd)s dev %(dev)s %(parent)s ' \161 'handle %(qdiscid)s %(name)s %(params)s'162 def __init__(self, handle):163 self._handle = handle164 self._parent_class = None165 self._tc_conf = None166 def get_handle(self):167 return self._handle168 def get_parent_class(self):169 return self._parent_class170 def set_parent_class(self, parent_class):171 self._parent_class = parent_class172 def _get_tc_conf(self, netif):173 if self._tc_conf:174 return self._tc_conf175 self._tc_conf = dict()176 self._tc_conf[tcfilter.conf_device] = netif.get_name()177 if self._parent_class:178 self._tc_conf[tcfilter.conf_parent] = ('parent %s' %179 self._parent_class.id())180 else:181 self._tc_conf[tcfilter.conf_parent] = 'root'182 self._tc_conf[tcfilter.conf_qdiscid] = self.id()183 self._tc_conf[tcfilter.conf_name] = self.name184 self._tc_conf[tcfilter.conf_params] = ''...
datatypes.py
Source:datatypes.py
...21 self.kwargs = kwargs22 self.resolver = TemplateFunction(resolver or default_resolver)\23 .set_default_hook(lambda *a, **kwa: self._default)\24 .set_permissions_hook(build_permissions_fn(self.permissions))25 def set_parent_class(self, cls):26 self.parent_class = cls27 def nullable(self, input=False):28 if not input:29 return self._nullable30 if self._nullable_if_input is None:31 return self._nullable32 return self._nullable_if_input33 def default(self, input=False):34 if not input:35 return self._default36 if self._default_if_input is None:37 return self._default38 return self._default_if_input39 def to_string(self):40 return "Type"41 def __str__(self):42 return "{}{}".format(self.to_string(), "" if self.nullable() else "!")43 def __repr__(self):44 return str(self)45class PrimitiveType(Type):46 pass47class IntegerType(PrimitiveType):48 def to_string(self):49 return "Integer"50class FloatType(PrimitiveType):51 def to_string(self):52 return "Float"53class StringType(PrimitiveType):54 def to_string(self):55 return "String"56class BooleanType(PrimitiveType):57 def to_string(self):58 return "Boolean"59class DateType(PrimitiveType):60 def to_string(self):61 return "Date"62class TimeType(PrimitiveType):63 def to_string(self):64 return "Time"65class DateTimeType(PrimitiveType):66 def to_string(self):67 return "DateTime"68class DurationType(PrimitiveType):69 def to_string(self):70 return "Duration"71class ObjectType(Type):72 _set_ref_handler = None # Django model handler goes here - this way, we don't mix layers73 _create_handler = None74 def __init__(self, to, nullable=False, default=None, parameters=None, resolver=None,75 nullable_if_input=None, default_if_input=None, **kwargs):76 super().__init__(nullable=nullable, default=default, parameters=parameters, resolver=resolver,77 nullable_if_input=nullable_if_input, default_if_input=default_if_input, **kwargs)78 self.to = to79 if ObjectType._create_handler is not None:80 ObjectType._create_handler(self)81 def get_parent_class(self):82 return self.parent_class83 def set_ref(self):84 from simple_api.object.object import Object85 if ObjectType._set_ref_handler is not None:86 ObjectType._set_ref_handler(self)87 if isclass(self.to) and issubclass(self.to, Object):88 pass89 elif self.to == OBJECT_SELF_REFERENCE:90 self.to = self.get_parent_class()91 elif "." not in self.to:92 self.to = object_storage.get(getattr(self.get_parent_class(), "__module__", None), self.to)93 else:94 self.to = object_storage.get(*self.to.rsplit(".", 1))95 def convert(self, adapter, **kwargs):96 self.set_ref()97 return super().convert(adapter, **kwargs)98 def to_string(self):99 if isclass(self.to):100 return self.to.__name__101 return self.to102class PlainListType(Type):103 def __init__(self, of, nullable=False, default=None, parameters=None, resolver=None,104 nullable_if_input=None, default_if_input=None, **kwargs):105 super().__init__(nullable=nullable, default=default, parameters=parameters, resolver=resolver,106 nullable_if_input=nullable_if_input, default_if_input=default_if_input, **kwargs)107 self.of = of108 def set_parent_class(self, cls):109 self.of.set_parent_class(cls)110 super().set_parent_class(cls)111 def to_string(self):...
actions.py
Source:actions.py
...9 self.name = None10 super().__init__(**kwargs)11 def set_name(self, name):12 self.name = name13 def set_parent_class(self, cls):14 self.parent_class = cls15 for field in {**self.parameters, **self.data}.values():16 field.set_parent_class(cls)17 if self.return_value is not None:18 self.return_value.set_parent_class(cls)19class Action(SetReferencesMixin, ToActionMixin):20 def __init__(self, parameters=None, data=None, return_value=None, exec_fn=None, permissions=None, **kwargs):21 self.parameters = parameters or {}22 self.data = data or {}23 self.return_value = return_value24 self.exec_fn = exec_fn25 self.permissions = permissions or ()26 self.kwargs = kwargs27 self._fn = None28 self.hidden = kwargs.get("hidden", False)29 self.with_object = kwargs.get("with_object", False)30 self.hide_if_denied = kwargs.get("hide_if_denied", False)31 self.retry_in = kwargs.get("retry_in")32 for name, param in {**self.parameters, **self.data}.items():...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!