def test_description_deletion(self): ht = HistoryTracker(gen_proj(), History()) ht.stage(POp_DelDesc, 0) p2 = gen_proj() self.assertTrue(same(ht.ctx, p2)) ht.commit() ht.undo() self.assertTrue(same(ht.ctx, p2))
def __same__(self, o): if type(self) is not type(o): return False if not same(self.prop_type, o.prop_type): return False if not same(self.prop_name, o.prop_name): return False s_val, o_val = self.prop_val, o.prop_val if isinstance(self.prop_type, QOMPropertyTypeLink): s_val, o_val = idon(s_val), idon(o_val) if same(s_val, o_val): return True return False
def __same__(self, o): if not Node.__same__(self, o): return False # Neither source nor destination device can be None. if not same(self.src_dev.id, o.src_dev.id): return False if not same(self.dst_dev.id, o.dst_dev.id): return False for a in ("src_irq_idx", "src_irq_name", "dst_irq_idx", "dst_irq_name"): if not same(getattr(self, a), getattr(o, a)): return False return True
def __same__(self, o): if not Node.__same__(self, o): return False if not same(idon(self.parent_device), idon(o.parent_device)): return False for a in ("c_type", "cast", "child_name", "force_index"): if not same(getattr(self, a), getattr(o, a)): return False # device order is not significant if same_sets((d.id for d in self.devices), (d.id for d in o.devices)): return True return False
def find_trinities_from_points(points, opposite_points, radius): pairs = dict() triangle_distance = radius * sqrt(3) for i in range(len(points)): pairs[i] = set() for i in range(len(points)): for j in range(i + 1, len(points)): if opposite_points[j] not in pairs[opposite_points[i]] and opposite_points[i] not in pairs[opposite_points[j]]: d = distance(points[i], points[j]) if common.same(d, triangle_distance): pairs[i].add(j) opp = [opposite_points[i], opposite_points[j]] opp.sort() pairs[opp[0]].add(opp[1]) for i in range(len(points)): if not pairs[i]: pairs.pop(i) trinities = set() for i in pairs: candidates = list(pairs[i]) candidates.sort() for j in range(len(candidates)): for k in range(j + 1, len(candidates)): if candidates[j] in pairs and candidates[k] in pairs[candidates[j]]: trinities.add((i, candidates[j], candidates[k])) opp = [opposite_points[i], opposite_points[candidates[j]], opposite_points[candidates[k]]] opp.sort() trinities.add(tuple(opp)) return trinities
def test(self): self._generator = gen = PyGenVisitor(self._original).visit().gen buf = gen.w code = buf.getvalue() res = {} try: exec(code, self._namespace, res) except: print("\nError in generated code:\n" + format_exc()) eq = False else: try: loaded = res[self._generator.nameof(self._original)] eq = same(loaded, self._original) except: print("\nLoaded object is bad:\n" + format_exc()) eq = False if PYGEN_VERBOSE or not eq: code_file = join(verbose_dir, type(self).__name__ + ".py") # save serialized code to the file for developer with open(code_file, "w") as f: f.write(code) self.assertTrue(eq, "Loaded object differs.")
def __same__(self, o): if not DeviceNode.__same__(self, o): return False for a in ("slot", "function", "multifunction"): if not same(getattr(self, a), getattr(o, a)): return False return True
def __same__(self, o): if not Node.__same__(self, o): return False for a in ("name", "size", "offset", "may_overlap", "priority", "alias_offset"): if not same(getattr(self, a), getattr(o, a)): return False if not same(idon(self.parent), idon(o.parent)): return False if not same(idon(self.alias_to), idon(o.alias_to)): return False # children order is not significant if same_sets((c.id for c in self.children), (c.id for c in o.children)): return True return False
def find_great_triangles(all_points, radius, edges, circles_to_points): trinities = set() triangle_distance = radius * sqrt(3) for e in range(len(edges)): circle = circles_to_points[e] for i in range(len(circle)): for j in range(i + 1, len(circle)): d1 = distance(all_points[circle[i]], all_points[circle[j]]) if triangle_distance > 0 and not common.same(d1, triangle_distance): continue for k in range(j + 1, len(circle)): d2 = distance(all_points[circle[i]], all_points[circle[k]]) d3 = distance(all_points[circle[j]], all_points[circle[k]]) if common.same(d1, d2) and common.same(d1, d3) and common.same(d2, d3): numbers = [circle[i], circle[j], circle[k]] numbers.sort() trinities.add(tuple(numbers)) break return trinities
def plus_minus(points): new_points = [] for p in points: mults = [] for i in range(len(p)): if common.same(p[i], 0): mults.append([1]) else: mults.append([1, -1]) for i in mults[0]: for j in mults[1]: for k in mults[2]: new_points.append([p[0] * i, p[1] * j, p[2] * k]) return new_points
def _check(self, diff): intrvls = git_diff2delta_intervals(diff) lines_map = {} for line in self._lines_map: if intrvls[line] is not None: lines_map[line] = line + intrvls[line] else: lines_map[line] = None try: eq = same(lines_map, self._lines_map) except: print("\nIntervals are different") eq = False self.assertTrue(eq, "Intervals differ.")
def __same__(self, o): if not Node.__same__(self, o): return False if not same(idon(self.parent_bus), idon(o.parent_bus)): return False if not same_attrs(self, o, "qom_type", "properties"): return False # order of buses is significant if not same_vectors((b.id for b in self.buses), (b.id for b in o.buses)): return False # order of IRQs is not significant if same_sets((i.id for i in self.irqs), (i.id for i in o.irqs)): return True return False
def compare(self, test, sender, dump, cmp_sender, cmp_dump): if dump["lineno"] != cmp_dump["lineno"]: msg = MSG_FORMAT.format(msg="branch instruction error, test: %s" % test) elif ("vars" in dump and "vars" in cmp_dump and not same(dump["vars"], cmp_dump["vars"])): msg = MSG_FORMAT.format(msg="binary instruction error, test: %s" % test) else: return dump4report = OrderedDict( sorted({ sender: dump, cmp_sender: cmp_dump }.items(), key=lambda x: x)) self._print_report(msg, dump4report) raise RuntimeError
def _is_same(self, loaded): return same(loaded, self._original)
def __same__(self, o): return same(self.target, o.target)
def test_equality(self): self.assertTrue(same(gen_proj(), gen_proj()))