annotate 1.20/test.py @ 20:5bfa23cd638d

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