def check(self, testfile): doc = etree.parse(testfile).getroot() self.reports[testfile] = doc for e in doc.findall(".//*[@class='expected']"): testcase = e.attrib[FONTTEST_ID] ok, observed = self.render(e) if ok: expected_svg = e.find('svg') self.normalize_svg(expected_svg) ok = svgutil.is_similar(expected_svg, observed, maxDelta=1.0) self.add_prefix_to_svg_ids(observed, 'OBSERVED') self.observed[testcase] = observed self.conformance[testcase] = ok print('%s %s' % ('PASS' if ok else 'FAIL', testcase)) for e in doc.findall(".//*[@class='expected-no-crash']"): testcase = e.attrib[FONTTEST_ID] ok, observed = self.render(e) self.add_prefix_to_svg_ids(observed, 'OBSERVED') self.observed[testcase] = observed self.conformance[testcase] = ok print('%s %s' % ('PASS' if ok else 'FAIL', testcase)) for testcase, ok in list(self.conformance.items()): groups = testcase.split('/') for i in range(len(groups)): group = '/'.join(groups[:i]) self.conformance[group] = (ok and self.conformance.get( group, True))
def check(self, testfile): all_ok = True doc = etree.parse(testfile).getroot() self.reports[testfile] = doc for e in doc.findall(".//*[@class='expected']"): testcase = e.attrib[FONTTEST_ID] font = os.path.join('fonts', e.attrib[FONTTEST_FONT]) render = e.attrib.get(FONTTEST_RENDER) variation = e.attrib.get(FONTTEST_VARIATION) expected_svg = e.find('svg') self.normalize_svg(expected_svg) command = ['build/out/Default/fonttest', '--font=' + font, '--testcase=' + testcase, '--engine=' + self.engine] if render: command.append('--render=' + render) if variation: command.append('--variation=' + variation) try: observed = subprocess.check_output(command) except subprocess.CalledProcessError: observed = '<error/>' observed = re.sub(r'>\s+<', '><', observed) observed = observed.replace( 'xmlns="http://www.w3.org/2000/svg"', '') observed_svg = etree.fromstring(observed) self.normalize_svg(observed_svg) self.observed[testcase] = observed_svg ok = svgutil.is_similar(expected_svg, observed_svg, maxDelta=1.0) all_ok = all_ok and ok self.conformance[testcase] = ok groups = testcase.split('/') for i in range(len(groups)): group = '/'.join(groups[:i]) self.conformance[group] = (ok and self.conformance.get(group, True)) print "%s %s" % ("PASS" if all_ok else "FAIL", testfile)
def test_is_similar(self): self.assertTrue(svgutil.is_similar(SVG_A, SVG_A, maxDelta=0.0)) self.assertFalse(svgutil.is_similar(SVG_A, SVG_B, maxDelta=1.0)) self.assertTrue(svgutil.is_similar(SVG_A, SVG_B, maxDelta=5.0)) self.assertFalse(svgutil.is_similar(SVG_A, SVG_C, maxDelta=1.0)) self.assertTrue(svgutil.is_similar(SVG_A, SVG_C, maxDelta=5.0)) self.assertTrue(svgutil.is_similar(SVG_A, SVG_D, maxDelta=0.0)) self.assertTrue(svgutil.is_similar(SVG_D, SVG_A, maxDelta=0.0))
def check(self, testfile): doc = etree.parse(testfile).getroot() self.reports[testfile] = doc all_ok = True for e in doc.findall(".//*[@class='expected']"): testcase = e.attrib[FONTTEST_ID] expected_svg = e.find('svg') self.normalize_svg(expected_svg) command = self.make_command(e) status, observed, _stderr = run_command(command, timeout_sec=3) if status == 0: observed = re.sub(r'>\s+<', '><', observed) observed = observed.replace( 'xmlns="http://www.w3.org/2000/svg"', '') observed_svg = etree.fromstring(observed) self.normalize_svg(observed_svg) ok = svgutil.is_similar(expected_svg, observed_svg, maxDelta=1.0) self.add_prefix_to_svg_ids(observed_svg, 'OBSERVED') self.observed[testcase] = observed_svg else: self.observed[testcase] = etree.fromstring( '<div>⁓</div>') ok = False self.conformance[testcase] = ok if not ok: all_ok = False print('%s %s' % ('PASS' if ok else 'FAIL', testcase)) for e in doc.findall(".//*[@class='should-not-crash']"): testcase = e.attrib[FONTTEST_ID] command = self.make_command(e) status, _observed, _stderr = run_command(command, timeout_sec=3) ok = self.conformance[testcase] = (status == 0) if not ok: all_ok = False print('%s %s' % ('PASS' if ok else 'FAIL', testcase)) for testcase, ok in list(self.conformance.items()): groups = testcase.split('/') for i in range(len(groups)): group = '/'.join(groups[:i]) self.conformance[group] = (ok and self.conformance.get( group, True))