Add <target> to one more testcase (see r8206).
[docutils.git] / sandbox / grubert / split-test-txt.py
blob81cb1fd84a3c6ba6ad4723a75f7f431ceb146472
1 #!/usr/bin/python
3 """
4 Author: grubert@users.sourceforge.net
5 Revision: $Revision$
7 Split docutils/tools/test.txt up to test one by one.
8 """
10 import sys, os, os.path
12 if len(sys.argv)>1:
13 test_filename = sys.argv[1]
14 else:
15 # run from sandbox subdirectory.
16 test_filename = "../../tools/test.txt"
18 if not os.path.exists(test_filename):
19 print "Testfile not found:", test_filename
20 sys.exit()
22 print "Using file:", test_filename
24 class Output:
25 def __init__(self,test_dir="test"):
26 self._file = 0
27 self._file_cnt = 0
28 self._test_dir = test_dir
29 self._test_file = "from_test_txt"
30 def close(self):
31 if self._file:
32 self._file.close()
33 def next_file(self):
34 self.close()
35 self._file_cnt += 1
36 self._file = open("%s/%s-%02d.txt.new"
37 %(self._test_dir,self._test_file,self._file_cnt),"w")
38 def write_line(self,str):
39 self._file.write(str+"\n")
40 def get_count(self):
41 return self._file_cnt
43 out = Output()
44 out.next_file()
46 line_before = -1
47 section_one = 1 # header plus first section into first file
48 for line in open(test_filename).readlines():
49 line = line.rstrip() # remove end of line
50 # we split on "------" sections.
51 if ((len(line)>0)and(line == "-"*(len(line)))and(len(line)==len(line_before))):
52 if not section_one:
53 out.next_file()
54 print section_one,line_before,line
55 section_one = 0
56 if not (type(line_before)==type(-1)):
57 # special treatment of start block
58 out.write_line(line_before)
59 line_before = line
61 out.close()