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_autotune_config.py 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright 2022 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. """
  16. Test Dataset AutoTune Configuration Support
  17. """
  18. import pytest
  19. import mindspore.dataset as ds
  20. @pytest.mark.forked
  21. class TestAutotuneConfig:
  22. @staticmethod
  23. def test_autotune_config_basic():
  24. """
  25. Feature: Autotuning
  26. Description: Test basic config of AutoTune
  27. Expectation: Config can be set successfully
  28. """
  29. autotune_state = ds.config.get_enable_autotune()
  30. assert autotune_state is False
  31. ds.config.set_enable_autotune(False)
  32. autotune_state = ds.config.get_enable_autotune()
  33. assert autotune_state is False
  34. with pytest.raises(TypeError):
  35. ds.config.set_enable_autotune(1)
  36. autotune_interval = ds.config.get_autotune_interval()
  37. assert autotune_interval == 0
  38. ds.config.set_autotune_interval(200)
  39. autotune_interval = ds.config.get_autotune_interval()
  40. assert autotune_interval == 200
  41. with pytest.raises(TypeError):
  42. ds.config.set_autotune_interval(20.012)
  43. with pytest.raises(ValueError):
  44. ds.config.set_autotune_interval(-999)
  45. @staticmethod
  46. def test_autotune_config_filepath_invalid():
  47. """
  48. Feature: Autotuning
  49. Description: Test set_enable_autotune() with invalid json_filepath
  50. Expectation: Invalid input is detected
  51. """
  52. with pytest.raises(TypeError):
  53. ds.config.set_enable_autotune(True, 123)
  54. with pytest.raises(TypeError):
  55. ds.config.set_enable_autotune(True, 0)
  56. with pytest.raises(TypeError):
  57. ds.config.set_enable_autotune(True, True)
  58. with pytest.raises(TypeError):
  59. ds.config.set_enable_autotune(False, 1.1)
  60. with pytest.raises(RuntimeError) as error_info:
  61. ds.config.set_enable_autotune(True, "")
  62. assert "cannot be the empty string" in str(error_info.value)
  63. with pytest.raises(RuntimeError) as error_info:
  64. ds.config.set_enable_autotune(True, "/tmp")
  65. assert "is a directory" in str(error_info.value)
  66. with pytest.raises(RuntimeError) as error_info:
  67. ds.config.set_enable_autotune(True, ".")
  68. assert "is a directory" in str(error_info.value)
  69. with pytest.raises(RuntimeError) as error_info:
  70. ds.config.set_enable_autotune(True, "/JUNKPATH/at_out.json")
  71. assert "Directory" in str(error_info.value)
  72. assert "does not exist" in str(error_info.value)
  73. @staticmethod
  74. def test_autotune_config_filepath_success():
  75. """
  76. Feature: Autotuning
  77. Description: Test set_enable_autotune() with valid filepath input
  78. Expectation: set_enable_autotune() executes successfully
  79. """
  80. # Note: No problem to have sequential calls to set_enable_autotune()
  81. ds.config.set_enable_autotune(True, "file1.json")
  82. ds.config.set_enable_autotune(True, "file1.json")
  83. ds.config.set_enable_autotune(True, "file2.json")
  84. # Note: It is permissible to not have preferred '.json' extension for json_filepath
  85. ds.config.set_enable_autotune(True, "at_out.JSON")
  86. ds.config.set_enable_autotune(True, "/tmp/at_out.txt")
  87. ds.config.set_enable_autotune(True, "at_out")
  88. # Note: When enable is false, the json_filepath parameter is ignored
  89. ds.config.set_enable_autotune(False, "/NONEXISTDIR/junk.json")
  90. ds.config.set_enable_autotune(False, "")
  91. ds.config.set_enable_autotune(False, None)