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.5 kB

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