source: proto/PDF/test/run_tests.py @ 2908

Last change on this file since 2908 was 2664, checked in by bhull, 7 years ago

Test data changes

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