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: 296239768 Change-Id: Ie1c44de9f4a0b31100ec66979152c39a5e2a965f
This commit is contained in:
parent
20e980d900
commit
49333f5489
@ -19,6 +19,12 @@ namespace {
|
||||
|
||||
constexpr char kNodeName[] = "text_line_dataset";
|
||||
|
||||
tstring LocalTempFilename() {
|
||||
std::string path;
|
||||
CHECK(Env::Default()->LocalTempFilename(&path));
|
||||
return tstring(path);
|
||||
}
|
||||
|
||||
class TextLineDatasetParams : public DatasetParams {
|
||||
public:
|
||||
TextLineDatasetParams(std::vector<tstring> filenames,
|
||||
@ -84,9 +90,7 @@ Status CreateTestFiles(const std::vector<tstring>& filenames,
|
||||
|
||||
// Test case 1: multiple text files with ZLIB compression.
|
||||
TextLineDatasetParams TextLineDatasetParams1() {
|
||||
std::vector<tstring> filenames = {
|
||||
absl::StrCat(testing::TmpDir(), "/text_line_ZLIB_1"),
|
||||
absl::StrCat(testing::TmpDir(), "/text_line_ZLIB_2")};
|
||||
std::vector<tstring> filenames = {LocalTempFilename(), LocalTempFilename()};
|
||||
std::vector<tstring> contents = {
|
||||
absl::StrCat("hello world\n", "11223334455\n"),
|
||||
absl::StrCat("abcd, EFgH\n", " \n", "$%^&*()\n")};
|
||||
@ -103,9 +107,7 @@ TextLineDatasetParams TextLineDatasetParams1() {
|
||||
|
||||
// Test case 2: multiple text files with GZIP compression.
|
||||
TextLineDatasetParams TextLineDatasetParams2() {
|
||||
std::vector<tstring> filenames = {
|
||||
absl::StrCat(testing::TmpDir(), "/text_line_GZIP_1"),
|
||||
absl::StrCat(testing::TmpDir(), "/text_line_GZIP_2")};
|
||||
std::vector<tstring> filenames = {LocalTempFilename(), LocalTempFilename()};
|
||||
std::vector<tstring> contents = {
|
||||
absl::StrCat("hello world\n", "11223334455\n"),
|
||||
absl::StrCat("abcd, EFgH\n", " \n", "$%^&*()\n")};
|
||||
@ -122,9 +124,7 @@ TextLineDatasetParams TextLineDatasetParams2() {
|
||||
|
||||
// Test case 3: multiple text files without compression.
|
||||
TextLineDatasetParams TextLineDatasetParams3() {
|
||||
std::vector<tstring> filenames = {
|
||||
absl::StrCat(testing::TmpDir(), "/text_line_UNCOMPRESSED_1"),
|
||||
absl::StrCat(testing::TmpDir(), "/text_line_UNCOMPRESSED_2")};
|
||||
std::vector<tstring> filenames = {LocalTempFilename(), LocalTempFilename()};
|
||||
std::vector<tstring> contents = {
|
||||
absl::StrCat("hello world\n", "11223334455\n"),
|
||||
absl::StrCat("abcd, EFgH\n", " \n", "$%^&*()\n")};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user