def generate_and_test(input_filename, source_dir, working_dir, fixup_path, pdfium_test_path, image_differ, drmem_wrapper): input_root, _ = os.path.splitext(input_filename) input_path = os.path.join(source_dir, input_root + '.in') pdf_path = os.path.join(working_dir, input_root + '.pdf') # Remove any existing generated images from previous runs. actual_images = image_differ.GetActualFiles(input_filename, source_dir, working_dir) for image in actual_images: if os.path.exists(image): os.remove(image) try: sys.stdout.flush() subprocess.check_call([ sys.executable, fixup_path, '--output-dir=' + working_dir, input_path ]) # add Dr. Memory wrapper if exist cmd_to_run = common.DrMemoryWrapper(drmem_wrapper, input_root) cmd_to_run.extend([pdfium_test_path, '--png', pdf_path]) # run test subprocess.check_call(cmd_to_run) except subprocess.CalledProcessError as e: print "FAILURE: " + input_filename + "; " + str(e) return False if image_differ.HasDifferences(input_filename, source_dir, working_dir): print "FAILURE: " + input_filename return False return True
def TestPixel(self, input_root, pdf_path): cmd_to_run = common.DrMemoryWrapper(self.drmem_wrapper, input_root) cmd_to_run.extend([self.pdfium_test_path, '--send-events', '--png']) if self.gold_results: cmd_to_run.append('--md5') cmd_to_run.append(pdf_path) return common.RunCommandExtractHashedFiles(cmd_to_run)
def test_one_file(input_filename, source_dir, working_dir, pdfium_test_path, image_differ, drmem_wrapper, redirect_output=False): input_path = os.path.join(source_dir, input_filename) pdf_path = os.path.join(working_dir, input_filename) # Remove any existing generated images from previous runs. actual_images = image_differ.GetActualFiles( input_filename, source_dir, working_dir) for image in actual_images: if os.path.exists(image): os.remove(image) shutil.copyfile(input_path, pdf_path) sys.stdout.flush() # add Dr. Memory wrapper if exist # remove .pdf suffix cmd_to_run = common.DrMemoryWrapper(drmem_wrapper, os.path.splitext(input_filename)[0]) cmd_to_run.extend([pdfium_test_path, '--png', pdf_path]) # run test error = common.RunCommand(cmd_to_run, redirect_output) if error: print "FAILURE: " + input_filename + "; " + str(error) return False return not image_differ.HasDifferences(input_filename, source_dir, working_dir, redirect_output)
def generate_and_test(input_filename, source_dir, working_dir, fixup_path, pdfium_test_path, text_diff_path, drmem_wrapper): input_root, _ = os.path.splitext(input_filename) input_path = os.path.join(source_dir, input_root + '.in') pdf_path = os.path.join(working_dir, input_root + '.pdf') txt_path = os.path.join(working_dir, input_root + '.txt') expected_path = os.path.join(source_dir, input_root + '_expected.txt') try: sys.stdout.flush() subprocess.check_call([ sys.executable, fixup_path, '--output-dir=' + working_dir, input_path ]) with open(txt_path, 'w') as outfile: # add Dr. Memory wrapper if exist cmd_to_run = common.DrMemoryWrapper(drmem_wrapper, input_root) cmd_to_run.extend([pdfium_test_path, pdf_path]) # run test subprocess.check_call(cmd_to_run, stdout=outfile) subprocess.check_call( [sys.executable, text_diff_path, expected_path, txt_path]) except subprocess.CalledProcessError as e: print "FAILURE: " + input_filename + "; " + str(e) return False return True
def TestText(self, input_root, expected_txt_path, pdf_path): txt_path = os.path.join(self.working_dir, input_root + '.txt') with open(txt_path, 'w') as outfile: # add Dr. Memory wrapper if exist cmd_to_run = common.DrMemoryWrapper(self.drmem_wrapper, input_root) cmd_to_run.extend([self.pdfium_test_path, pdf_path]) subprocess.check_call(cmd_to_run, stdout=outfile) cmd = [ sys.executable, self.text_diff_path, expected_txt_path, txt_path ] return common.RunCommand(cmd)
def TestPixel(self, input_root, pdf_path): cmd_to_run = common.DrMemoryWrapper(self.drmem_wrapper, input_root) cmd_to_run.extend( [self.pdfium_test_path, '--send-events', '--png', pdf_path]) return common.RunCommand(cmd_to_run)