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

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