Best Python code snippet using Kiwi_python
mld_group.py
Source:mld_group.py
1# Python2import weakref3import functools4# Genie5from genie.decorator import managedattribute6from genie.conf.base import ConfigurableBase7@functools.total_ordering8class MldGroup(ConfigurableBase):9 @property10 def testbed(self):11 return self.device.testbed12 @property13 def device(self):14 return self._device()15 # join_group16 join_group = managedattribute(17 name='join_group',18 default=None,19 type=(None, managedattribute.test_istype(str)),20 doc="Configure join_group under interface.")21 # join_group_source_addr22 join_group_source_addr = managedattribute(23 name='join_group_source_addr',24 default=None,25 type=(None, managedattribute.test_istype(str)),26 doc="Configure join_group_source_addr under interface.")27 # static_group28 static_group = managedattribute(29 name='static_group',30 default=None,31 type=(None, managedattribute.test_istype(str)),32 doc="Configure static_group under interface.")33 # static_group_source_addr34 static_group_source_addr = managedattribute(35 name='static_group_source_addr',36 default=None,37 type=(None, managedattribute.test_istype(str)),38 doc="Configure static_group_source_addr under interface.")39 # ==========================================================================40 # Overload __eq__41 def __eq__(self, other):42 if not isinstance(other, MldGroup):43 raise NotImplemented44 45 return (self.join_group,46 self.join_group_source_addr,47 self.static_group,48 self.static_group_source_addr,49 self.device) == \50 (other.join_group,51 other.join_group_source_addr,52 other.static_group,53 other.static_group_source_addr,54 other.device)55 # Overload __lt__56 def __lt__(self, other):57 if not isinstance(other, MldGroup):58 raise NotImplemented("Cannot compare '{s}' to a '{o}'".format(s=type(self), o=type(other)))59 group_current = self.join_group if self.join_group else self.static_group60 group_previous = other.join_group if other.join_group else other.static_group61 source_current = self.join_group_source_addr if \62 self.join_group_source_addr else self.static_group_source_addr63 source_previous = other.join_group_source_addr if \64 other.join_group_source_addr else other.static_group_source_addr65 # Comparing same types66 if type(group_current) == type(group_previous):67 if group_current == group_previous:68 return source_current < source_previous69 return group_current < group_previous70 else:71 self_addr = str(group_current)72 other_addr = str(group_previous)73 return self_addr < other_addr74 75 # Overload __hash__76 def __hash__(self):77 return hash((self.join_group,78 self.join_group_source_addr,79 self.static_group,80 self.static_group_source_addr,81 self.device))82 # Overload __repr__83 def __repr__(self):84 if isinstance(self.join_group, str):85 return '%s object at 0x%x with string name %s/%s/%s/%s' % (86 self.__class__.__name__,87 id(self),88 self.join_group,89 self.join_group_source_addr,90 self.static_group,91 self.static_group_source_addr)92 else:93 return '%s object at 0x%x with the name %s/%s/%s/%s which is not string' % (94 self.__class__.__name__,95 id(self),96 self.join_group,97 self.join_group_source_addr,98 self.static_group,99 self.static_group_source_addr)100 def __init__(self, device, *args, **kwargs):101 self._device = weakref.ref(device)...
igmp_group.py
Source:igmp_group.py
1# Python2import weakref3import functools4# Genie5from genie.decorator import managedattribute6from genie.conf.base import ConfigurableBase7@functools.total_ordering8class IgmpGroup(ConfigurableBase):9 @property10 def testbed(self):11 return self.device.testbed12 @property13 def device(self):14 return self._device()15 # join_group16 join_group = managedattribute(17 name='join_group',18 default=None,19 type=(None, managedattribute.test_istype(str)),20 doc="Configure join_group under interface.")21 # join_group_source_addr22 join_group_source_addr = managedattribute(23 name='join_group_source_addr',24 default=None,25 type=(None, managedattribute.test_istype(str)),26 doc="Configure join_group_source_addr under interface.")27 # static_group28 static_group = managedattribute(29 name='static_group',30 default=None,31 type=(None, managedattribute.test_istype(str)),32 doc="Configure static_group under interface.")33 # static_group_source_addr34 static_group_source_addr = managedattribute(35 name='static_group_source_addr',36 default=None,37 type=(None, managedattribute.test_istype(str)),38 doc="Configure static_group_source_addr under interface.")39 # ==========================================================================40 # Overload __eq__41 def __eq__(self, other):42 if not isinstance(other, IgmpGroup):43 raise NotImplemented44 45 return (self.join_group,46 self.join_group_source_addr,47 self.static_group,48 self.static_group_source_addr,49 self.device) == \50 (other.join_group,51 other.join_group_source_addr,52 other.static_group,53 other.static_group_source_addr,54 other.device)55 # Overload __lt__56 def __lt__(self, other):57 if not isinstance(other, IgmpGroup):58 raise NotImplemented("Cannot compare '{s}' to a '{o}'".format(s=type(self), o=type(other)))59 group_current = self.join_group if self.join_group else self.static_group60 group_previous = other.join_group if other.join_group else other.static_group61 source_current = self.join_group_source_addr if \62 self.join_group_source_addr else self.static_group_source_addr63 source_previous = other.join_group_source_addr if \64 other.join_group_source_addr else other.static_group_source_addr65 # Comparing same types66 if type(group_current) == type(group_previous):67 if group_current == group_previous:68 return source_current < source_previous69 return group_current < group_previous70 else:71 self_addr = str(group_current)72 other_addr = str(group_previous)73 return self_addr < other_addr74 75 # Overload __hash__76 def __hash__(self):77 return hash((self.join_group,78 self.join_group_source_addr,79 self.static_group,80 self.static_group_source_addr,81 self.device))82 # Overload __repr__83 def __repr__(self):84 if isinstance(self.join_group, str):85 return '%s object at 0x%x with string name %s/%s/%s/%s' % (86 self.__class__.__name__,87 id(self),88 self.join_group,89 self.join_group_source_addr,90 self.static_group,91 self.static_group_source_addr)92 else:93 return '%s object at 0x%x with none string name %s/%s/%s/%s' % (94 self.__class__.__name__,95 id(self),96 self.join_group,97 self.join_group_source_addr,98 self.static_group,99 self.static_group_source_addr)100 def __init__(self, device, *args, **kwargs):101 self._device = weakref.ref(device)...
app.py
Source:app.py
1groups = open("day_6/input.txt").read().split('\n\n')2total = 03for group in groups:4 letters = []5 group_l = group.split('\n')6 if '' in group_l:7 group_l.remove('')8 if len(group_l) == 1:9 total += len(set([char for char in group.replace('\n', '')]))10 else:11 join_group = ''.join(group_l)12 print(set(join_group))13 print(join_group)14 for l in set(join_group):15 if join_group.count(l) >= len(group_l):16 total += 1...
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!!