提交 54b194d5 authored 作者: Piotr Frankowski's avatar Piotr Frankowski

#3429 - python 'with' statement in tests module

上级 218094ba
...@@ -265,99 +265,101 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile, ...@@ -265,99 +265,101 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile,
fields = ('Fields: computation time; nosetests sequential id;' fields = ('Fields: computation time; nosetests sequential id;'
' test name; parent class (if any); outcome\n\n') ' test name; parent class (if any); outcome\n\n')
path_nosort = os.path.join(sav_dir, 'timeprof_nosort') path_nosort = os.path.join(sav_dir, 'timeprof_nosort')
f_nosort = open(path_nosort, 'w') # probably this part can be extracted for function with many args
f_nosort.write('TIME-PROFILING OF THEANO\'S NOSETESTS' with open(path_nosort, 'w') as f_nosort:
' (by sequential id)\n\n' + stamp + fields) # begin of saving nosort
f_nosort.flush() f_nosort.write('TIME-PROFILING OF THEANO\'S NOSETESTS'
for test_floor in xrange(1, n_tests + 1, batch_size): ' (by sequential id)\n\n' + stamp + fields)
for test_id in xrange(test_floor, min(test_floor + batch_size, f_nosort.flush()
n_tests + 1)): for test_floor in xrange(1, n_tests + 1, batch_size):
# Print the test we will start in the raw log to help for test_id in xrange(test_floor, min(test_floor + batch_size,
# debug tests that are too long. n_tests + 1)):
f_rawlog.write("\n%s Will run test #%d %s\n" % ( # Print the test we will start in the raw log to help
time.ctime(), test_id, data["ids"][test_id])) # debug tests that are too long.
f_rawlog.flush() f_rawlog.write("\n%s Will run test #%d %s\n" % (
time.ctime(), test_id, data["ids"][test_id]))
p_out = output_subprocess_Popen( f_rawlog.flush()
([python, theano_nose, '-v', '--with-id']
+ [str(test_id)] + argv + p_out = output_subprocess_Popen(
['--disabdocstring'])) ([python, theano_nose, '-v', '--with-id']
# the previous option calls a custom Nosetests plugin + [str(test_id)] + argv +
# precluding automatic sustitution of doc. string for ['--disabdocstring']))
# test name in display # the previous option calls a custom Nosetests plugin
# (see class 'DisabDocString' in file theano-nose) # precluding automatic sustitution of doc. string for
# test name in display
# recovering and processing data from pipe # (see class 'DisabDocString' in file theano-nose)
err = p_out[1]
# print the raw log # recovering and processing data from pipe
f_rawlog.write(err) err = p_out[1]
f_rawlog.flush() # print the raw log
f_rawlog.write(err)
# parsing the output f_rawlog.flush()
l_err = err.split()
try: # parsing the output
pos_id = getIndexOfFirst(l_err, '#') l_err = err.split()
prof_id = l_err[pos_id] try:
pos_dot = getIndexOfFirst(l_err, '...') pos_id = getIndexOfFirst(l_err, '#')
prof_test = '' prof_id = l_err[pos_id]
for s in l_err[pos_id + 1: pos_dot]: pos_dot = getIndexOfFirst(l_err, '...')
prof_test += s + ' ' prof_test = ''
if 'OK' in err: for s in l_err[pos_id + 1: pos_dot]:
pos_ok = getIndexOfLast(l_err, 'OK') prof_test += s + ' '
if len(l_err) == pos_ok + 1: if 'OK' in err:
prof_time = float(l_err[pos_ok - 1][0:-1]) pos_ok = getIndexOfLast(l_err, 'OK')
prof_pass = 'OK' if len(l_err) == pos_ok + 1:
elif 'SKIP' in l_err[pos_ok + 1]: prof_time = float(l_err[pos_ok - 1][0:-1])
prof_time = 0. prof_pass = 'OK'
prof_pass = 'SKIPPED TEST' elif 'SKIP' in l_err[pos_ok + 1]:
elif 'KNOWNFAIL' in l_err[pos_ok + 1]: prof_time = 0.
prof_time = float(l_err[pos_ok - 1][0:-1]) prof_pass = 'SKIPPED TEST'
prof_pass = 'OK' elif 'KNOWNFAIL' in l_err[pos_ok + 1]:
prof_time = float(l_err[pos_ok - 1][0:-1])
prof_pass = 'OK'
else:
prof_time = 0.
prof_pass = 'FAILED TEST'
else: else:
prof_time = 0. prof_time = 0.
prof_pass = 'FAILED TEST' prof_pass = 'FAILED TEST'
else: except Exception:
prof_time = 0. prof_time = 0
prof_pass = 'FAILED TEST' prof_id = '#' + str(test_id)
except Exception: prof_test = ('FAILED PARSING, see raw log for details'
prof_time = 0 ' on test')
prof_id = '#' + str(test_id) prof_pass = ''
prof_test = ('FAILED PARSING, see raw log for details' prof_tuple = (prof_time, prof_id, prof_test, prof_pass)
' on test')
prof_pass = '' # appending tuple to master list
prof_tuple = (prof_time, prof_id, prof_test, prof_pass) prof_master_nosort.append(prof_tuple)
# appending tuple to master list # write the no sort file
prof_master_nosort.append(prof_tuple) s_nosort = ((str(prof_tuple[0]) + 's').ljust(10) +
" " + prof_tuple[1].ljust(7) + " " +
# write the no sort file prof_tuple[2] + prof_tuple[3] +
s_nosort = ((str(prof_tuple[0]) + 's').ljust(10) + "\n")
" " + prof_tuple[1].ljust(7) + " " + f_nosort.write(s_nosort)
prof_tuple[2] + prof_tuple[3] + f_nosort.flush()
"\n")
f_nosort.write(s_nosort) print('%s%% time-profiled' % ((test_id * 100) // n_tests))
f_nosort.flush() f_rawlog.close()
print('%s%% time-profiled' % ((test_id * 100) // n_tests)) # sorting tests according to running-time
f_rawlog.close() prof_master_sort = sorted(prof_master_nosort,
key=lambda test: test[0], reverse=True)
# sorting tests according to running-time
prof_master_sort = sorted(prof_master_nosort, # saving results to readable files
key=lambda test: test[0], reverse=True) path_sort = os.path.join(sav_dir, 'timeprof_sort')
with open(path_sort, 'w') as f_sort:
# saving results to readable files f_sort.write('TIME-PROFILING OF THEANO\'S NOSETESTS'
path_sort = os.path.join(sav_dir, 'timeprof_sort') ' (sorted by computation time)\n\n' + stamp + fields)
f_sort = open(path_sort, 'w') for i in xrange(len(prof_master_nosort)):
f_sort.write('TIME-PROFILING OF THEANO\'S NOSETESTS' s_sort = ((str(prof_master_sort[i][0]) + 's').ljust(10) +
' (sorted by computation time)\n\n' + stamp + fields) " " + prof_master_sort[i][1].ljust(7) + " " +
for i in xrange(len(prof_master_nosort)): prof_master_sort[i][2] + prof_master_sort[i][3] +
s_sort = ((str(prof_master_sort[i][0]) + 's').ljust(10) + "\n")
" " + prof_master_sort[i][1].ljust(7) + " " + f_sort.write(s_sort)
prof_master_sort[i][2] + prof_master_sort[i][3] +
"\n") # end of saving nosort
f_sort.write(s_sort)
f_nosort.close()
f_sort.close()
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())
...@@ -275,17 +275,16 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'): ...@@ -275,17 +275,16 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'):
the "whitelist_flake8" in this file. the "whitelist_flake8" in this file.
""" """
f_txt = open('theano_filelist.txt', 'a') with open('theano_filelist.txt', 'a') as f_txt:
for (dir, _, files) in os.walk(dir_path): for (dir, _, files) in os.walk(dir_path):
for f in files: for f in files:
if fnmatch(f, pattern): if fnmatch(f, pattern):
error_num = flake8.main.check_file(os.path.join(dir, f), error_num = flake8.main.check_file(os.path.join(dir, f),
ignore=ignore) ignore=ignore)
if error_num > 0: if error_num > 0:
path = os.path.relpath(os.path.join(dir, f), path = os.path.relpath(os.path.join(dir, f),
theano.__path__[0]) theano.__path__[0])
f_txt.write('"' + path + '",\n') f_txt.write('"' + path + '",\n')
f_txt.close()
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论