180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru''' 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruCompares the rendererings of serialized SkPictures to expected images. 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruLaunch with --help to see more information. 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruCopyright 2012 Google Inc. 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruUse of this source code is governed by a BSD-style license that can be 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querufound in the LICENSE file. 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru''' 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru# common Python modules 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruimport os 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruimport optparse 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruimport sys 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruimport shutil 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruimport tempfile 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruimport test_rendering 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruUSAGE_STRING = 'Usage: %s input... expectedDir' 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruHELP_STRING = ''' 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruTakes input SkPicture files and renders them as PDF files, and then compares 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruthose resulting PDF files against PDF files found in expectedDir. 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruEach instance of "input" can be either a file (name must end in .skp), or a 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querudirectory (in which case this script will process all .skp files within the 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querudirectory). 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru''' 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querudef Main(args): 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru """Allow other scripts to call this script with fake command-line args. 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru @param The commandline argument list 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru """ 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parser = optparse.OptionParser(USAGE_STRING % '%prog' + HELP_STRING) 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parser.add_option('--render_dir', dest='render_dir', 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru help = ('specify the location to output the rendered ' 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 'files. Default is a temp directory.')) 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parser.add_option('--diff_dir', dest='diff_dir', 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru help = ('specify the location to output the diff files. ' 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 'Default is a temp directory.')) 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru options, arguments = parser.parse_args(args) 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (len(arguments) < 3): 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru print("Expected at least one input and one ouput folder.") 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parser.print_help() 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru sys.exit(-1) 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru inputs = arguments[1:-1] 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru expected_dir = arguments[-1] 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru test_rendering.TestRenderSkps(inputs, expected_dir, options.render_dir, 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru options.diff_dir, 'render_pdfs', '') 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruif __name__ == '__main__': 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Main(sys.argv) 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 61