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