def test_output(self): """Test that empty or intentionally unchanged glyphs are unchanged, and everything else is changed. """ glyph_sets = self.getGlyphSets( self.instance_glyph_sets, self.instance_weights_to_test) standard = glyph_sets[0] pen = GlyphAreaPen(standard) areas = {} for name in self.instance_glyphs_to_test: standard[name].draw(pen) areas[name] = pen.pop() errors = [] for other in glyph_sets[1:]: other_pen = GlyphAreaPen(other) for name, area in areas.iteritems(): if name in self.whitelist: continue other[name].draw(other_pen) other_area = other_pen.pop() if name in self.unchanged or not area: if area != other_area: errors.append( "%s has changed, but should not have: %s vs. %s." % (name, area, other_area)) else: if area == other_area: errors.append( "%s has not changed, but should have: %s vs. %s." % (name, area, other_area)) self.assertFalse(errors, '\n'.join([''] + errors))
def find_shape_diffs(self): """Report differences in glyph shapes, using BooleanOperations.""" self.build_names() area_pen = GlyphAreaPen(None) pen = PointToSegmentPen(area_pen) mismatched = {} for name in self.names: glyph_a = Glyph() glyph_b = Glyph() self.glyph_set_a[name].draw(Qu2CuPen(glyph_a.getPen(), self.glyph_set_a)) self.glyph_set_b[name].draw(Qu2CuPen(glyph_b.getPen(), self.glyph_set_b)) booleanOperations.xor(list(glyph_a), list(glyph_b), pen) area = abs(area_pen.pop()) if area: mismatched[name] = area stats = self.stats["compared"] for name, area in mismatched.items(): stats.append((area, name, self.basepath))
def setUp(self): """Determine which glyphs are intentionally unchanged.""" self.unchanged = set() master_a, master_b = self.getGlyphSets( self.master_glyph_sets, self.master_weights_to_test) pen_a = GlyphAreaPen(master_a) pen_b = GlyphAreaPen(master_b) for name in self.master_glyphs_to_test: if name in self.whitelist: continue master_a[name].draw(pen_a) area_a = pen_a.pop() master_b[name].draw(pen_b) area_b = pen_b.pop() if area_a == area_b: if area_a: self.unchanged.add(name) else: assert area_a and area_b
def find_area_diffs(self): """Report differences in glyph areas.""" self.build_names() pen_a = GlyphAreaPen(self.glyph_set_a) pen_b = GlyphAreaPen(self.glyph_set_b) mismatched = {} for name in self.names: self.glyph_set_a[name].draw(pen_a) area_a = pen_a.pop() self.glyph_set_b[name].draw(pen_b) area_b = pen_b.pop() if area_a != area_b: mismatched[name] = (area_a, area_b) stats = self.stats['compared'] calc = self._calc_ratio if self.ratio_diffs else self._calc_diff for name, areas in mismatched.items(): stats.append((calc(areas), name, self.basepath, areas[0], areas[1]))
def test_output(self): """Test that empty or intentionally unchanged glyphs are unchanged, and everything else is changed. """ glyph_sets = self.getGlyphSets(self.instance_glyph_sets, self.instance_weights_to_test) standard = glyph_sets[0] pen = GlyphAreaPen(standard) areas = {} for name in self.instance_glyphs_to_test: standard[name].draw(pen) areas[name] = pen.pop() errors = [] for other in glyph_sets[1:]: other_pen = GlyphAreaPen(other) for name, area in areas.items(): if name in self.whitelist: continue other[name].draw(other_pen) other_area = other_pen.pop() if name in self.unchanged or not area: if area != other_area: errors.append( "%s has changed, but should not have: %s vs. %s." % (name, area, other_area)) else: if area == other_area: errors.append( "%s has not changed, but should have: %s vs. %s." % (name, area, other_area)) self.assertFalse(errors, '\n'.join([''] + errors))
def test_output(self): """Test that empty or intentionally unchanged glyphs are unchanged, and everything else is changed. """ glyph_sets = self.getGlyphSets( self.instance_glyph_sets, self.instance_weights_to_test) standard = glyph_sets[0] pen = GlyphAreaPen(standard) areas = {} for name in self.instance_glyphs_to_test: standard[name].draw(pen) areas[name] = pen.pop() for other in glyph_sets[1:]: other_pen = GlyphAreaPen(other) for name, area in areas.iteritems(): if name in self.whitelist: continue other[name].draw(other_pen) other_area = other_pen.pop() if name in self.unchanged or not area: self.assertEqual( area, other_area, name + " has changed, but should not have: %s vs. %s." % (area, other_area)) else: self.assertNotEqual( area, other_area, name + " has not changed, but should have: %s vs. %s." % (area, other_area))
def find_shape_diffs(self): """Report differences in glyph shapes, using BooleanOperations.""" self.build_names() area_pen = GlyphAreaPen(None) pen = PointToSegmentPen(area_pen) mismatched = {} for name in self.names: glyph_a = Glyph() glyph_b = Glyph() self.glyph_set_a[name].draw( Qu2CuPen(glyph_a.getPen(), self.glyph_set_a)) self.glyph_set_b[name].draw( Qu2CuPen(glyph_b.getPen(), self.glyph_set_b)) booleanOperations.xor(list(glyph_a), list(glyph_b), pen) area = abs(area_pen.pop()) if area: mismatched[name] = (area) stats = self.stats['compared'] for name, area in mismatched.items(): stats.append((area, name, self.basepath))
def find_area_diffs(self): """Report differences in glyph areas.""" self.build_names() pen_a = GlyphAreaPen(self.glyph_set_a) pen_b = GlyphAreaPen(self.glyph_set_b) mismatched = {} for name in self.names: self.glyph_set_a[name].draw(pen_a) area_a = pen_a.pop() self.glyph_set_b[name].draw(pen_b) area_b = pen_b.pop() if area_a != area_b: mismatched[name] = (area_a, area_b) stats = self.stats["compared"] calc = self._calc_ratio if self.ratio_diffs else self._calc_diff for name, areas in mismatched.items(): stats.append((calc(areas), name, self.basepath, areas[0], areas[1]))
def setUp(self): """Determine which glyphs are intentionally unchanged.""" self.unchanged = set() master_a, master_b = self.getGlyphSets(self.master_glyph_sets, self.master_weights_to_test) pen_a = GlyphAreaPen(master_a) pen_b = GlyphAreaPen(master_b) for name in self.master_glyphs_to_test: if name in self.whitelist: continue master_a[name].draw(pen_a) area_a = pen_a.pop() master_b[name].draw(pen_b) area_b = pen_b.pop() if area_a == area_b: if area_a: self.unchanged.add(name) else: assert area_a and area_b