Make use of GetDataDependencyFilepath and io::JoinPath to be operating system independent.

PiperOrigin-RevId: 295016334
Change-Id: I613b75f859d1822fbec4a0b3880635531463c207
This commit is contained in:
Brian Atkinson 2020-02-13 15:37:11 -08:00 committed by TensorFlower Gardener
parent 3d5d9b37b7
commit 62adf994a6
2 changed files with 17 additions and 7 deletions
tensorflow/core/api_def

View File

@ -113,5 +113,6 @@ tf_cc_test(
"//tensorflow/core:protos_all_cc",
"//tensorflow/core:test",
"//tensorflow/core:test_main",
"//tensorflow/core/platform:resource_loader",
],
)

View File

@ -16,6 +16,7 @@ limitations under the License.
// Test that validates tensorflow/core/api_def/base_api/api_def*.pbtxt files.
#include <ctype.h>
#include <algorithm>
#include <string>
#include <unordered_map>
@ -33,17 +34,25 @@ limitations under the License.
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/init_main.h"
#include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/platform/resource_loader.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/types.h"
namespace tensorflow {
namespace {
constexpr char kDefaultApiDefDir[] =
"tensorflow/core/api_def/base_api";
constexpr char kPythonApiDefDir[] =
"tensorflow/core/api_def/python_api";
constexpr char kApiDefFilePattern[] = "api_def_*.pbtxt";
string DefaultApiDefDir() {
return GetDataDependencyFilepath(
io::JoinPath("tensorflow", "core", "api_def", "base_api"));
}
string PythonApiDefDir() {
return GetDataDependencyFilepath(
io::JoinPath("tensorflow", "core", "api_def", "python_api"));
}
// Reads golden ApiDef files and returns a map from file name to ApiDef file
// contents.
void GetGoldenApiDefs(Env* env, const string& api_files_dir,
@ -191,7 +200,6 @@ void TestDeprecationVersionSetCorrectly(
}
}
}
} // namespace
class BaseApiTest : public ::testing::Test {
protected:
@ -200,7 +208,7 @@ class BaseApiTest : public ::testing::Test {
const std::vector<string> multi_line_fields = {"description"};
Env* env = Env::Default();
GetGoldenApiDefs(env, kDefaultApiDefDir, &api_defs_map_);
GetGoldenApiDefs(env, DefaultApiDefDir(), &api_defs_map_);
}
OpList ops_;
std::unordered_map<string, ApiDef> api_defs_map_;
@ -296,7 +304,7 @@ class PythonApiTest : public ::testing::Test {
const std::vector<string> multi_line_fields = {"description"};
Env* env = Env::Default();
GetGoldenApiDefs(env, kPythonApiDefDir, &api_defs_map_);
GetGoldenApiDefs(env, PythonApiDefDir(), &api_defs_map_);
}
OpList ops_;
std::unordered_map<string, ApiDef> api_defs_map_;
@ -336,4 +344,5 @@ TEST_F(PythonApiTest, DeprecationVersionSetCorrectly) {
TestDeprecationVersionSetCorrectly(api_defs_map_);
}
} // namespace
} // namespace tensorflow