• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 """
16import pytest
17
18from mindspore._checkparam import Validator, check_input_format, _expand_tuple
19
20once = _expand_tuple(1)
21twice = _expand_tuple(2)
22triple = _expand_tuple(3)
23kernel_size = 5
24kernel_size1 = twice(kernel_size)
25assert kernel_size1 == (5, 5)
26
27
28def test_check_int_1():
29    assert Validator.check_is_int(3) == 3
30
31
32def check_int_positive_1():
33    with pytest.raises(ValueError):
34        Validator.check_positive_int(-1)
35
36
37def test_NCHW1():
38    assert check_input_format("NCHW") == "NCHW"
39
40
41def test_NCHW3():
42    with pytest.raises(ValueError):
43        check_input_format("rt")
44
45
46def test_check_int_2():
47    with pytest.raises(TypeError):
48        Validator.check_is_int(3.3)
49
50
51def test_check_int_3():
52    with pytest.raises(TypeError):
53        Validator.check_is_int("str")
54
55
56def test_check_int_4():
57    with pytest.raises(TypeError):
58        Validator.check_is_int(True)
59
60
61def test_check_bool_1():
62    assert Validator.check_bool(True)
63
64
65def test_check_bool_2():
66    assert Validator.check_bool(False) is not True
67
68
69def test_check_bool_3():
70    with pytest.raises(TypeError):
71        Validator.check_bool("str")
72
73
74def test_check_bool_4():
75    with pytest.raises(TypeError):
76        Validator.check_bool(1)
77
78
79def test_check_bool_5():
80    with pytest.raises(TypeError):
81        Validator.check_bool(3.5)
82
83
84def test_twice_1():
85    assert twice(3) == (3, 3)
86
87
88def test_twice_2():
89    assert twice((3, 3)) == (3, 3)
90
91
92def test_twice_3():
93    with pytest.raises(TypeError):
94        twice(0.5)
95
96
97def test_twice_4():
98    with pytest.raises(TypeError):
99        twice("str")
100
101
102def test_twice_5():
103    with pytest.raises(TypeError):
104        twice((1, 2, 3))
105
106
107def test_twice_6():
108    with pytest.raises(TypeError):
109        twice((3.3, 4))
110