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_checkparameter.py 2.4 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Copyright 2020 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. """ test_checkparameter """
  16. import pytest
  17. from mindspore._checkparam import Validator, check_input_format, _expand_tuple
  18. once = _expand_tuple(1)
  19. twice = _expand_tuple(2)
  20. triple = _expand_tuple(3)
  21. kernel_size = 5
  22. kernel_size1 = twice(kernel_size)
  23. assert kernel_size1 == (5, 5)
  24. def test_check_int_1():
  25. assert Validator.check_is_int(3) == 3
  26. def check_int_positive_1():
  27. with pytest.raises(ValueError):
  28. Validator.check_positive_int(-1)
  29. def test_NCHW1():
  30. assert check_input_format("NCHW") == "NCHW"
  31. def test_NCHW3():
  32. with pytest.raises(ValueError):
  33. check_input_format("rt")
  34. def test_check_int_2():
  35. with pytest.raises(TypeError):
  36. Validator.check_is_int(3.3)
  37. def test_check_int_3():
  38. with pytest.raises(TypeError):
  39. Validator.check_is_int("str")
  40. def test_check_int_4():
  41. with pytest.raises(TypeError):
  42. Validator.check_is_int(True)
  43. def test_check_bool_1():
  44. assert Validator.check_bool(True)
  45. def test_check_bool_2():
  46. assert Validator.check_bool(False) is not True
  47. def test_check_bool_3():
  48. with pytest.raises(TypeError):
  49. Validator.check_bool("str")
  50. def test_check_bool_4():
  51. with pytest.raises(TypeError):
  52. Validator.check_bool(1)
  53. def test_check_bool_5():
  54. with pytest.raises(TypeError):
  55. Validator.check_bool(3.5)
  56. def test_twice_1():
  57. assert twice(3) == (3, 3)
  58. def test_twice_2():
  59. assert twice((3, 3)) == (3, 3)
  60. def test_twice_3():
  61. with pytest.raises(TypeError):
  62. twice(0.5)
  63. def test_twice_4():
  64. with pytest.raises(TypeError):
  65. twice("str")
  66. def test_twice_5():
  67. with pytest.raises(TypeError):
  68. twice((1, 2, 3))
  69. def test_twice_6():
  70. with pytest.raises(TypeError):
  71. twice((3.3, 4))