From 0b6474d5c4abebd6ebe951acb120613a5b66ec50 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Fri, 23 Jun 2017 21:57:48 -0700 Subject: Avoid hardcoded names for temporary files in tests. These tests (and examples that are run as tests) were using hardcoded names for temporary files. This failed when multiple copies of these tests were run in parallel, or even successively by different users, where the second run could not overwrite files left by the first. This change uses the TEST_TMPDIR environment variable used by bazel's test runner to choose a temporary directory. If that directory is not set, /tmp is used, as before. PiperOrigin-RevId: 160026924 --- tensorflow/examples/tutorials/mnist/fully_connected_feed.py | 8 +++++--- tensorflow/examples/tutorials/mnist/mnist_with_summaries.py | 7 +++++-- tensorflow/python/training/saver_test.py | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'tensorflow') diff --git a/tensorflow/examples/tutorials/mnist/fully_connected_feed.py b/tensorflow/examples/tutorials/mnist/fully_connected_feed.py index be50f4529f..af89c8c77b 100644 --- a/tensorflow/examples/tutorials/mnist/fully_connected_feed.py +++ b/tensorflow/examples/tutorials/mnist/fully_connected_feed.py @@ -20,7 +20,7 @@ from __future__ import print_function # pylint: disable=missing-docstring import argparse -import os.path +import os import sys import time @@ -257,13 +257,15 @@ if __name__ == '__main__': parser.add_argument( '--input_data_dir', type=str, - default='/tmp/tensorflow/mnist/input_data', + default=os.path.join(os.getenv('TEST_TMPDIR', '/tmp'), + 'tensorflow/mnist/input_data'), help='Directory to put the input data.' ) parser.add_argument( '--log_dir', type=str, - default='/tmp/tensorflow/mnist/logs/fully_connected_feed', + default=os.path.join(os.getenv('TEST_TMPDIR', '/tmp'), + 'tensorflow/mnist/logs/fully_connected_feed'), help='Directory to put the log data.' ) parser.add_argument( diff --git a/tensorflow/examples/tutorials/mnist/mnist_with_summaries.py b/tensorflow/examples/tutorials/mnist/mnist_with_summaries.py index dc0d870315..c401d09df8 100644 --- a/tensorflow/examples/tutorials/mnist/mnist_with_summaries.py +++ b/tensorflow/examples/tutorials/mnist/mnist_with_summaries.py @@ -25,6 +25,7 @@ from __future__ import division from __future__ import print_function import argparse +import os import sys import tensorflow as tf @@ -200,12 +201,14 @@ if __name__ == '__main__': parser.add_argument( '--data_dir', type=str, - default='/tmp/tensorflow/mnist/input_data', + default=os.path.join(os.getenv('TEST_TMPDIR', '/tmp'), + 'tensorflow/mnist/input_data'), help='Directory for storing input data') parser.add_argument( '--log_dir', type=str, - default='/tmp/tensorflow/mnist/logs/mnist_with_summaries', + default=os.path.join(os.getenv('TEST_TMPDIR', '/tmp'), + 'tensorflow/mnist/logs/mnist_with_summaries'), help='Summaries log directory') FLAGS, unparsed = parser.parse_known_args() tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) diff --git a/tensorflow/python/training/saver_test.py b/tensorflow/python/training/saver_test.py index d17b7e93a1..f351efd843 100644 --- a/tensorflow/python/training/saver_test.py +++ b/tensorflow/python/training/saver_test.py @@ -1951,7 +1951,8 @@ class MetaGraphTest(test.TestCase): logits=logit) adam.AdamOptimizer().minimize(cost, name="optimize") meta_graph_def = saver_module.export_meta_graph(clear_devices=True) - graph_io.write_graph(meta_graph_def, "/tmp", "meta_graph.pbtxt") + graph_io.write_graph(meta_graph_def, self.get_temp_dir(), + "meta_graph.pbtxt") with session.Session(graph=ops_lib.Graph()) as sess: saver_module.import_meta_graph(meta_graph_def, import_scope="new_model") -- cgit v1.2.3