source: proto/PDF/test/run_tests.py

Last change on this file was 3241, checked in by ksherdy, 6 years ago

Del readme.

File size: 2.6 KB
Line 
1#
2# run_tests.py
3#
4# Quick-and-dirty Python PDF test script.
5# Generates expected output files.
6# Diffs generated files against expected values.
7#
8# Created on: April 12, 2012
9# Modified: November 2012 - Re-targetted for PDF tests.
10# Author: Ken Herdy, Ben Hull
11#
12#----------------------------------------------------------------------------
13# Edit:
14#program_path='../pdf.py'
15test_dir_path='../test/data'
16out_dir_path='../test/out'
17test_suffix='.in'
18
19#----------------------------------------------------------------------------
20import sys
21import os
22import subprocess
23import shutil
24import fnmatch                 
25import string
26#----------------------------------------------------------------------------
27# Test cases. Quick and dirty.
28#----------------------------------------------------------------------------
29
30def gen_test_file(program, input_file, outfile_root):
31        (head, tail) = os.path.split(input_file)
32        temp = head[head.find('/')+1:]
33       
34        outputdir = os.path.join(os.path.join(outfile_root, temp), tail)
35
36        (head, tail) = os.path.split(outputdir)
37        if os.path.exists(head)==False:
38                os.makedirs(head)
39        print head + os.path.sep + tail
40        out_f = open(head + os.path.sep + tail, 'w')
41        if program.endswith('.py'):
42                subprocess.call(['python', program, input_file], stderr=None, stdout=out_f)
43        else:
44                subprocess.call([program, input_file], stderr=None, stdout=out_f)
45        out_f.close()
46
47def gen_test_file_list(test_dir_path):
48    test_files = []
49    for dirname, dirnames, filenames in os.walk(test_dir_path):
50            for filename in filenames:
51                    if filename.endswith(test_suffix) and not filename.endswith('.svn-base'):
52                            test_files.append(os.path.relpath(os.path.join(dirname, filename)))
53    return test_files
54
55#----------------------------------------------------------------------------
56# Command line args.
57#----------------------------------------------------------------------------
58import optparse
59def get_option_parser():
60        """Return an C{optparse.OptionParser} instance tied to this configuration."""
61       
62        parser = optparse.OptionParser(usage='python %prog', version='1.0')
63
64        return parser
65#----------------------------------------------------------------------------
66
67if __name__ == "__main__":
68
69        option_parser = get_option_parser() 
70        options, args = option_parser.parse_args(sys.argv[1:])
71
72        if len(args) != 1:
73            option_parser.print_usage()
74            sys.exit()
75
76        if not os.path.isfile(sys.argv[1]):
77            option_parser.print_usage()
78            sys.exit()
79
80        program = sys.argv[1]
81
82        test_files = gen_test_file_list(test_dir_path)
83
84        print test_files
85
86        for test_file in test_files:
87                gen_test_file(program, test_file, out_dir_path)
Note: See TracBrowser for help on using the repository browser.