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/core/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. .SetRowsPerBuffer(2)
  53. .SetWorkerConnectorSize(16)
  54. .SetNumWorkers(1)
  55. .Build(&my_tfreader_op);
  56. EXPECT_TRUE(rc.IsOk());
  57. rc = my_tree->AssociateNode(my_tfreader_op);
  58. EXPECT_TRUE(rc.IsOk());
  59. // Creating DatasetOp
  60. std::vector<std::string> in_colnames = {"label"};
  61. std::vector<std::string> out_colnames = {"label1"};
  62. std::shared_ptr<RenameOp> rename_op;
  63. rc = RenameOp::Builder()
  64. .SetInColNames(in_colnames)
  65. .SetOutColNames(out_colnames)
  66. .Build(&rename_op);
  67. EXPECT_TRUE(rc.IsOk());
  68. rc = my_tree->AssociateNode(rename_op);
  69. EXPECT_TRUE(rc.IsOk());
  70. rc = rename_op->AddChild(std::move(my_tfreader_op));
  71. EXPECT_TRUE(rc.IsOk());
  72. rc = my_tree->AssignRoot(rename_op);
  73. EXPECT_TRUE(rc.IsOk());
  74. rc = my_tree->Prepare();
  75. EXPECT_TRUE(rc.IsOk());
  76. // Launch the tree execution to kick off threads and start running the pipeline
  77. MS_LOG(INFO) << "Launching my tree.";
  78. rc = my_tree->Launch();
  79. EXPECT_TRUE(rc.IsOk());
  80. // Simulate a parse of data from our pipeline.
  81. std::shared_ptr<DatasetOp> root_node = my_tree->root();
  82. DatasetIterator di(my_tree);
  83. TensorRow tensor_list;
  84. rc = di.FetchNextTensorRow(&tensor_list);
  85. EXPECT_TRUE(rc.IsOk());
  86. int row_count = 0;
  87. while (!tensor_list.empty()) {
  88. MS_LOG(INFO) << "Row display for row #: " << row_count << ".";
  89. // Display the tensor by calling the printer on it
  90. for (int i = 0; i < tensor_list.size(); i++) {
  91. std::ostringstream ss;
  92. ss << "(" << tensor_list[i] << "): " << *tensor_list[i] << std::endl;
  93. MS_LOG(INFO) << "Tensor print: " << ss.str() << ".";
  94. }
  95. rc = di.FetchNextTensorRow(&tensor_list);
  96. EXPECT_TRUE(rc.IsOk());
  97. row_count++;
  98. }
  99. ASSERT_EQ(row_count, 3); // Should be 3 rows fetched
  100. }