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.

test_storage.py 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. from util import save_and_check
  16. import mindspore.dataset as ds
  17. from mindspore import log as logger
  18. DATA_DIR = ["../data/dataset/testTFTestAllTypes/test.data"]
  19. SCHEMA_DIR = "../data/dataset/testTFTestAllTypes/datasetSchema.json"
  20. COLUMNS = ["col_1d", "col_2d", "col_3d", "col_binary", "col_float",
  21. "col_sint16", "col_sint32", "col_sint64"]
  22. GENERATE_GOLDEN = False
  23. def test_case_storage():
  24. """
  25. test StorageDataset
  26. """
  27. logger.info("Test Simple StorageDataset")
  28. # define parameters
  29. parameters = {"params": {}}
  30. # apply dataset operations
  31. data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, shuffle=False)
  32. filename = "storage_result.npz"
  33. save_and_check(data1, parameters, filename, generate_golden=GENERATE_GOLDEN)
  34. def test_case_no_rows():
  35. DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"]
  36. SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetNoRowsSchema.json"
  37. dataset = ds.StorageDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"])
  38. assert dataset.get_dataset_size() == 3
  39. count = 0
  40. for data in dataset.create_tuple_iterator():
  41. count += 1
  42. assert count == 3