test_pdfs.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. '''
  2. Compares the rendererings of serialized SkPictures to expected images.
  3. Launch with --help to see more information.
  4. Copyright 2012 Google Inc.
  5. Use of this source code is governed by a BSD-style license that can be
  6. found in the LICENSE file.
  7. '''
  8. # common Python modules
  9. import os
  10. import optparse
  11. import sys
  12. import shutil
  13. import tempfile
  14. import test_rendering
  15. USAGE_STRING = 'Usage: %s input... expectedDir'
  16. HELP_STRING = '''
  17. Takes input SkPicture files and renders them as PDF files, and then compares
  18. those resulting PDF files against PDF files found in expectedDir.
  19. Each instance of "input" can be either a file (name must end in .skp), or a
  20. directory (in which case this script will process all .skp files within the
  21. directory).
  22. '''
  23. def Main(args):
  24. """Allow other scripts to call this script with fake command-line args.
  25. @param The commandline argument list
  26. """
  27. parser = optparse.OptionParser(USAGE_STRING % '%prog' + HELP_STRING)
  28. parser.add_option('--render_dir', dest='render_dir',
  29. help = ('specify the location to output the rendered '
  30. 'files. Default is a temp directory.'))
  31. parser.add_option('--diff_dir', dest='diff_dir',
  32. help = ('specify the location to output the diff files. '
  33. 'Default is a temp directory.'))
  34. options, arguments = parser.parse_args(args)
  35. if (len(arguments) < 3):
  36. print("Expected at least one input and one ouput folder.")
  37. parser.print_help()
  38. sys.exit(-1)
  39. inputs = arguments[1:-1]
  40. expected_dir = arguments[-1]
  41. test_rendering.TestRenderSkps(inputs, expected_dir, options.render_dir,
  42. options.diff_dir, 'render_pdfs', '')
  43. if __name__ == '__main__':
  44. Main(sys.argv)