annotate test.py @ 6:b0034b18f942

maxexitcode now gets on with test groups This includes the implied single-test-case groups.
author Oleg Oshmyan <chortos@inbox.lv>
date Sun, 14 Feb 2010 00:17:43 +0000
parents eb15a5a9b026
children ed90b375d197
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
1 #! /usr/bin/python
3
cd4304ff1d1b Minor changes
Oleg Oshmyan <chortos@inbox.lv>
parents: 2
diff changeset
2 # Copyright (c) 2009-2010 Chortos-2 <chortos@inbox.lv>
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
3
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
4 import os, sys, shutil, time, subprocess, filecmp, optparse, signal, tempfile, tarfile, zipfile
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
5
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
6 parser = optparse.OptionParser(version='test.py 1.21.0 (SVN)', usage='usage: %prog [options] [problem names] [[path' + os.path.sep + 'to' + os.path.sep + ']solution-app] [test case numbers]\n\nTest case numbers can be specified in plain text or as a Python expression\nif there is only one positional argument.\n\nOnly problem names listed in testconf.py are recognized.')
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
7 parser.add_option('-e', '--exclude', dest='exclude', action='append', help='test case number(s) to exclude, as a Python expression; multiple -e options can be supplied')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
8 parser.add_option('-c', '--cleanup', dest='clean', action='store_true', default=False, help='delete the copies of input/output files and exit')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
9 parser.add_option('-s', '--save-io', dest='erase', action='store_false', default=True, help='do not delete the copies of input/output files after the last test case; create copies of input files and store output in files even if the solution uses standard I/O; delete the stored input/output files if the solution uses standard I/O and the -c/--cleanup option is specified')
4
06eef313aeaa -c command line option fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 3
diff changeset
10 parser.add_option('-m', '--copy-io', dest='copyonly', action='store_true', default=False, help='only create a copy of the input/output files of the last test case for manual testing; to delete them, use options -cs or -cm')
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
11 parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed when finished testing')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
12 parser.add_option('-p', '--python', action='store_true', default=False, help='always parse all positional arguments as a single Python expression (including the first argument even if it names an executable file)')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
13 parser.add_option('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
14
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
15 options, args = parser.parse_args()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
16 parser.destroy()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
17 del parser
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
18
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
19 globals1 = set(globals())
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
20
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
21 # Initialize some configuration variables with default values
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
22 tasknames = (os.path.curdir,)
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
23 maxtime = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
24 tests = ()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
25 dummies = ()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
26 testsexcluded = ()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
27 padwithzeroestolength = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
28 taskweight = 100
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
29 pointmap = {}
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
30 stdio = False
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
31 dummyinname = ''
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
32 dummyoutname = ''
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
33 tester = ''
5
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
34 maxexitcode = 0
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
35
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
36 def exectestconf_helper(name):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
37 if os.path.isfile('tests.tar'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
38 f = tarfile.open('tests.tar')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
39 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
40 exec f.extractfile(name).read() in globals()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
41 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
42 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
43 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
44 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
45 if os.path.isfile('tests.zip'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
46 f = zipfile.ZipFile('tests.zip')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
47 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
48 exec f.open(name, 'rU').read() in globals()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
49 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
50 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
51 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
52 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
53 if os.path.isfile('tests.tgz'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
54 f = tarfile.open('tests.tgz')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
55 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
56 exec f.extractfile(name).read() in globals()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
57 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
58 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
59 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
60 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
61 if os.path.isfile('tests.tar.gz'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
62 f = tarfile.open('tests.tar.gz')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
63 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
64 exec f.extractfile(name).read() in globals()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
65 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
66 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
67 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
68 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
69 if os.path.isfile('tests.tbz2'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
70 f = tarfile.open('tests.tbz2')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
71 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
72 exec f.extractfile(name).read() in globals()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
73 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
74 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
75 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
76 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
77 if os.path.isfile('tests.tar.bz2'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
78 f = tarfile.open('tests.tar.bz2')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
79 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
80 exec f.extractfile(name).read() in globals()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
81 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
82 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
83 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
84 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
85 return False
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
86
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
87 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
88 execfile('testconf.py')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
89 except IOError, error:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
90 exc_info = sys.exc_info()[2]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
91 try:
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
92 execfile(os.path.join('tests', 'testconf.py'))
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
93 except IOError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
94 if not exectestconf_helper('testconf.py'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
95 raise IOError, (error.errno, 'The configuration file is missing', error.filename), exc_info
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
96 del exc_info
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
97
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
98 globals2 = set(globals())
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
99 globals2.remove('globals1')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
100 globals2 -= globals1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
101 del globals1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
102
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
103 shared = {}
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
104 g = globals()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
105 for k in globals2:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
106 shared[k] = g[k]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
107
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
108 newtasknames = []
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
109 while len(args) and args[0] in tasknames:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
110 newtasknames.append(args[0])
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
111 del args[0]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
112 if len(newtasknames):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
113 tasknames = newtasknames
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
114
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
115 scoresumoveralltasks = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
116 scoremaxoveralltasks = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
117 ntasks = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
118 nfulltasks = 0
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
119 cwd = '' # At any time this is either '' or taskname
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
120
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
121 if options.autotime:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
122 c = time.clock()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
123 time.sleep(1)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
124 c = time.clock() - c
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
125 if int(c + .99999) == 1:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
126 clock = time.clock
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
127 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
128 clock = time.time
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
129 elif os.name == 'nt':
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
130 clock = time.clock
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
131 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
132 clock = time.time
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
133
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
134 if options.copyonly:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
135 options.erase = False
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
136
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
137 def existstestcase_helper(name):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
138 if os.path.isfile('tests.tar'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
139 f = tarfile.open('tests.tar')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
140 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
141 f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
142 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
143 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
144 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
145 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
146 if os.path.isfile('tests.zip'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
147 f = zipfile.ZipFile('tests.zip')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
148 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
149 f.getinfo(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
150 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
151 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
152 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
153 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
154 if os.path.isfile('tests.tgz'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
155 f = tarfile.open('tests.tgz')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
156 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
157 f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
158 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
159 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
160 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
161 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
162 if os.path.isfile('tests.tar.gz'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
163 f = tarfile.open('tests.tar.gz')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
164 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
165 f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
166 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
167 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
168 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
169 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
170 if os.path.isfile('tests.tbz2'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
171 f = tarfile.open('tests.tbz2')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
172 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
173 f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
174 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
175 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
176 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
177 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
178 if os.path.isfile('tests.tar.bz2'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
179 f = tarfile.open('tests.tar.bz2')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
180 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
181 f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
182 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
183 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
184 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
185 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
186 return False
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
187
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
188 def existstestcase(name):
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
189 if os.path.isfile(os.path.join('tests', taskname, name)) or os.path.isfile(os.path.join('tests', name)):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
190 return True
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
191 if cwd and (os.path.isfile(os.path.join(oldcwd, 'tests', cwd, name)) or os.path.isfile(os.path.join(oldcwd, 'tests', name))):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
192 return True
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
193 if existstestcase_helper(os.path.join(taskname, name)) or existstestcase_helper(name):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
194 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
195 if cwd:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
196 os.chdir(oldcwd)
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
197 if existstestcase_helper(os.path.join(cwd, name)) or existstestcase_helper(name):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
198 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
199 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
200 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
201 return False
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
202
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
203 def opentestcase_helper(name):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
204 if os.path.isfile('tests.tar'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
205 f = tarfile.open('tests.tar')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
206 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
207 c = f.extractfile(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
208 return c
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
209 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
210 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
211 if os.path.isfile('tests.zip'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
212 f = zipfile.ZipFile('tests.zip')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
213 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
214 c = f.open(name, 'rU')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
215 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
216 return c
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
217 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
218 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
219 if os.path.isfile('tests.tgz'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
220 f = tarfile.open('tests.tgz')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
221 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
222 c = f.extractfile(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
223 return c
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
224 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
225 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
226 if os.path.isfile('tests.tar.gz'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
227 f = tarfile.open('tests.tar.gz')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
228 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
229 c = f.extractfile(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
230 return c
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
231 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
232 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
233 if os.path.isfile('tests.tbz2'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
234 f = tarfile.open('tests.tbz2')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
235 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
236 c = f.extractfile(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
237 return c
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
238 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
239 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
240 if os.path.isfile('tests.tar.bz2'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
241 f = tarfile.open('tests.tar.bz2')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
242 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
243 c = f.extractfile(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
244 return c
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
245 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
246 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
247 return None
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
248
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
249 def opentestcase(name):
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
250 if os.path.isfile(os.path.join('tests', taskname, name)):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
251 return open(os.path.join('tests', taskname, name), 'rU')
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
252 elif os.path.isfile(os.path.join('tests', name)):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
253 return open(os.path.join('tests', name), 'rU')
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
254 f = opentestcase_helper(os.path.join(taskname, name))
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
255 if not f:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
256 f = opentestcase_helper(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
257 if f:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
258 return f
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
259 if cwd:
3
cd4304ff1d1b Minor changes
Oleg Oshmyan <chortos@inbox.lv>
parents: 2
diff changeset
260 if os.path.isfile(os.path.join(oldcwd, 'tests', cwd, name)):
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
261 return open(os.path.join(oldcwd, 'tests', cwd, name), 'rU')
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
262 elif os.path.isfile(os.path.join(oldcwd, 'tests', name)):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
263 return open(os.path.join(oldcwd, 'tests', name), 'rU')
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
264 os.chdir(oldcwd)
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
265 f = opentestcase_helper(os.path.join(cwd, name))
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
266 if not f:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
267 f = opentestcase_helper(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
268 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
269 if f:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
270 return f
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
271 raise KeyError, 'The test-case-defining file \'' + name + '\' cannot be found'
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
272
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
273 def copytestcase_helper(name, target):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
274 if os.path.isfile('tests.tar'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
275 f = tarfile.open('tests.tar')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
276 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
277 m = f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
278 m.name = target
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
279 f.extract(m)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
280 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
281 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
282 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
283 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
284 if os.path.isfile('tests.zip'):
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
285 if not os.path.isabs(target):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
286 f = zipfile.ZipFile('tests.zip')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
287 m = f.getinfo(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
288 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
289 m.filename = target
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
290 f.extract(m)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
291 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
292 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
293 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
294 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
295 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
296 oldcwd = os.getcwdu()
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
297 os.chdir('/') # FIXME: portability?
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
298 f = zipfile.ZipFile(os.path.join(oldcwd, 'tests.zip'))
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
299 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
300 m = f.getinfo(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
301 m.filename = target[1:]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
302 f.extract(m)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
303 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
304 os.chdir(oldcwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
305 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
306 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
307 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
308 os.chdir(oldwcd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
309 if os.path.isfile('tests.tgz'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
310 f = tarfile.open('tests.tgz')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
311 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
312 m = f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
313 m.name = target
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
314 f.extract(m)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
315 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
316 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
317 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
318 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
319 if os.path.isfile('tests.tar.gz'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
320 f = tarfile.open('tests.tar.gz')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
321 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
322 m = f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
323 m.name = target
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
324 f.extract(m)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
325 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
326 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
327 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
328 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
329 if os.path.isfile('tests.tbz2'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
330 f = tarfile.open('tests.tbz2')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
331 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
332 m = f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
333 m.name = target
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
334 f.extract(m)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
335 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
336 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
337 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
338 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
339 if os.path.isfile('tests.tar.bz2'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
340 f = tarfile.open('tests.tar.bz2')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
341 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
342 m = f.getmember(name)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
343 m.name = target
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
344 f.extract(m)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
345 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
346 return True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
347 except KeyError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
348 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
349 return False
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
350
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
351 def copytestcase(name, target):
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
352 if os.path.isfile(os.path.join('tests', taskname, name)):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
353 shutil.copyfile(os.path.join('tests', taskname, name), target)
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
354 return
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
355 elif os.path.isfile(os.path.join('tests', name)):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
356 shutil.copyfile(os.path.join('tests', name), target)
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
357 return
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
358 if copytestcase_helper(os.path.join(taskname, name), target) or copytestcase_helper(name, target):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
359 return
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
360 if cwd:
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
361 if os.path.isfile(os.path.join(oldcwd, 'tests', cwd, name)):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
362 shutil.copyfile(os.path.join(oldcwd, 'tests', cwd, name), target)
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
363 return
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
364 elif os.path.isfile(os.path.join(oldcwd, 'tests', name)):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
365 shutil.copyfile(os.path.join(oldcwd, 'tests', name), target)
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
366 return
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
367 os.chdir(oldcwd)
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
368 if copytestcase_helper(os.path.join(cwd, name), target) or copytestcase_helper(name, target):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
369 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
370 return
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
371 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
372 raise KeyError, 'The test-case-defining file \'' + name + '\' cannot be found'
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
373
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
374 # Always chdir if the directory exists but use any existing config
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
375 def chdir_and_exec_testconf():
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
376 global cwd
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
377 cwd = ''
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
378 if os.path.isdir(taskname):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
379 os.chdir(taskname)
3
cd4304ff1d1b Minor changes
Oleg Oshmyan <chortos@inbox.lv>
parents: 2
diff changeset
380 if taskname != os.path.curdir:
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
381 cwd = taskname
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
382 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
383 execfile('testconf.py', globals())
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
384 return
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
385 except IOError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
386 pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
387 if not cwd:
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
388 if os.path.isfile(os.path.join('tests', taskname, 'testconf.py')):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
389 execfile(os.path.join('tests', taskname, 'testconf.py'), globals())
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
390 return
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
391 if os.path.isfile(os.path.join('tests', 'testconf.py')):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
392 execfile(os.path.join('tests', 'testconf.py'), globals())
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
393 return
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
394 if exectestconf_helper(os.path.join(taskname, 'testconf.py')) or exectestconf_helper('testconf.py'):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
395 return
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
396 if cwd:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
397 os.chdir(oldcwd)
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
398 if os.path.isfile(os.path.join('tests', cwd, 'testconf.py')):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
399 execfile(os.path.join('tests', cwd, 'testconf.py'), globals())
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
400 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
401 return
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
402 if os.path.isfile(os.path.join('tests', 'testconf.py')):
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
403 execfile(os.path.join('tests', 'testconf.py'), globals())
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
404 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
405 return
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
406 if exectestconf_helper(os.path.join(cwd, 'testconf.py')) or exectestconf_helper('testconf.py'):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
407 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
408 return
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
409 if os.path.isfile('testconf.py'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
410 execfile('testconf.py', globals())
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
411 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
412 return
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
413 os.chdir(cwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
414 elif os.path.isfile('testconf.py'):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
415 execfile('testconf.py', globals())
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
416 return
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
417 raise KeyError, 'The configuration file for task ' + taskname + ' is missing'
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
418
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
419 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
420 name
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
421 namedefined = True
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
422 except Exception:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
423 namedefined = False
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
424
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
425 for taskname in tasknames:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
426 if ntasks:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
427 print
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
428
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
429 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
430 if len(tasknames) > 1:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
431 print taskname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
432 except Exception:
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
433 if taskname != os.path.curdir or ntasks:
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
434 print taskname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
435
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
436 try: del inname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
437 except NameError: pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
438 try: del outname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
439 except NameError: pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
440 try: del ansname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
441 except NameError: pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
442
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
443 if not namedefined and taskname != os.path.curdir:
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
444 name = os.path.join(os.path.curdir, taskname)
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
445 for k in shared:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
446 g[k] = shared[k]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
447
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
448 oldcwd = os.getcwdu()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
449 chdir_and_exec_testconf()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
450
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
451 if options.clean:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
452 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
453 if not stdio or tester:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
454 if not tester:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
455 inname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
456 outname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
457 if tester:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
458 ansname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
459 except NameError, error:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
460 raise NameError, 'configuration ' + str(error).replace('name ', 'variable ', 1), sys.exc_info()[2]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
461 if not options.erase:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
462 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
463 inname = inname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
464 except NameError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
465 inname = taskname + '.in'
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
466 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
467 outname = outname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
468 except NameError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
469 outname = taskname + '.out'
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
470 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
471 ansname = ansname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
472 except NameError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
473 ansname = taskname + '.ans'
4
06eef313aeaa -c command line option fixes
Oleg Oshmyan <chortos@inbox.lv>
parents: 3
diff changeset
474 elif not stdio or tester or not options.erase:
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
475 inname = inname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
476 outname = outname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
477 if tester:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
478 ansname = ansname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
479 if not stdio or tester or not options.erase:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
480 if os.path.exists(inname): os.remove(inname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
481 if os.path.exists(outname): os.remove(outname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
482 if (tester or not options.erase) and ansname:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
483 if os.path.exists(ansname): os.remove(ansname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
484 continue
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
485
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
486 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
487 name
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
488 except NameError, error:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
489 if str(error).count('name') == 1:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
490 raise NameError, 'configuration ' + str(error), sys.exc_info()[2]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
491 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
492 raise NameError, 'configuration ' + str(error).replace('name ', 'variable ', 1), sys.exc_info()[2]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
493
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
494 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
495 if not stdio:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
496 inname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
497 outname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
498 testcaseinname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
499 if tester:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
500 outname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
501 if ansname:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
502 testcaseoutname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
503 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
504 testcaseoutname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
505 except NameError, error:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
506 raise NameError, 'configuration ' + str(error).replace('name ', 'variable ', 1), sys.exc_info()[2]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
507
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
508 if not options.erase:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
509 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
510 inname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
511 except NameError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
512 inname = taskname + '.in'
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
513 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
514 outname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
515 except NameError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
516 outname = taskname + '.out'
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
517 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
518 ansname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
519 except NameError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
520 ansname = taskname + '.ans'
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
521
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
522 if options.pause:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
523 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
524 pause
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
525 except NameError, error:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
526 if os.name == 'posix':
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
527 pause = 'read -s -n 1'
3
cd4304ff1d1b Minor changes
Oleg Oshmyan <chortos@inbox.lv>
parents: 2
diff changeset
528 print 'Configuration ' + str(error).replace('name ', 'variable ') + '; it was devised automatically but the choice might be incorrect, so test.py might exit immediately after the testing is completed.'
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
529 elif os.name == 'nt':
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
530 pause = 'pause'
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
531 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
532 raise NameError, 'configuration ' + str(error).replace('name ', 'variable ') + ' and cannot be devised automatically', sys.exc_info()[2]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
533
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
534 if not dummyinname:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
535 dummyinname = testcaseinname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
536 if not dummyoutname and (not tester or ansname):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
537 dummyoutname = testcaseoutname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
538
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
539 dummyinname = dummyinname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
540 dummyoutname = dummyoutname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
541 testcaseinname = testcaseinname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
542 if not stdio or not options.erase:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
543 inname = inname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
544 outname = outname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
545 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
546 ansname = ansname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
547 except NameError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
548 pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
549 if tester:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
550 try: inname = inname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
551 except NameError: pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
552 outname = outname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
553 if ansname:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
554 ansname = ansname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
555 testcaseoutname = testcaseoutname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
556 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
557 testcaseoutname = testcaseoutname.replace('%', taskname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
558
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
559 if isinstance(padwithzeroestolength, tuple):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
560 padwithzeroestolength, paddummieswithzeroestolength = padwithzeroestolength
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
561 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
562 paddummieswithzeroestolength = padwithzeroestolength
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
563
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
564 if options.python:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
565 dummies = ()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
566 s = ' '.join(args)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
567 tests = eval(s)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
568 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
569 tests.__iter__
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
570 except AttributeError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
571 tests = (tests,)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
572 elif len(args):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
573 if os.path.exists(args[0]):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
574 name = args[0]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
575 del args[0]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
576 if len(args) > 1:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
577 dummies = ()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
578 tests = args
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
579 elif len(args):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
580 dummies = ()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
581 s = args[0]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
582 if len(s) < padwithzeroestolength:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
583 s = s.zfill(padwithzeroestolength)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
584 if existstestcase(testcaseinname.replace('$', s)):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
585 tests = (s,)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
586 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
587 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
588 tests = eval(args[0])
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
589 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
590 tests.__iter__
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
591 except AttributeError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
592 tests = (tests,)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
593 except Exception:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
594 tests = (s,)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
595
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
596 if options.exclude:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
597 testsexcluded = []
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
598 for i in options.exclude:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
599 v = eval(i)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
600 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
601 testsexcluded.extend(v)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
602 except TypeError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
603 testsexcluded.append(v)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
604
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
605 # Windows doesn't like paths beginning with .\ and not ending with an extension
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
606 name = os.path.normcase(name)
2
bddcc05aba59 Finished path portability improvements
Oleg Oshmyan <chortos@inbox.lv>
parents: 1
diff changeset
607 if os.name == 'nt' and name.startswith('.\\'):
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
608 name = name[2:]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
609
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
610 newpointmap = {}
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
611
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
612 for i in pointmap:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
613 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
614 for j in i:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
615 newpointmap[j] = pointmap[i]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
616 except TypeError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
617 newpointmap[i] = pointmap[i]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
618
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
619 pointmap = newpointmap
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
620
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
621 if maxtime > 0:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
622 strmaxtime = '/%.3f' % maxtime
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
623 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
624 strmaxtime = ''
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
625
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
626 padoutputtolength = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
627 ntests = []
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
628
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
629 for j in dummies:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
630 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
631 j.__iter__
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
632 except AttributeError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
633 j = (j,)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
634 ntests.append((j, True))
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
635 for i in j:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
636 s = str(i)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
637 if len(s) < paddummieswithzeroestolength:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
638 s = s.zfill(paddummieswithzeroestolength)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
639 s = 'sample ' + s
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
640 if padoutputtolength < len(s):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
641 padoutputtolength = len(s)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
642
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
643 for j in tests:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
644 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
645 j.__iter__
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
646 except AttributeError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
647 j = (j,)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
648 ntests.append((j, False))
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
649 for i in j:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
650 s = str(i)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
651 if len(s) < padwithzeroestolength:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
652 s = s.zfill(padwithzeroestolength)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
653 if padoutputtolength < len(s):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
654 padoutputtolength = len(s)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
655
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
656 tests = ntests
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
657 score = maxpoints = ncorrect = ntotal = ncorrectvalued = nvalued = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
658
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
659 if options.copyonly:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
660 j, isdummy = tests[-1]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
661 if isdummy:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
662 realinname = dummyinname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
663 realoutname = dummyoutname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
664 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
665 realinname = testcaseinname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
666 realoutname = testcaseoutname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
667 for i in j:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
668 if i in testsexcluded and not isdummy:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
669 continue
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
670 s = str(i)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
671 if isdummy:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
672 if len(s) < paddummieswithzeroestolength:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
673 s = s.zfill(paddummieswithzeroestolength)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
674 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
675 if len(s) < padwithzeroestolength:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
676 s = s.zfill(padwithzeroestolength)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
677 copytestcase(realinname.replace('$', s), inname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
678 if ansname:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
679 copytestcase(realoutname.replace('$', s), ansname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
680 continue
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
681
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
682 for j, isdummy in tests:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
683 ncorrectgrp = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
684 ntotalgrp = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
685 scoregrp = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
686 maxpointsgrp = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
687 if isdummy:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
688 realinname = dummyinname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
689 realoutname = dummyoutname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
690 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
691 realinname = testcaseinname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
692 realoutname = testcaseoutname
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
693 for i in j:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
694 if i in testsexcluded and not isdummy:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
695 continue
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
696 ntotalgrp += 1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
697 s = str(i)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
698 if isdummy:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
699 npoints = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
700 if len(s) < paddummieswithzeroestolength:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
701 s = s.zfill(paddummieswithzeroestolength)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
702 spref = 'sample '
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
703 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
704 npoints = pointmap.get(None, 1)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
705 npoints = pointmap.get(i, npoints)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
706 maxpointsgrp += npoints
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
707 if npoints:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
708 nvalued += 1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
709 if len(s) < padwithzeroestolength:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
710 s = s.zfill(padwithzeroestolength)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
711 spref = ''
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
712 print ' ' * (padoutputtolength - len(spref + s)) + spref + s + ':',
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
713 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
714 outputdata = open(os.devnull, 'w')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
715 if stdio:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
716 f = tempfile.NamedTemporaryFile(delete=False)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
717 inputdatafname = f.name
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
718 f.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
719 copytestcase(realinname.replace('$', s), inputdatafname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
720 inputdata = open(inputdatafname, 'rU')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
721 if options.erase:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
722 tempoutput = tempfile.TemporaryFile('w+')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
723 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
724 tempoutput = open(outname, 'w+')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
725 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
726 proc = subprocess.Popen(name, stdin=inputdata, stdout=tempoutput, stderr=outputdata, universal_newlines=True)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
727 except OSError, error:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
728 raise OSError, 'The program to be tested cannot be launched: ' + str(error), sys.exc_info()[2]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
729 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
730 if os.path.exists(outname):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
731 os.remove(outname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
732 copytestcase(realinname.replace('$', s), inname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
733 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
734 proc = subprocess.Popen(name, stdin=outputdata, stdout=outputdata, stderr=outputdata, universal_newlines=True)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
735 except OSError, error:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
736 raise OSError, 'The program to be tested cannot be launched: ' + str(error), sys.exc_info()[2]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
737 cl = clock()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
738 if maxtime > 0:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
739 while 1:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
740 proc.poll()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
741 elapsed = clock() - cl
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
742 if proc.returncode == None:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
743 if elapsed >= maxtime:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
744 print '%.3f%s s, 0/%d, time limit exceeded' % (elapsed, strmaxtime, npoints)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
745 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
746 while proc.returncode == None:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
747 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
748 proc.terminate()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
749 except OSError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
750 pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
751 except AttributeError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
752 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
753 os.kill(proc.pid, signal.SIGTERM)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
754 except Exception:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
755 pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
756 proc.poll()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
757 outputdata.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
758 if stdio:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
759 tempoutput.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
760 break
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
761 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
762 print '%.3f%s s,' % (elapsed, strmaxtime),
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
763 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
764 elapsed = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
765 if stdio:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
766 tempoutput.seek(0)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
767 lines = tempoutput.readlines()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
768 tempoutput.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
769 break
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
770 if elapsed >= maxtime:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
771 continue
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
772 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
773 data = proc.communicate()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
774 elapsed = clock() - cl
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
775 print '%.3f%s s,' % (elapsed, strmaxtime),
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
776 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
777 if stdio:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
778 tempoutput.seek(0)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
779 lines = tempoutput.readlines()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
780 tempoutput.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
781 outputdata.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
782 if stdio:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
783 inputdata.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
784 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
785 os.unlink(inputdatafname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
786 except Exception:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
787 pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
788 if proc.returncode > 0:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
789 print '0/%d, non-zero return code %d' % (npoints, proc.returncode)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
790 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
791 elif proc.returncode < 0:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
792 print '0/%d, terminated by signal %d' % (npoints, -proc.returncode)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
793 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
794 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
795 if not tester:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
796 if stdio:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
797 outputdata = opentestcase(realoutname.replace('$', s))
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
798 r = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
799 data = outputdata.read().splitlines(True)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
800 if len(lines) != len(data):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
801 r = 1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
802 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
803 for i in zip(lines, data):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
804 if i[0] != i[1]:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
805 r = 1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
806 break
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
807 outputdata.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
808 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
809 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
810 inputdata = open(outname, 'rU')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
811 except IOError:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
812 print '0/%g, output file not created or not readable' % npoints
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
813 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
814 r = None
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
815 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
816 outputdata = opentestcase(realoutname.replace('$', s))
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
817 r = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
818 lines = inputdata.readlines()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
819 data = outputdata.read().splitlines(True)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
820 if len(lines) != len(data):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
821 r = 1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
822 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
823 for i in zip(lines, data):
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
824 if i[0] != i[1]:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
825 r = 1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
826 break
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
827 inputdata.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
828 outputdata.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
829 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
830 if ansname:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
831 copytestcase(realoutname.replace('$', s), ansname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
832 if stdio:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
833 try: copytestcase(realinname.replace('$', s), inname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
834 except NameError: pass
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
835 outputdata = open(outname, 'w')
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
836 outputdata.writelines(lines)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
837 outputdata.close()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
838 try:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
839 proc = subprocess.Popen(tester, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
840 except OSError, error:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
841 raise OSError, 'The tester application cannot be launched: ' + str(error), sys.exc_info()[2]
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
842 data = proc.communicate()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
843 r = proc.returncode
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
844 if tester and data[0]:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
845 data = ''.join((' (', data[0].strip(), ')'))
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
846 else:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
847 data = ''
5
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
848 if not maxexitcode and r or maxexitcode and not r:
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
849 print '0/%g, wrong answer%s' % (npoints, data)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
850 sys.stdout.flush()
5
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
851 elif not maxexitcode and r == 0 or maxexitcode and r >= maxexitcode:
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
852 print '%g/%g, OK%s' % (npoints, npoints, data)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
853 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
854 scoregrp += npoints
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
855 ncorrectgrp += 1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
856 if npoints:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
857 ncorrectvalued += 1
5
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
858 elif maxexitcode and r != None:
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
859 actualpoints = npoints*r/maxexitcode if not npoints*r%maxexitcode else float(npoints*r)/maxexitcode
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
860 print '%g/%g, partly OK%s' % (actualpoints, npoints, data)
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
861 sys.stdout.flush()
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
862 scoregrp += actualpoints
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
863 ncorrectgrp += 1
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
864 if npoints:
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
865 ncorrectvalued += 1
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
866 if ntotalgrp:
6
b0034b18f942 maxexitcode now gets on with test groups
Oleg Oshmyan <chortos@inbox.lv>
parents: 5
diff changeset
867 if ncorrectgrp < ntotalgrp:
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
868 scoregrp = 0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
869 if ntotalgrp > 1:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
870 print 'Group total: %d/%d tests; %g/%g points' % (ncorrectgrp, ntotalgrp, scoregrp, maxpointsgrp)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
871 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
872 ncorrect += ncorrectgrp
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
873 ntotal += ntotalgrp
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
874 score += scoregrp
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
875 maxpoints += maxpointsgrp
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
876
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
877 if options.erase:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
878 if not stdio or tester:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
879 if os.path.exists(inname): os.remove(inname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
880 if os.path.exists(outname): os.remove(outname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
881 if tester and ansname:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
882 if os.path.exists(ansname): os.remove(ansname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
883 elif stdio:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
884 copytestcase(realinname.replace('$', s), inname)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
885 copytestcase(realoutname.replace('$', s), ansname)
5
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
886 actualpoints = (score*taskweight/maxpoints if not score*taskweight%maxpoints else float(score*taskweight)/maxpoints) if maxpoints else 0
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
887 if nvalued != ntotal:
5
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
888 print 'Grand total: %d/%d tests (%d/%d valued); %g/%g points; weighted score: %g/%g' % (ncorrect, ntotal, ncorrectvalued, nvalued, score, maxpoints, actualpoints, taskweight)
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
889 else:
5
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
890 print 'Grand total: %d/%d tests; %g/%g points; weighted score: %g/%g' % (ncorrect, ntotal, score, maxpoints, actualpoints, taskweight)
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
891
5
eb15a5a9b026 Output validators can now award partial scores
Oleg Oshmyan <chortos@inbox.lv>
parents: 4
diff changeset
892 scoresumoveralltasks += actualpoints
0
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
893 scoremaxoveralltasks += taskweight
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
894 ntasks += 1
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
895 nfulltasks += int((score == maxpoints) if maxpoints else (taskweight == 0))
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
896
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
897 os.chdir(oldcwd)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
898
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
899 if options.clean or options.copyonly:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
900 sys.exit()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
901
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
902 if ntasks != 1:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
903 print
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
904 print 'Grand grand total: %g/%g weighted points; %d/%d problems solved fully' % (scoresumoveralltasks, scoremaxoveralltasks, nfulltasks, ntasks)
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
905
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
906 if options.pause:
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
907 print 'Press any key to exit... ',
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
908 sys.stdout.flush()
b9622c1e2197 Created the repository
Oleg Oshmyan <chortos@inbox.lv>
parents:
diff changeset
909 os.system(pause + ' >' + os.devnull)