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.

rename_op_test.cc 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Copyright 2019 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 <cstring>
  17. #include <iostream>
  18. #include <memory>
  19. #include <string>
  20. #include "minddata/dataset/core/client.h"
  21. #include "minddata/dataset/include/constants.h"
  22. #include "minddata/dataset/engine/datasetops/rename_op.h"
  23. #include "common/common.h"
  24. #include "utils/ms_utils.h"
  25. #include "minddata/dataset/engine/data_buffer.h"
  26. #include "gtest/gtest.h"
  27. #include "minddata/dataset/core/global_context.h"
  28. #include "utils/log_adapter.h"
  29. namespace common = mindspore::common;
  30. using namespace mindspore::dataset;
  31. using mindspore::MsLogLevel::INFO;
  32. using mindspore::ExceptionType::NoExceptionType;
  33. using mindspore::LogStream;
  34. class MindDataTestRenameOp : public UT::DatasetOpTesting {
  35. };
  36. TEST_F(MindDataTestRenameOp, TestRenameOpDefault) {
  37. // Tree:
  38. //
  39. //
  40. // OpId(2) RenameOp
  41. // |
  42. // OpId(0) TFReaderOp
  43. // Start with an empty execution tree
  44. Status rc;
  45. MS_LOG(INFO) << "UT test TestRenameBasic.";
  46. auto my_tree = std::make_shared<ExecutionTree>();
  47. // Creating TFReaderOp
  48. std::string dataset_path = datasets_root_path_ + "/test_tf_file_3_images/train-0000-of-0001.data";
  49. std::shared_ptr<TFReaderOp> my_tfreader_op;
  50. rc = TFReaderOp::Builder()
  51. .SetDatasetFilesList({dataset_path})
  52. .SetWorkerConnectorSize(16)
  53. .SetNumWorkers(1)
  54. .Build(&my_tfreader_op);
  55. EXPECT_TRUE(rc.IsOk());
  56. rc = my_tree->AssociateNode(my_tfreader_op);
  57. EXPECT_TRUE(rc.IsOk());
  58. // Creating DatasetOp
  59. std::vector<std::string> in_colnames = {"label"};
  60. std::vector<std::string> out_colnames = {"label1"};
  61. std::shared_ptr<RenameOp> rename_op;
  62. rc = RenameOp::Builder()
  63. .SetInColNames(in_colnames)
  64. .SetOutColNames(out_colnames)
  65. .Build(&rename_op);
  66. EXPECT_TRUE(rc.IsOk());
  67. rc = my_tree->AssociateNode(rename_op);
  68. EXPECT_TRUE(rc.IsOk());
  69. rc = rename_op->AddChild(std::move(my_tfreader_op));
  70. EXPECT_TRUE(rc.IsOk());
  71. rc = my_tree->AssignRoot(rename_op);
  72. EXPECT_TRUE(rc.IsOk());
  73. rc = my_tree->Prepare();
  74. EXPECT_TRUE(rc.IsOk());
  75. // Launch the tree execution to kick off threads and start running the pipeline
  76. MS_LOG(INFO) << "Launching my tree.";
  77. rc = my_tree->Launch();
  78. EXPECT_TRUE(rc.IsOk());
  79. // Simulate a parse of data from our pipeline.
  80. std::shared_ptr<DatasetOp> root_node = my_tree->root();
  81. DatasetIterator di(my_tree);
  82. TensorRow tensor_list;
  83. rc = di.FetchNextTensorRow(&tensor_list);
  84. EXPECT_TRUE(rc.IsOk());
  85. int row_count = 0;
  86. while (!tensor_list.empty()) {
  87. MS_LOG(INFO) << "Row display for row #: " << row_count << ".";
  88. // Display the tensor by calling the printer on it
  89. for (int i = 0; i < tensor_list.size(); i++) {
  90. std::ostringstream ss;
  91. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  92. MS_LOG(INFO) << "Tensor print: " << ss.str() << ".";
  93. }
  94. rc = di.FetchNextTensorRow(&tensor_list);
  95. EXPECT_TRUE(rc.IsOk());
  96. row_count++;
  97. }
  98. ASSERT_EQ(row_count, 3); // Should be 3 rows fetched
  99. }