Use Env::LocalTempFilename for a temp filename.

This function works both in and outside of tests. Additionally,
LocalTempFilename works well on Windows where as TmpDir is a little problematic
because of bazel oddities.

PiperOrigin-RevId: 296093672
Change-Id: I998ac9dab0077d7cfc09631db4bf295f4eef155a
This commit is contained in:
Brian Atkinson 2020-02-19 17:16:52 -08:00 committed by TensorFlower Gardener
parent 37d4d0484c
commit 10568a537f
2 changed files with 6 additions and 4 deletions
tensorflow/compiler/xla

View File

@ -722,6 +722,7 @@ tf_cc_test(
":text_literal_writer",
":types",
"//tensorflow/core:lib",
"//tensorflow/core:test",
"//tensorflow/core:test_main",
],
)

View File

@ -23,6 +23,7 @@ limitations under the License.
#include "tensorflow/compiler/xla/test.h"
#include "tensorflow/compiler/xla/test_helpers.h"
#include "tensorflow/compiler/xla/types.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/io/path.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/logging.h"
@ -35,12 +36,12 @@ TEST(TextLiteralWriterTest, WritesFloatLiteral) {
{3.14, 2.17},
{1.23, 4.56},
});
string path =
tensorflow::io::JoinPath(tensorflow::testing::TmpDir(), "/whatever");
string path;
ASSERT_TRUE(tensorflow::Env::Default()->LocalTempFilename(&path));
ASSERT_IS_OK(TextLiteralWriter::WriteToPath(literal, path));
string contents;
TF_CHECK_OK(tensorflow::ReadFileToString(tensorflow::Env::Default(), path,
&contents));
TF_ASSERT_OK(tensorflow::ReadFileToString(tensorflow::Env::Default(), path,
&contents));
const string expected = R"(f32[2,2]
(0, 0): 3.14
(0, 1): 2.17