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

#3429 - python 'with' statement in tests module

上级 218094ba
...@@ -265,7 +265,9 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile, ...@@ -265,7 +265,9 @@ 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
with open(path_nosort, 'w') as f_nosort:
# begin of saving nosort
f_nosort.write('TIME-PROFILING OF THEANO\'S NOSETESTS' f_nosort.write('TIME-PROFILING OF THEANO\'S NOSETESTS'
' (by sequential id)\n\n' + stamp + fields) ' (by sequential id)\n\n' + stamp + fields)
f_nosort.flush() f_nosort.flush()
...@@ -347,7 +349,7 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile, ...@@ -347,7 +349,7 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile,
# saving results to readable files # saving results to readable files
path_sort = os.path.join(sav_dir, 'timeprof_sort') path_sort = os.path.join(sav_dir, 'timeprof_sort')
f_sort = open(path_sort, 'w') with open(path_sort, 'w') as f_sort:
f_sort.write('TIME-PROFILING OF THEANO\'S NOSETESTS' f_sort.write('TIME-PROFILING OF THEANO\'S NOSETESTS'
' (sorted by computation time)\n\n' + stamp + fields) ' (sorted by computation time)\n\n' + stamp + fields)
for i in xrange(len(prof_master_nosort)): for i in xrange(len(prof_master_nosort)):
...@@ -356,8 +358,8 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile, ...@@ -356,8 +358,8 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile,
prof_master_sort[i][2] + prof_master_sort[i][3] + prof_master_sort[i][2] + prof_master_sort[i][3] +
"\n") "\n")
f_sort.write(s_sort) f_sort.write(s_sort)
f_nosort.close()
f_sort.close() # end of saving nosort
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())
...@@ -275,7 +275,7 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'): ...@@ -275,7 +275,7 @@ 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):
...@@ -285,7 +285,6 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'): ...@@ -285,7 +285,6 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'):
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论