annotate test-svn.py @ 14:28b1f4853968

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