You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

schema_test.cc 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <fstream>
  17. #include <iostream>
  18. #include <memory>
  19. #include <string>
  20. #include "common/common.h"
  21. #include "utils/ms_utils.h"
  22. #include "minddata/dataset/core/client.h"
  23. #include "minddata/dataset/core/global_context.h"
  24. #include "minddata/dataset/engine/data_schema.h"
  25. #include "minddata/dataset/util/path.h"
  26. #include "minddata/dataset/util/status.h"
  27. #include "gtest/gtest.h"
  28. #include "utils/log_adapter.h"
  29. #include "securec.h"
  30. namespace common = mindspore::common;
  31. using namespace mindspore::dataset;
  32. using mindspore::MsLogLevel::ERROR;
  33. using mindspore::ExceptionType::NoExceptionType;
  34. using mindspore::LogStream;
  35. class MindDataTestSchema : public UT::DatasetOpTesting {
  36. protected:
  37. };
  38. TEST_F(MindDataTestSchema, TestOldSchema) {
  39. std::string schema_file = datasets_root_path_ + "/testDataset2/datasetSchema.json";
  40. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  41. Status rc = schema->LoadSchemaFile(schema_file, {});
  42. if (rc.IsError()) {
  43. MS_LOG(ERROR) << "Return code error detected during schema load: " << common::SafeCStr(rc.ToString()) << ".";
  44. EXPECT_TRUE(false);
  45. } else {
  46. int32_t num_cols = schema->NumColumns();
  47. EXPECT_TRUE(num_cols == 4);
  48. }
  49. }
  50. TEST_F(MindDataTestSchema, TestAlbumSchema) {
  51. std::string schema_file = datasets_root_path_ + "/testAlbum/fullSchema.json";
  52. std::unique_ptr<DataSchema> schema = std::make_unique<DataSchema>();
  53. Status rc = schema->LoadSchemaFile(schema_file, {});
  54. if (rc.IsError()) {
  55. MS_LOG(ERROR) << "Return code error detected during schema load: " << common::SafeCStr(rc.ToString()) << ".";
  56. EXPECT_TRUE(false);
  57. } else {
  58. int32_t num_cols = schema->NumColumns();
  59. MS_LOG(INFO) << "num_cols: " << num_cols << ".";
  60. EXPECT_TRUE(num_cols == 7);
  61. }
  62. }