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

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