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

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