Best Python code snippet using molotov_python
common.py
Source:common.py
...64 return self._val65 @val.setter66 def val(self, value):67 self._val = value68 def __cmp__(self, other):69 if self._val < other._val:70 return -171 if self._val > other._val:72 return +173 if self._val < other._val:74 return -175 if self._val > other._val:76 return +177 return 078 def __eq__(self, other):79 return self.__cmp__(other) == 080 def __ne__(self, other):81 return self.__cmp__(other) != 082 def __gt__(self, other):83 return self.__cmp__(other) > 084 def __lt__(self, other):85 return self.__cmp__(other) < 086 def __ge__(self, other):87 return self.__cmp__(other) >= 088 def __le__(self, other):89 return self.__cmp__(other) <= 090 def __repr__(self) -> str:91 return '{}'.format(self._val)92class Interval():93 def __init__(self, min, max):94 assert min <= max95 self.min = min96 self.max = max97 def interesects(self, other):98 if other.max >= self.min and other.min <= self.max:99 return True100 return False101 def contains(self, x):102 return self.min < x < self.max103 def contains_eq(self, x):104 return x <= self.max and x >= self.min105 def __cmp__(self, other):106 if self.min < other.min:107 return -1108 elif self.min > other.min:109 return 1110 elif self.max < other.max:111 return -1112 elif self.max > other.max:113 return 1114 else:115 return 0116 def __eq__(self, other):117 return self.__cmp__(other) == 0118 def __ne__(self, other):119 return self.__cmp__(other) != 0120 def __gt__(self, other):121 return self.__cmp__(other) > 0122 def __lt__(self, other):123 return self.__cmp__(other) < 0124 def __ge__(self, other):125 return self.__cmp__(other) >= 0126 def __le__(self, other):127 return self.__cmp__(other) <= 0128 def __repr__(self):129 return 'Interval(%s, %s)' % (self.min, self.max)130class SegmentHV():131 def __init__(self, x1, y1, x2, y2):132 assert x1 <= x2 and y1 <= y2133 # assert not (x1 == x2 and y1 == y2)134 self.x1 = x1135 self.x2 = x2136 self.y1 = y1137 self.y2 = y2138 def is_horizontal(self):139 return self.y1 == self.y2140 def is_vertical(self):141 return self.x1 == self.x2142 def __cmp__(self, other):143 if self.y1 < other.y1:144 return -1145 elif self.y1 > other.y2:146 return 1147 elif self.y2 < other.y2:148 return -1149 elif self.y2 > other.y2:150 return 1151 elif self.x1 < other.x1:152 return -1153 elif self.x1 > other.x1:154 return 1155 elif self.x2 < other.x2:156 return -1157 elif self.x2 > other.x2:158 return 1159 return 0160 def __eq__(self, other):161 return self.__cmp__(other) == 0162 def __ne__(self, other):163 return self.__cmp__(other) != 0164 def __gt__(self, other):165 return self.__cmp__(other) > 0166 def __lt__(self, other):167 return self.__cmp__(other) < 0168 def __ge__(self, other):169 return self.__cmp__(other) >= 0170 def __le__(self, other):171 return self.__cmp__(other) <= 0172 def __repr__(self):173 # h, v = self.is_horizontal(), self.is_vertical()174 # if h or v:175 # return 'Horizontal Line' if h else 'Vertical Line'176 return "[Point(%s, %s) ,Point(%s, %s)]" % (self.x1, self.y1, self.x2, self.y2)177class AVLNode():178 def __init__(self, key, value, size=1, height=0):179 self._left = self._right = None180 self._key = key181 self._value = value182 self._size = size183 self._height = height184 self._max = 0185 @property186 def max(self):187 return self._max188 @max.setter189 def max(self, max):190 self._max = max191 @property192 def height(self):193 return self._height194 @height.setter195 def height(self, height):196 self._height = height197 @property198 def left(self):199 return self._left200 @left.setter201 def left(self, node):202 assert isinstance(node, (AVLNode, type(None)))203 self._left = node204 @property205 def right(self):206 return self._right207 @right.setter208 def right(self, node):209 assert isinstance(node, (AVLNode, type(None)))210 self._right = node211 @property212 def size(self):213 return self._size214 @size.setter215 def size(self, value):216 assert isinstance(value, int) and value >= 0217 self._size = value218 @property219 def key(self):220 return self._key221 @key.setter222 def key(self, value):223 self._key = value224 @property225 def value(self):226 return self._value227 @value.setter228 def value(self, value):229 self._value = value230 def __cmp__(self, other):231 return self.key - other.key232 def __eq__(self, other):233 return self.__cmp__(other) == 0234 def __ne__(self, other):235 return self.__cmp__(other) != 0236 def __gt__(self, other):237 return self.__cmp__(other) > 0238 def __lt__(self, other):239 return self.__cmp__(other) < 0240 def __ge__(self, other):241 return self.__cmp__(other) >= 0242 def __le__(self, other):243 return self.__cmp__(other) <= 0244 def __repr__(self):245 return '(key => %s, height => %s, size => %s, max => %s)' % (self.key, self.height, self.size, self.max)246class Rect(object):247 def __init__(self, xmin, ymin, xmax, ymax) -> None:248 self._xmin = xmin249 self._ymin = ymin250 self._xmax = xmax251 self._ymax = ymax252 @property253 def xmin(self):254 return self._xmin255 @xmin.setter256 def xmin(self, xmin):257 self._xmin = xmin258 @property259 def ymin(self):260 return self._ymin261 @ymin.setter262 def ymin(self, ymin):263 self._ymin = ymin264 @property265 def xmax(self):266 return self._xmax267 @xmax.setter268 def xmax(self, xmax):269 self._xmax = xmax270 @property271 def ymax(self):272 return self._ymax273 @ymax.setter274 def ymax(self, ymax):275 self._ymax = ymax276 def intersects(self, other):277 return self.xmax >= other.xmin and self.ymax >= other.ymin and other.xmax >= self.xmin and other.ymax >= self.ymin278 def contains(self, p):279 return (p.x() >= self.xmin) and (p.x() <= self.xmax) and (p.y() >= self.ymin) and (p.y() <= self.ymax)280 def distanceTo(self, p):281 return sqrt(self.distanceSquaredTo(p))282 def distanceSquaredTo(self, p):283 dx = 0.0284 dy = 0.0285 if (p.x() < self.xmin):286 dx = p.x() - self.xmin287 elif (p.x() > self.xmax):288 dx = p.x() - self.xmax289 if (p.y() < self.ymin):290 dy = p.y() - self.ymin291 elif (p.y() > self.ymax):292 dy = p.y() - self.ymax293 return dx*dx + dy*dy294 def __cmp__(self, other):295 if (self.xmin != other.xmin):296 return 0297 if (self.ymin != other.ymin):298 return 0299 if (self.xmax != other.xmax):300 return 0301 if (self.ymax != other.ymax):302 return 0303 return 1304 def __cmp__(self, other):305 return self.key - other.key306 def __eq__(self, other):307 return self.__cmp__(other) == 0308 def __ne__(self, other):309 return self.__cmp__(other) != 0310 def __gt__(self, other):311 return self.__cmp__(other) > 0312 def __lt__(self, other):313 return self.__cmp__(other) < 0314 def __ge__(self, other):315 return self.__cmp__(other) >= 0316 def __le__(self, other):317 return self.__cmp__(other) <= 0318 def __repr__(self) -> str:319 return 'rect[{}, {}, {}, {}]'.format(self.xmin, self.ymin, self.xmax, self.ymax)320class Point2D():321 def __init__(self, x, y):322 self._x = x323 self._y = y324 def __cmp__(self, other):325 if (self.y < other.y):326 return -1327 if (self.y > other.y):328 return +1329 if (self.x < other.x):330 return -1331 if (self.x > other.x):332 return +1333 return 0334 def __eq__(self, other):335 return self.__cmp__(other) == 0336 def __ne__(self, other):337 return self.__cmp__(other) != 0338 def __gt__(self, other):339 return self.__cmp__(other) > 0340 def __lt__(self, other):341 return self.__cmp__(other) < 0342 def __ge__(self, other):343 return self.__cmp__(other) >= 0344 def __le__(self, other):345 return self.__cmp__(other) <= 0346 def __repr__(self):347 return 'Interval(%s, %s)' % (self.min, self.max)348class Event():349 """350 Represent A Line segment Event occured durinf line sweep algorithm351 """352 def __init__(self, time, segment, position):353 self.segment: SegmentHV = segment354 self.time = time355 self.position = position356 def __cmp__(self, other):357 if self.time < other.time:358 return -1359 elif self.time > other.time:360 return 1361 else:362 return 0363 def __eq__(self, other):364 return self.__cmp__(other) == 0365 def __ne__(self, other):366 return self.__cmp__(other) != 0367 def __gt__(self, other):368 return self.__cmp__(other) > 0369 def __lt__(self, other):370 return self.__cmp__(other) < 0371 def __ge__(self, other):372 return self.__cmp__(other) >= 0373 def __le__(self, other):374 return self.__cmp__(other) <= 0375def display_bst(root):376 lines, *_ = _display_aux(root)377 for line in lines:378 print(line)379def _display_aux(self):380 """Returns list of strings, width, height, and horizontal coordinate of the root."""381 # No child.382 if self.right is None and self.left is None:383 line = '%s' % self.val384 width = len(line)385 height = 1386 middle = width // 2387 return [line], width, height, middle388 # Only left child....
__init__.py
Source:__init__.py
...39 # On Python 2, __cmp__ will just work, so no need to add extra methods:40 if not _PY3:41 return klass42 def __eq__(self, other):43 c = self.__cmp__(other)44 if c is NotImplemented:45 return c46 return c == 047 def __ne__(self, other):48 c = self.__cmp__(other)49 if c is NotImplemented:50 return c51 return c != 052 def __lt__(self, other):53 c = self.__cmp__(other)54 if c is NotImplemented:55 return c56 return c < 057 def __le__(self, other):58 c = self.__cmp__(other)59 if c is NotImplemented:60 return c61 return c <= 062 def __gt__(self, other):63 c = self.__cmp__(other)64 if c is NotImplemented:65 return c66 return c > 067 def __ge__(self, other):68 c = self.__cmp__(other)69 if c is NotImplemented:70 return c71 return c >= 072 klass.__lt__ = __lt__73 klass.__gt__ = __gt__74 klass.__le__ = __le__75 klass.__ge__ = __ge__76 klass.__eq__ = __eq__77 klass.__ne__ = __ne__78 return klass79#80# Versioning81#82@_comparable83class _inf(object):84 """85 An object that is bigger than all other objects.86 """87 def __cmp__(self, other):88 """89 @param other: Another object.90 @type other: any91 @return: 0 if other is inf, 1 otherwise.92 @rtype: C{int}93 """94 if other is _inf:95 return 096 return 197_inf = _inf()98class IncomparableVersions(TypeError):99 """100 Two versions could not be compared.101 """102@_comparable103class Version(object):104 """105 An encapsulation of a version for a project, with support for outputting106 PEP-440 compatible version strings.107 This class supports the standard major.minor.micro[rcN] scheme of108 versioning.109 """110 def __init__(self, package, major, minor, micro, release_candidate=None,111 prerelease=None, dev=None):112 """113 @param package: Name of the package that this is a version of.114 @type package: C{str}115 @param major: The major version number.116 @type major: C{int} or C{str} (for the "NEXT" symbol)117 @param minor: The minor version number.118 @type minor: C{int}119 @param micro: The micro version number.120 @type micro: C{int}121 @param release_candidate: The release candidate number.122 @type release_candidate: C{int}123 @param prerelease: The prerelease number. (Deprecated)124 @type prerelease: C{int}125 @param dev: The development release number.126 @type dev: C{int}127 """128 if release_candidate and prerelease:129 raise ValueError("Please only return one of these.")130 elif prerelease and not release_candidate:131 release_candidate = prerelease132 warnings.warn(("Passing prerelease to incremental.Version was "133 "deprecated in Incremental 16.9.0. Please pass "134 "release_candidate instead."),135 DeprecationWarning, stacklevel=2)136 if major == "NEXT":137 if minor or micro or release_candidate or dev:138 raise ValueError(("When using NEXT, all other values except "139 "Package must be 0."))140 self.package = package141 self.major = major142 self.minor = minor143 self.micro = micro144 self.release_candidate = release_candidate145 self.dev = dev146 @property147 def prerelease(self):148 warnings.warn(("Accessing incremental.Version.prerelease was "149 "deprecated in Incremental 16.9.0. Use "150 "Version.release_candidate instead."),151 DeprecationWarning, stacklevel=2),152 return self.release_candidate153 def public(self):154 """155 Return a PEP440-compatible "public" representation of this L{Version}.156 Examples:157 - 14.4.0158 - 1.2.3rc1159 - 14.2.1rc1dev9160 - 16.04.0dev0161 """162 if self.major == "NEXT":163 return self.major164 if self.release_candidate is None:165 rc = ""166 else:167 rc = "rc%s" % (self.release_candidate,)168 if self.dev is None:169 dev = ""170 else:171 dev = "dev%s" % (self.dev,)172 return '%r.%d.%d%s%s' % (self.major,173 self.minor,174 self.micro,175 rc, dev)176 base = public177 short = public178 local = public179 def __repr__(self):180 if self.release_candidate is None:181 release_candidate = ""182 else:183 release_candidate = ", release_candidate=%r" % (184 self.release_candidate,)185 if self.dev is None:186 dev = ""187 else:188 dev = ", dev=%r" % (self.dev,)189 return '%s(%r, %r, %d, %d%s%s)' % (190 self.__class__.__name__,191 self.package,192 self.major,193 self.minor,194 self.micro,195 release_candidate,196 dev)197 def __str__(self):198 return '[%s, version %s]' % (199 self.package,200 self.short())201 def __cmp__(self, other):202 """203 Compare two versions, considering major versions, minor versions, micro204 versions, then release candidates. Package names are case insensitive.205 A version with a release candidate is always less than a version206 without a release candidate. If both versions have release candidates,207 they will be included in the comparison.208 @param other: Another version.209 @type other: L{Version}210 @return: NotImplemented when the other object is not a Version, or one211 of -1, 0, or 1.212 @raise IncomparableVersions: when the package names of the versions213 differ.214 """215 if not isinstance(other, self.__class__):...
timer.py
Source:timer.py
...25 def set_initial_due_time(self, when):26 self._when = when27 def update_expiration(self):28 self._when += self._interval29 def __cmp__(self, other):30 if other is None:31 return 132 self_k = (self.get_expiration(), self.ident())33 other_k = (other.get_expiration(), other.ident())34 if self_k == other_k:35 return 036 elif self_k < other_k:37 return -138 else:39 return 140 def __eq__(self, other):41 return isinstance(other, Timer) and (self.ident() == other.ident())42 def __hash__(self):43 return hash(self.ident())44 def __ne__(self, other):45 return self.__cmp__(other) != 046 def __gt__(self, other):47 return self.__cmp__(other) > 048 def __lt__(self, other):49 return self.__cmp__(other) < 050 def __ge__(self, other):51 return self.__cmp__(other) >= 052 def __le__(self, other):53 return self.__cmp__(other) <= 054 def __call__(self):55 self._callback()56 def ident(self):...
node.py
Source:node.py
...11 self.parent = parent # type: Node12 def __hash__(self):13 pass14 # Implemented methods to support compare and default comparator:15 def __cmp__(self, other):16 return self.f - other.f17 def __eq__(self, other): return self.__cmp__(other) == 018 def __lt__(self, other): return self.__cmp__(other) < 019 def __le__(self, other): return self.__cmp__(other) < 0 or self.__cmp__(other) == 020 def __gt__(self, other): return self.__cmp__(other) > 021 def __ge__(self, other): return self.__cmp__(other) > 0 or self.__cmp__(other) == 022 def create_children(self):23 pass24 def is_solution(self):25 pass # return self.h == 026 def recalculate_G_for_all_children(self, new_parent):27 self.parent = new_parent28 self.setG(new_parent.g)29 for child in self.children:30 child.recalculate_G_for_all_children(self)31 def setF(self):32 """ Total weight of this node from start to end """33 pass34 def setG(self, parent_value=None):35 """...
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!!