提交 586ce4b9 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

In pickling test, work in a temporary directory that gets removed at the end.

上级 e4c6880e
""" test code snippet in the Theano tutorials. """ test code snippet in the Theano tutorials.
""" """
import os, unittest import os, shutil, unittest
import theano import theano
import theano.tensor as T import theano.tensor as T
from theano import function from theano import function
...@@ -705,7 +705,7 @@ class T_aliasing(unittest.TestCase): ...@@ -705,7 +705,7 @@ class T_aliasing(unittest.TestCase):
class T_loading_and_saving(unittest.TestCase): class T_loading_and_saving(unittest.TestCase):
## All tests here belog to ## All tests here belong to
## http://deeplearning.net/software/theano/tutorial/loading_and_saving.html ## http://deeplearning.net/software/theano/tutorial/loading_and_saving.html
## Theano/doc/tutorial/loading_and_saving.txt ## Theano/doc/tutorial/loading_and_saving.txt
## Any change you do here also add it to the tutorial ! ## Any change you do here also add it to the tutorial !
...@@ -722,14 +722,14 @@ class T_loading_and_saving(unittest.TestCase): ...@@ -722,14 +722,14 @@ class T_loading_and_saving(unittest.TestCase):
mode_instance = theano.compile.mode.get_mode(None) mode_instance = theano.compile.mode.get_mode(None)
if not isinstance(mode_instance, theano.compile.debugmode.DebugMode): if not isinstance(mode_instance, theano.compile.debugmode.DebugMode):
if os.path.exists('obj.save') or os.path.exists('objects.save'): # Here, we work in a temporary directory in order not to clutter
# We do not want to delete these files silently, in case for # the Theano repository. Code relative to creating that dir and
# some reason they would be something else than test-generated # removing it afterwards should _not_ be backported to the tutorial.
# files. from tempfile import mkdtemp
# Ideally we would save those files in a temporary directory... tmpdir = mkdtemp()
raise AssertionError( origdir = os.getcwd()
'Please get rid of files obj.save and ' try:
'objects.save in directory %s' % os.getcwd()) os.chdir(tmpdir)
f = file('obj.save', 'wb') f = file('obj.save', 'wb')
cPickle.dump(my_obj, f, protocol=cPickle.HIGHEST_PROTOCOL) cPickle.dump(my_obj, f, protocol=cPickle.HIGHEST_PROTOCOL)
...@@ -754,10 +754,10 @@ class T_loading_and_saving(unittest.TestCase): ...@@ -754,10 +754,10 @@ class T_loading_and_saving(unittest.TestCase):
for i in range(3): for i in range(3):
loaded_objects.append(cPickle.load(f)) loaded_objects.append(cPickle.load(f))
f.close() f.close()
finally:
# Cleanup created files. # Get back to the orinal dir, and temporary one.
os.remove('obj.save') os.chdir(origdir)
os.remove('objects.save') shutil.rmtree(tmpdir)
class T_modes(unittest.TestCase): class T_modes(unittest.TestCase):
## All tests here belog to ## All tests here belog to
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论