How to use identify_cycle method in tox

Best Python code snippet using tox_python

cycle.py

Source:cycle.py Github

copy

Full Screen

...161 @abstractmethod162 def description(cls) -> str:163 pass164 @abstractmethod165 def identify_cycle(cls, node_cycle: List[Any], edge_cycle: List[Any]) -> bool:166 pass167 @abstractmethod168 def edge_types(cls) -> List[Any]:169 pass170 class G0(CyclicalAnomalyType):171 @classmethod172 def description(cls) -> str:173 return "G0: write cycles"174 @staticmethod175 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:176 return all(e.type in DSG.CyclicalAnomaly.G0.edge_types() for e in edge_cycle)177 @classmethod178 def edge_types(cls) -> List[Any]:179 return [DSG.Edge.Type.WW]180 class G1C(CyclicalAnomalyType):181 @classmethod182 def description(cls) -> str:183 return "G1c: circular information flow"184 @staticmethod185 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:186 return all(e.type in DSG.CyclicalAnomaly.G1C.edge_types() for e in edge_cycle)187 @classmethod188 def edge_types(cls) -> List[Any]:189 return [DSG.Edge.Type.WW, DSG.Edge.Type.WR]190 class G2item(CyclicalAnomalyType):191 @classmethod192 def description(cls) -> str:193 return "G2-item: item anti dependency cycle"194 @staticmethod195 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:196 return all(e.type in DSG.CyclicalAnomaly.G2item.edge_types() for e in edge_cycle) and any(197 e.type == DSG.Edge.Type.RW for e in edge_cycle198 )199 @classmethod200 def edge_types(cls) -> List[Any]:201 return [DSG.Edge.Type.WW, DSG.Edge.Type.WR, DSG.Edge.Type.RW]202 class Gsingle(CyclicalAnomalyType):203 @classmethod204 def description(cls) -> str:205 return "G-single: single anti dependency cycle"206 @staticmethod207 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:208 return (209 all(e.type in DSG.CyclicalAnomaly.Gsingle.edge_types() for e in edge_cycle)210 and sum(211 map(212 lambda e: 1 if e.type in [DSG.Edge.Type.RW, DSG.Edge.Type.PRW] else 0,213 edge_cycle,214 )215 )216 == 1217 )218 @classmethod219 def edge_types(cls) -> List[Any]:220 return [221 DSG.Edge.Type.WW,222 DSG.Edge.Type.WR,223 DSG.Edge.Type.RW,224 DSG.Edge.Type.PRW,225 ]226 class Gsingleitem(CyclicalAnomalyType):227 @classmethod228 def description(cls) -> str:229 return "G-single-item: single item anti dependency cycle"230 @staticmethod231 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:232 return (233 all(e.type in DSG.CyclicalAnomaly.Gsingleitem.edge_types() for e in edge_cycle)234 and sum(map(lambda e: 1 if e.type == DSG.Edge.Type.RW else 0, edge_cycle)) == 1235 )236 @classmethod237 def edge_types(cls) -> List[Any]:238 return [DSG.Edge.Type.WW, DSG.Edge.Type.WR, DSG.Edge.Type.RW]239 class G2(CyclicalAnomalyType):240 @classmethod241 def description(cls) -> str:242 return "G2: anti dependency cycle"243 @staticmethod244 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:245 return all(e.type in DSG.CyclicalAnomaly.G2.edge_types() for e in edge_cycle) and any(246 e.type in [DSG.Edge.Type.RW, DSG.Edge.Type.PRW] for e in edge_cycle247 )248 @classmethod249 def edge_types(cls) -> List[Any]:250 return [251 DSG.Edge.Type.WW,252 DSG.Edge.Type.WR,253 DSG.Edge.Type.RW,254 DSG.Edge.Type.PRW,255 ]256 class Gcursor(CyclicalAnomalyType):257 @classmethod258 def description(cls) -> str:259 return "G-cursor: labeled single anti dependency cycle"260 @staticmethod261 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:262 return False # TODO: unimplemented263 @classmethod264 def edge_types(cls) -> List[Any]:265 return [] # TODO: unimplemented266 class GMSRA(CyclicalAnomalyType):267 @classmethod268 def description(cls) -> str:269 return "G-MSRa: action interference"270 @staticmethod271 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:272 return False # TODO: unimplemented273 @classmethod274 def edge_types(cls) -> List[Any]:275 return [] # TODO: unimplemented276 class GMSRB(CyclicalAnomalyType):277 @classmethod278 def description(cls) -> str:279 return "G-MSRb: action missed"280 @staticmethod281 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:282 return False # TODO: unimplemented283 @classmethod284 def edge_types(cls) -> List[Any]:285 return [] # TODO: unimplemented286 class GMSR(CyclicalAnomalyType):287 @classmethod288 def description(cls) -> str:289 return "G-MSRb: action missed"290 @staticmethod291 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:292 return DSG.CyclicalAnomaly.GMSRA.identify_cycle(293 node_cycle, edge_cycle294 ) or DSG.CyclicalAnomaly.GMSRB.identify_cycle(node_cycle, edge_cycle)295 @classmethod296 def edge_types(cls) -> List[Any]:297 return [] # TODO: unimplemented298 class Gmonotonic(CyclicalAnomalyType):299 @classmethod300 def description(cls) -> str:301 return "G-monotonic: monotonic reads"302 @staticmethod303 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:304 return False # TODO: unimplemented305 @classmethod306 def edge_types(cls) -> List[Any]:307 return [] # TODO: unimplemented308 class GSIA(CyclicalAnomalyType):309 @classmethod310 def description(cls) -> str:311 return "G-SIa: interference"312 @staticmethod313 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:314 return False # TODO: unimplemented315 @classmethod316 def edge_types(cls) -> List[Any]:317 return [] # TODO: unimplemented318 class GSIB(CyclicalAnomalyType):319 @classmethod320 def description(cls) -> str:321 return "G-SIb: missed effects"322 @staticmethod323 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:324 return False # TODO: unimplemented325 @classmethod326 def edge_types(cls) -> List[Any]:327 return [] # TODO: unimplemented328 class GSI(CyclicalAnomalyType):329 @classmethod330 def description(cls) -> str:331 return "G-SI: snapshot isolation violation"332 @staticmethod333 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:334 return DSG.CyclicalAnomaly.GSIA.identify_cycle(335 node_cycle, edge_cycle336 ) or DSG.CyclicalAnomaly.GSIB.identify_cycle(node_cycle, edge_cycle)337 @classmethod338 def edge_types(cls) -> List[Any]:339 return [] # TODO: unimplemented340 class Gupdate(CyclicalAnomalyType):341 @classmethod342 def description(cls) -> str:343 return "G-update: single anti dependency cycle with update transmission"344 @staticmethod345 def identify_cycle(node_cycle: List[Any], edge_cycle: List[Any]) -> bool:346 return False # TODO: unimplemented347 @classmethod348 def edge_types(cls) -> List[Any]:349 return [] # TODO: unimplemented350 @staticmethod351 def safe_implies(anomaly_type: Any) -> Optional[List[Any]]:352 """353 Implication between cyclical dependencies without throwing exceptions354 """355 if anomaly_type == DSG.CyclicalAnomaly.G0:356 return [DSG.CyclicalAnomaly.G1C]357 if anomaly_type == DSG.CyclicalAnomaly.G1C:358 return [DSG.CyclicalAnomaly.G1]359 if anomaly_type == DSG.CyclicalAnomaly.Gmonotonic:360 return [DSG.CyclicalAnomaly.G2item]361 if anomaly_type == DSG.CyclicalAnomaly.Gcursor:362 return [DSG.CyclicalAnomaly.G2item, DSG.CyclicalAnomaly.Gsingle]363 if anomaly_type == DSG.CyclicalAnomaly.GMSRA:364 return [DSG.CyclicalAnomaly.GMSR]365 if anomaly_type == DSG.CyclicalAnomaly.GMSRB:366 return [DSG.CyclicalAnomaly.GMSR]367 if anomaly_type == DSG.CyclicalAnomaly.GSIA:368 return [DSG.CyclicalAnomaly.GSI]369 if anomaly_type == DSG.CyclicalAnomaly.GSIB:370 return [DSG.CyclicalAnomaly.GSI]371 if anomaly_type == DSG.CyclicalAnomaly.Gupdate:372 return [DSG.CyclicalAnomaly.G2]373 if anomaly_type == DSG.CyclicalAnomaly.GMSR:374 return [DSG.CyclicalAnomaly.G2]375 if anomaly_type == DSG.CyclicalAnomaly.GSI:376 return [DSG.CyclicalAnomaly.G2]377 if anomaly_type == DSG.CyclicalAnomaly.Gsingleitem:378 return [DSG.CyclicalAnomaly.Gsingle, DSG.CyclicalAnomaly.G2item]379 if anomaly_type == DSG.CyclicalAnomaly.Gsingle:380 return [DSG.CyclicalAnomaly.G2]381 if anomaly_type == DSG.CyclicalAnomaly.G2item:382 return [DSG.CyclicalAnomaly.G2]383 if anomaly_type == DSG.CyclicalAnomaly.G2:384 return []385 return None386 @staticmethod387 def cyclical_implies(cls: Any) -> List[Any]:388 """389 Implication between cyclical dependencies390 """391 implies: List[Any] = DSG.CyclicalAnomaly.safe_implies(cls)392 if implies is None:393 raise ValueError("Unknown anomaly type: {}".format(cls))394 return implies395 @staticmethod396 def cyclical_closure(a: Any) -> List[Any]:397 """398 Compute transitive closure of a cyclical anomaly type399 """400 def aux(l: List[Any], additions: List[Any]) -> List[Any]:401 if len(additions) == 0:402 return l403 return aux(404 l + additions,405 list(406 sum(407 filter(408 lambda x: x is not None,409 map(410 lambda y: DSG.CyclicalAnomaly.safe_implies(y),411 additions,412 ),413 ),414 [],415 )416 ),417 )418 return aux(list(), [a])419 def __init__(420 self,421 dsg: Any,422 node_cycle: List[Any],423 edge_cycle: List[Any],424 final_txn: ObservedTransaction,425 ):426 if len(node_cycle) != len(edge_cycle):427 raise ValueError(428 "Node cycle and edge cycles need to have the same size: {} vs {}".format(node_cycle, edge_cycle)429 )430 elif len(node_cycle) < 2:431 raise ValueError("Need at least two nodes in the cycle: {}".format(node_cycle))432 elif edge_cycle[-1].target != node_cycle[0]:433 raise ValueError(434 "If the target of the last edge is not the first node, this isn't a cycle: {} vs {}".format(435 edge_cycle[-1].target, node_cycle[0]436 )437 )438 self._node_cycle: List[DSG.Node] = node_cycle439 self._edge_cycle: List[DSG.Edge] = edge_cycle440 self._final_txn: ObservedTransaction = final_txn441 self._dsg: DSG = dsg442 def type(self) -> CyclicalAnomalyType:443 """444 To identify the cycle, it gives it to each anomaly type445 After getting the matches, it finds the one which isn't implied by any446 This assumes that there are no cycles the implication graph of anomalies.447 Moreover, one cycle should have one (and only one) fundamental anomaly448 (ie: it shouldn't match unrelated anomalies)449 """450 possible_types: List[Any] = [451 DSG.CyclicalAnomaly.G0,452 DSG.CyclicalAnomaly.G1C,453 DSG.CyclicalAnomaly.Gmonotonic,454 DSG.CyclicalAnomaly.Gcursor,455 DSG.CyclicalAnomaly.GMSRA,456 DSG.CyclicalAnomaly.GMSRB,457 DSG.CyclicalAnomaly.GSIA,458 DSG.CyclicalAnomaly.GSIB,459 DSG.CyclicalAnomaly.Gupdate,460 DSG.CyclicalAnomaly.GMSR,461 DSG.CyclicalAnomaly.GSI,462 DSG.CyclicalAnomaly.Gsingleitem,463 DSG.CyclicalAnomaly.Gsingle,464 DSG.CyclicalAnomaly.G2item,465 DSG.CyclicalAnomaly.G2,466 ]467 matched_types: List[Any] = list(468 filter(469 lambda x: x.identify_cycle(self._node_cycle, self._edge_cycle),470 possible_types,471 )472 )473 if len(matched_types) == 0:474 raise ValueError("Unknown anomaly: {}, {}".format(self._node_cycle, self._edge_cycle))475 minimal_types: List[Any] = list()476 for idx, t in enumerate(matched_types):477 if all(478 t not in DSG.CyclicalAnomaly.cyclical_closure(s)479 for s in matched_types[:idx] + matched_types[idx + 1 :]480 ):481 minimal_types.append(t)482 if len(minimal_types) != 1:483 raise ValueError(...

Full Screen

Full Screen

graph.py

Source:graph.py Github

copy

Full Screen

...30 if not degree[to_node]: # if a node has no more incoming node it's ready to visit31 ready_to_visit.add(to_node)32 result = [n for n in topology if n in to_order] # filter out missing nodes we extended33 if len(result) < len(to_order):34 identify_cycle(graph)35 msg = "could not order tox environments and failed to detect circle" # pragma: no cover36 raise ValueError(msg) # pragma: no cover37 return result38def identify_cycle(graph):39 path = OrderedDict()40 visited = set()41 def visit(vertex):42 if vertex in visited:43 return None44 visited.add(vertex)45 path[vertex] = None46 for neighbour in graph.get(vertex, ()):47 if neighbour in path or visit(neighbour):48 return path49 del path[vertex]50 return None51 for node in graph:52 result = visit(node)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful