Best Python code snippet using autotest_python
tracer.py
Source:tracer.py
1#!/usr/bin/python2# -*- coding: UTF-8 -*-3import json4class TracerList(object):5 def __init__(self):6 self.TracerCount = 07 self.mylist = []8 def count(self):9 self.TracerCount += 110 return self.TracerCount11 def append(self, value):12 self.mylist.append(value)13 def info(self):14 #fp = open("sort.txt", "w")15 print(json.dumps(self.mylist))16 #for var in self.mylist:17 # #fp.write(str(var))18 # #print(var)19tracerlist = TracerList()20class Array2DTracer(object):21 def __init__(self, name=""):22 self.name = name23 self.id = tracerlist.count()24 self.type = "Array2DTracer"25 JSONObject = {"ID": self.id, "Type": self.type, "Event": "init", "Data": {"name": name}}26 tracerlist.append(JSONObject)27 28 def getID(self):29 return self.id30 31 def palatte(self, obj):32 JSONObject = {"ID": self.id, "Type": self.type, "Event": "palette", "Data": {"obj": obj}}33 tracerlist.append(JSONObject)34 return self35 def setData(self, D):36 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setData", "Data": D}37 tracerlist.append(JSONObject)38 return self39 def notify(self, x, y, v):40 JSONObject = {"ID": self.id, "Type": self.type, "Event": "notify", "Data": {"x": x, "y": y, "v": v}}41 tracerlist.append(JSONObject)42 return self43 def denotify(self, x, y):44 JSONObject = {"ID": self.id, "Type": self.type, "Event": "denotify", "Data": {"x": x, "y": y}}45 tracerlist.append(JSONObject)46 return self47 def select(self, sx, sy, ex, ey):48 JSONObject = {"ID": self.id, "Type": self.type, "Event": "selectRT", "Data": {"sx": sx, "sy": sy, "ex": ex, "ey": ey}}49 tracerlist.append(JSONObject)50 return self51 def deselect(self, sx, sy, ex, ey):52 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deselectRT", "Data": {"sx": sx, "sy": sy, "ex": ex, "ey": ey}}53 tracerlist.append(JSONObject)54 return self55 def select(self, x, y):56 JSONObject = {"ID": self.id, "Type": self.type, "Event": "select", "Data": {"x": x, "y": y}}57 tracerlist.append(JSONObject)58 return self59 def deselect(self, x, y):60 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deselect", "Data": {"x": x, "y": y}}61 tracerlist.append(JSONObject)62 return self63 def selectRow(self, x, sy, ey):64 JSONObject = {"ID": self.id, "Type": self.type, "Event": "selectRow", "Data": {"x": x, "sy": sy, "ey": ey}}65 tracerlist.append(JSONObject)66 return self67 def deselectRow(self, x, sy, ey):68 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deselectRow", "Data": {"x": x, "sy": sy, "ey": ey}}69 tracerlist.append(JSONObject)70 return self71 def selectCol(self, y, sx, ex):72 JSONObject = {"ID": self.id, "Type": self.type, "Event": "selectCol", "Data": {"y": y, "sx": sx, "ex": ex}}73 tracerlist.append(JSONObject)74 return self75 def deselectCol(self, y, sx, ex):76 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deselectCol", "Data": {"y": y, "sx": sx, "ex": ex}}77 tracerlist.append(JSONObject)78 return self79 def separate(self, x, y):80 JSONObject = {"ID": self.id, "Type": self.type, "Event": "separate", "Data": {"x": x, "y": y}}81 tracerlist.append(JSONObject)82 return self83 def separateRow(self, x):84 JSONObject = {"ID": self.id, "Type": self.type, "Event": "separateRow", "Data": {"x": x}}85 tracerlist.append(JSONObject)86 return self87 def separateCol(self, y):88 JSONObject = {"ID": self.id, "Type": self.type, "Event": "separateCol", "Data": {"y": y}}89 tracerlist.append(JSONObject)90 return self91 def deseparate(self, x, y):92 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deseparate", "Data": {"x": x, "y": y}}93 tracerlist.append(JSONObject)94 return self95 def deseparateRow(self, x):96 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deseparateRow", "Data": {"x": x}}97 tracerlist.append(JSONObject)98 return self99 def deseparateCol(self, y):100 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deseparateCol", "Data": {"y": y}}101 tracerlist.append(JSONObject)102 return self103 def wait(self, line):104 JSONObject = {"ID": self.id, "Type": self.type, "Event": "wait", "Data": {"line": line}}105 tracerlist.append(JSONObject)106 return self107 def clear(self):108 JSONObject = {"ID": self.id, "Type": self.type, "Event": "clear", "Data": {}}109 tracerlist.append(JSONObject)110 return self111 def attach(self, id):112 JSONObject = {"ID": self.id, "Type": self.type, "Event": "attach", "Data": {"id": id}}113 tracerlist.append(JSONObject)114 return self115class Array1DTracer(object):116 def __init__(self, name=""):117 self.name = name118 self.id = tracerlist.count()119 self.type = "Array1DTracer"120 JSONObject = {"ID": self.id, "Type": self.type, "Event": "init", "Data": {"name": name}}121 tracerlist.append(JSONObject)122 def getID(self):123 return self.id124 125 def palatte(self, obj):126 JSONObject = {"ID": self.id, "Type": self.type, "Event": "palette", "Data": {"obj": obj}}127 tracerlist.append(JSONObject)128 return self129 def setData(self, D):130 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setData", "Data": D}131 tracerlist.append(JSONObject)132 return self133 def notify(self, x, v):134 JSONObject = {"ID": self.id, "Type": self.type, "Event": "notify", "Data": {"x": x, "v": v}}135 tracerlist.append(JSONObject)136 return self137 def denotify(self, x):138 JSONObject = {"ID": self.id, "Type": self.type, "Event": "denotify", "Data": {"x": x}}139 tracerlist.append(JSONObject)140 return self141 def select(self, s, e):142 JSONObject = {"ID": self.id, "Type": self.type, "Event": "selectR", "Data": {"s": s, "e": e}}143 tracerlist.append(JSONObject)144 return self145 def deselect(self, s, e):146 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deselectR", "Data": {"s": s, "e": e}}147 tracerlist.append(JSONObject)148 return self149 def select(self, x):150 JSONObject = {"ID": self.id, "Type": self.type, "Event": "select", "Data": {"x": x}}151 tracerlist.append(JSONObject)152 return self153 def deselect(self, x):154 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deselect", "Data": {"x": x}}155 tracerlist.append(JSONObject)156 return self157 def separate(self, x):158 JSONObject = {"ID": self.id, "Type": self.type, "Event": "separate", "Data": {"x": x}}159 tracerlist.append(JSONObject)160 return self161 def deseparate(self, x):162 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deseparate", "Data": {"x": x}}163 tracerlist.append(JSONObject)164 return self165 def wait(self, line):166 JSONObject = {"ID": self.id, "Type": self.type, "Event": "wait", "Data": {"line": line}}167 tracerlist.append(JSONObject)168 return self169 def clear(self):170 JSONObject = {"ID": self.id, "Type": self.type, "Event": "clear", "Data": {}}171 tracerlist.append(JSONObject)172 return self173 def attach(self, id):174 JSONObject = {"ID": self.id, "Type": self.type, "Event": "attach", "Data": {"id": id}}175 tracerlist.append(JSONObject)176 return self177class LogTracer(object):178 def __init__(self, name=""):179 self.name = name180 self.id = tracerlist.count()181 self.type = "LogTracer"182 JSONObject = {"ID": self.id, "Type": self.type, "Event": "init", "Data": {"name": name}}183 tracerlist.append(JSONObject)184 185 def getID(self):186 return self.id187 188 def Print(self, info):189 JSONObject = {"ID": self.id, "Type": self.type, "Event": "print", "Data": {"info": info}}190 tracerlist.append(JSONObject)191 return self192 def wait(self, line):193 JSONObject = {"ID": self.id, "Type": self.type, "Event": "wait", "Data": {"line": line}}194 tracerlist.append(JSONObject)195 return self196 def clear(self):197 JSONObject = {"ID": self.id, "Type": self.type, "Event": "clear", "Data": {}}198 tracerlist.append(JSONObject)199 return self200class ChartTracer(object):201 def __init__(self, name=""):202 self.name = name203 self.id = tracerlist.count()204 self.type = "ChartTracer"205 JSONObject = {"ID": self.id, "Type": self.type, "Event": "init", "Data": {"name": name}}206 tracerlist.append(JSONObject)207 208 def getID(self):209 return self.id210 211 def palatte(self, obj):212 JSONObject = {"ID": self.id, "Type": self.type, "Event": "palette", "Data": {"obj": obj}}213 tracerlist.append(JSONObject)214 return self215 def setData(self, D):216 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setData", "Data": D}217 tracerlist.append(JSONObject)218 return self219 def notify(self, x, v):220 JSONObject = {"ID": self.id, "Type": self.type, "Event": "notify", "Data": {"x": x, "v": v}}221 tracerlist.append(JSONObject)222 return self223 def denotify(self, x):224 JSONObject = {"ID": self.id, "Type": self.type, "Event": "denotify", "Data": {"x": x}}225 tracerlist.append(JSONObject)226 return self227 def select(self, s, e):228 JSONObject = {"ID": self.id, "Type": self.type, "Event": "selectR", "Data": {"s": s, "e": e}}229 tracerlist.append(JSONObject)230 return self231 def deselect(self, s, e):232 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deselectR", "Data": {"s": s, "e": e}}233 tracerlist.append(JSONObject)234 return self235 def select(self, x):236 JSONObject = {"ID": self.id, "Type": self.type, "Event": "select", "Data": {"x": x}}237 tracerlist.append(JSONObject)238 return self239 def deselect(self, x):240 JSONObject = {"ID": self.id, "Type": self.type, "Event": "deselect", "Data": {"x": x}}241 tracerlist.append(JSONObject)242 return self243 def wait(self, line):244 JSONObject = {"ID": self.id, "Type": self.type, "Event": "wait", "Data": {"line": line}}245 tracerlist.append(JSONObject)246 return self247 def clear(self):248 JSONObject = {"ID": self.id, "Type": self.type, "Event": "clear", "Data": {}}249 tracerlist.append(JSONObject)250 return self251class DirectedGraghTracer(object):252 def __init__(self, name=""):253 self.name = name254 self.id = tracerlist.count()255 self.type = "DirectedGraphTracer"256 JSONObject = {"ID": self.id, "Type": self.type, "Event": "init", "Data": {"name": name}}257 tracerlist.append(JSONObject)258 259 def getID(self):260 return self.id261 262 def palatte(self, obj):263 JSONObject = {"ID": self.id, "Type": self.type, "Event": "palette", "Data": {"obj": obj}}264 tracerlist.append(JSONObject)265 return self266 def setTreeData(self, D):267 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setTreeData", "Data": D}268 tracerlist.append(JSONObject)269 return self270 def setData(self, D):271 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setData", "Data": D}272 tracerlist.append(JSONObject)273 return self274 def visit(self, t, s):275 JSONObject = {"ID": self.id, "Type": self.type, "Event": "visit", "Data": {"t": t, "s": s}}276 tracerlist.append(JSONObject)277 return self278 279 def visit(self, t):280 JSONObject = {"ID": self.id, "Type": self.type, "Event": "visit", "Data": {"t": t}}281 tracerlist.append(JSONObject)282 return self283 def leave(self, t, s):284 JSONObject = {"ID": self.id, "Type": self.type, "Event": "leave", "Data": {"t": t, "s": s}}285 tracerlist.append(JSONObject)286 return self287 288 def leave(self, t):289 JSONObject = {"ID": self.id, "Type": self.type, "Event": "leave", "Data": {"t": t}}290 tracerlist.append(JSONObject)291 return self292 def wait(self, line):293 JSONObject = {"ID": self.id, "Type": self.type, "Event": "wait", "Data": {"line": line}}294 tracerlist.append(JSONObject)295 return self296 def clear(self):297 JSONObject = {"ID": self.id, "Type": self.type, "Event": "clear", "Data": {}}298 tracerlist.append(JSONObject)299 return self300 def attach(self, id):301 JSONObject = {"ID": self.id, "Type": self.type, "Event": "attach", "Data": {"id": id}}302 tracerlist.append(JSONObject)303 return self304class UnDirectedGraghTracer(object):305 def __init__(self, name=""):306 self.name = name307 self.id = tracerlist.count()308 self.type = "UnDirectedGraphTracer"309 JSONObject = {"ID": self.id, "Type": self.type, "Event": "init", "Data": {"name": name}}310 tracerlist.append(JSONObject)311 def getID(self):312 return self.id313 314 def palatte(self, obj):315 JSONObject = {"ID": self.id, "Type": self.type, "Event": "palette", "Data": {"obj": obj}}316 tracerlist.append(JSONObject)317 return self318 def setTreeData(self, D):319 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setTreeData", "Data": D}320 tracerlist.append(JSONObject)321 return self322 def setData(self, D):323 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setData", "Data": D}324 tracerlist.append(JSONObject)325 return self326 def visit(self, t, s):327 JSONObject = {"ID": self.id, "Type": self.type, "Event": "visit", "Data": {"t": t, "s": s}}328 tracerlist.append(JSONObject)329 return self330 def leave(self, t, s):331 JSONObject = {"ID": self.id, "Type": self.type, "Event": "leave", "Data": {"t": t, "s": s}}332 tracerlist.append(JSONObject)333 return self334 335 def visit(self, t):336 JSONObject = {"ID": self.id, "Type": self.type, "Event": "visit", "Data": {"t": t}}337 tracerlist.append(JSONObject)338 return self339 def leave(self, t):340 JSONObject = {"ID": self.id, "Type": self.type, "Event": "leave", "Data": {"t": t}}341 tracerlist.append(JSONObject)342 return self343 def wait(self, line):344 JSONObject = {"ID": self.id, "Type": self.type, "Event": "wait", "Data": {"line": line}}345 tracerlist.append(JSONObject)346 return self347 def clear(self):348 JSONObject = {"ID": self.id, "Type": self.type, "Event": "clear", "Data": {}}349 tracerlist.append(JSONObject)350 return self351 def attach(self, id):352 JSONObject = {"ID": self.id, "Type": self.type, "Event": "attach", "Data": {"id": id}}353 tracerlist.append(JSONObject)354 return self355class WeightedDirectedGraghTracer(object):356 def __init__(self, name=""):357 self.name = name358 self.id = tracerlist.count()359 self.type = "WeightedDirectedGraphTracer"360 JSONObject = {"ID": self.id, "Type": self.type, "Event": "init", "Data": {"name": name}}361 tracerlist.append(JSONObject)362 363 def getID(self):364 return self.id365 366 def palatte(self, obj):367 JSONObject = {"ID": self.id, "Type": self.type, "Event": "palette", "Data": {"obj": obj}}368 tracerlist.append(JSONObject)369 return self370 def setTreeData(self, D, root):371 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setTreeData", "Data": {"D": D, "root": root}}372 tracerlist.append(JSONObject)373 return self374 def setData(self, D):375 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setData", "Data": D}376 tracerlist.append(JSONObject)377 return self378 def weight(self, t, w):379 JSONObject = {"ID": self.id, "Type": self.type, "Event": "weight", "Data": {"t": t, "w": w}}380 tracerlist.append(JSONObject)381 return self382 def visit(self, t, s, w):383 JSONObject = {"ID": self.id, "Type": self.type, "Event": "visit", "Data": {"t": t, "s": s, "w": w}}384 tracerlist.append(JSONObject)385 return self386 def leave(self, t, s, w):387 JSONObject = {"ID": self.id, "Type": self.type, "Event": "leave", "Data": {"t": t, "s": s, "w": w}}388 tracerlist.append(JSONObject)389 return self390 391 def visit(self, t):392 JSONObject = {"ID": self.id, "Type": self.type, "Event": "visit", "Data": {"t": t}}393 tracerlist.append(JSONObject)394 return self395 def leave(self, t):396 JSONObject = {"ID": self.id, "Type": self.type, "Event": "leave", "Data": {"t": t}}397 tracerlist.append(JSONObject)398 return self399 def wait(self, line):400 JSONObject = {"ID": self.id, "Type": self.type, "Event": "wait", "Data": {"line": line}}401 tracerlist.append(JSONObject)402 return self403 def clear(self):404 JSONObject = {"ID": self.id, "Type": self.type, "Event": "clear", "Data": {}}405 tracerlist.append(JSONObject)406 return self407 def attach(self, id):408 JSONObject = {"ID": self.id, "Type": self.type, "Event": "attach", "Data": {"id": id}}409 tracerlist.append(JSONObject)410 return self411class WeightedUnDirectedGraghTracer(object):412 def __init__(self, name=""):413 self.name = name414 self.id = tracerlist.count()415 self.type = "WeightedUnDirectedGraphTracer"416 JSONObject = {"ID": self.id, "Type": self.type, "Event": "init", "Data": {"name": name}}417 tracerlist.append(JSONObject)418 419 def getID(self):420 return self.id421 422 def palatte(self, obj):423 JSONObject = {"ID": self.id, "Type": self.type, "Event": "palette", "Data": {"obj": obj}}424 tracerlist.append(JSONObject)425 return self426 def setTreeData(self, D, root):427 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setTreeData", "Data": {"D": D, "root": root}}428 tracerlist.append(JSONObject)429 return self430 def setData(self, D):431 JSONObject = {"ID": self.id, "Type": self.type, "Event": "setData", "Data": D}432 tracerlist.append(JSONObject)433 return self434 def weight(self, t, w):435 JSONObject = {"ID": self.id, "Type": self.type, "Event": "weight", "Data": {"t": t, "w": w}}436 tracerlist.append(JSONObject)437 return self438 def visit(self, t, s, w):439 JSONObject = {"ID": self.id, "Type": self.type, "Event": "visit", "Data": {"t": t, "s": s, "w": w}}440 tracerlist.append(JSONObject)441 return self442 def leave(self, t, s, w):443 JSONObject = {"ID": self.id, "Type": self.type, "Event": "leave", "Data": {"t": t, "s": s, "w": w}}444 tracerlist.append(JSONObject)445 return self446 447 def visit(self, t):448 JSONObject = {"ID": self.id, "Type": self.type, "Event": "visit", "Data": {"t": t}}449 tracerlist.append(JSONObject)450 return self451 def leave(self, t):452 JSONObject = {"ID": self.id, "Type": self.type, "Event": "leave", "Data": {"t": t}}453 tracerlist.append(JSONObject)454 return self455 456 def wait(self, line):457 JSONObject = {"ID": self.id, "Type": self.type, "Event": "wait", "Data": {"line": line}}458 tracerlist.append(JSONObject)459 return self460 def clear(self):461 JSONObject = {"ID": self.id, "Type": self.type, "Event": "clear", "Data": {}}462 tracerlist.append(JSONObject)463 return self464 def attach(self, id):465 JSONObject = {"ID": self.id, "Type": self.type, "Event": "attach", "Data": {"id": id}}466 tracerlist.append(JSONObject)467 return self468import random469if __name__ == '__main__':470 A = []471 for i in range(10):472 A.append(random.randint(1, 100))473 tracer = Array1DTracer("A1D").setData(A)474 logger = LogTracer("Lt")475 A[0] = 100476 tracer.notify(0, A[0]).wait(1)477 tracer.denotify(0)478 A[1] = 1479 tracer.notify(1, A[1]).wait(1)480 for i in range(9):481 for j in range(9 - i):482 tracer.select(j)483 tracer.select(j + 1).wait(1)484 if A[j] > A[j + 1]:485 tmp = A[j + 1]486 A[j + 1] = A[j]487 A[j] = tmp488 tracer.notify(j, A[j])489 tracer.notify(j + 1, A[j + 1]).wait(1)490 #for i in range(10):491 #print(A[i])...
objects.py
Source:objects.py
...4from .schemas import (5 ADDRESS_SCHEMA, AGENTS_SCHEMA, CUSTOMS_DECLARATION_SCHEMA, EXTRAS_SCHEMA,6 LOCATION_SCHEMA, LOCATIONS_SCHEMA, PARCELS_SCHEMA, PARTNER_SCHEMA,7 PDF_CONFIG_SCHEMA, SERVICE_SCHEMA)8class JSONObject(object):9 schema = {} # Defined in subclass10 def __init__(self, data=None):11 self._data = data12 if data:13 self.validate()14 def __setitem__(self, key, value):15 self._data[key] = value16 self.validate()17 def __getitem__(self, item):18 return self._data[item]19 def validate(self):20 validate(self._data, self.schema)21 @classmethod22 def from_shipment(cls, shipment):...
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!!