Expand parser and Unicode test coverage
[jansson.git] / test / split-testfile.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5
6 def open_files(outdir, i):
7     return (open(os.path.join(outdir, 'test%02d.in' % i), 'w'),
8             open(os.path.join(outdir, 'test%02d.out' % i), 'w'))
9
10 def close_files(input, output):
11     print os.path.basename(input.name), os.path.basename(output.name)
12     input.close()
13     output.close()
14
15 def main():
16     if len(sys.argv) != 3:
17         print 'usage: %s input-file output-directory' % sys.argv[0]
18         return 2
19
20     infile = os.path.normpath(sys.argv[1])
21     outdir = os.path.normpath(sys.argv[2])
22
23     if not os.path.exists(outdir):
24         print >>sys.stderr, 'output directory %r does not exist!' % outdir
25         return 1
26
27     i = 0
28     input, output = open_files(outdir, i)
29     current = input
30
31     for line in open(infile):
32         if line == '====\n':
33             current = output
34         elif line == '========\n':
35             close_files(input, output)
36             i += 1
37             input, output = open_files(outdir, i)
38             current = input
39         else:
40             current.write(line)
41
42     close_files(input, output)
43     print >>sys.stderr, "%s: %d test cases" % (infile, i + 1)
44
45 if __name__ == '__main__':
46     sys.exit(main() or 0)