diff --git a/.jenkins/check/config/filter_pylint.txt b/.jenkins/check/config/filter_pylint.txt index 68aff172674..fe671a8f5b0 100644 --- a/.jenkins/check/config/filter_pylint.txt +++ b/.jenkins/check/config/filter_pylint.txt @@ -123,7 +123,6 @@ "mindspore/tests/ut/python/parallel/" "protected-access" "mindspore/tests/ut/python/parameter_feature/test_var_grad.py" "bad-super-call" "mindspore/tests/ut/python/parameter_feature/test_var_grad.py" "redefined-outer-name" -"mindspore/tests/ut/python/pipeline/parse/test_cont_break.py" "unused-variable" "mindspore/tests/ut/python/pynative_mode" "no-else-return" "mindspore/tests/ut/python/pynative_mode" "superfluous-parens" "mindspore/tests/ut/python/pynative_mode" "unused-variable" @@ -133,17 +132,20 @@ "mindspore/tests/ut/python/rewrite/test_node.py" "syntax-error" "mindspore/tests/ut/python/rewrite/test_node.py" "protected-access" "mindspore/tests/ut/python/rewrite/test_for.py" "protected-access" -"mindspore/tests/ut/python/python_builtin/test_list_tuple.py" "len-as-condition" "mindspore/tests/ut/python/rewrite/test_symbol_tree.py" "len-as-condition" "mindspore/tests/ut/python/rewrite/test_lenet.py" "protected-access" "mindspore/tests/ut/python/rewrite/test_if.py" "protected-access" "mindspore/tests/ut/python/test_log.py" "possibly-unused-variable" "mindspore/tests/ut/python/test_log.py" "protected-access" "mindspore/tests/ut/python/train/summary/test_summary_collector.py" "protected-access" -"mindspore/tests/ut/python/pipeline/parse/test_super.py" "bad-super-call" -"mindspore/tests/ut/python/pipeline/parse/test_super.py" "assignment-from-none" -"mindspore/tests/ut/python/pipeline/parse/test_dictionary.py" "consider-iterating-dictionary" +"mindspore/tests/ut/python/pipeline/infer/test_hypermap.py" "useless-super-delegation" "mindspore/tests/ut/python/pipeline/parse/test_use_undefined_name_or_unsupported_builtin_function.py" "pointless-statement" +"mindspore/tests/ut/python/graph_syntax" "useless-super-delegation" +"mindspore/tests/ut/python/graph_syntax/dict/test_dictionary.py" "consider-iterating-dictionary" +"mindspore/tests/ut/python/graph_syntax/list/test_list_add_list.py" "superfluous-parens" +"mindspore/tests/ut/python/graph_syntax/control_flow/test_cont_break.py" "unused-variable" +"mindspore/tests/ut/python/graph_syntax/python_builtin_functions/test_list_tuple.py" "len-as-condition" +"mindspore/tests/ut/python/graph_syntax/python_builtin_functions/test_super.py" "bad-super-call" "mindspore/tests/st/networks/test_gpu_resnet.py" "superfluous-parens" "mindspore/tests/st/networks/test_gpu_resnet.py" "unused-variable" "mindspore/tests/st/networks/test_gpu_lstm.py" "unused-variable" diff --git a/tests/st/syntax/test_list_append.py b/tests/st/graph_syntax/list/test_list_append.py similarity index 100% rename from tests/st/syntax/test_list_append.py rename to tests/st/graph_syntax/list/test_list_append.py diff --git a/tests/st/syntax/test_list_assign.py b/tests/st/graph_syntax/list/test_list_assign.py similarity index 100% rename from tests/st/syntax/test_list_assign.py rename to tests/st/graph_syntax/list/test_list_assign.py diff --git a/tests/st/syntax/test_list_clear.py b/tests/st/graph_syntax/list/test_list_clear.py similarity index 100% rename from tests/st/syntax/test_list_clear.py rename to tests/st/graph_syntax/list/test_list_clear.py diff --git a/tests/st/syntax/test_list_count.py b/tests/st/graph_syntax/list/test_list_count.py similarity index 100% rename from tests/st/syntax/test_list_count.py rename to tests/st/graph_syntax/list/test_list_count.py diff --git a/tests/st/syntax/test_list_extend.py b/tests/st/graph_syntax/list/test_list_extend.py similarity index 100% rename from tests/st/syntax/test_list_extend.py rename to tests/st/graph_syntax/list/test_list_extend.py diff --git a/tests/st/syntax/test_list_insert.py b/tests/st/graph_syntax/list/test_list_insert.py similarity index 100% rename from tests/st/syntax/test_list_insert.py rename to tests/st/graph_syntax/list/test_list_insert.py diff --git a/tests/st/syntax/test_list_pop.py b/tests/st/graph_syntax/list/test_list_pop.py similarity index 100% rename from tests/st/syntax/test_list_pop.py rename to tests/st/graph_syntax/list/test_list_pop.py diff --git a/tests/st/syntax/test_list_reverse.py b/tests/st/graph_syntax/list/test_list_reverse.py similarity index 100% rename from tests/st/syntax/test_list_reverse.py rename to tests/st/graph_syntax/list/test_list_reverse.py diff --git a/tests/st/fallback/test_graph_fallback_and_or.py b/tests/st/graph_syntax/operators/test_and_or.py similarity index 100% rename from tests/st/fallback/test_graph_fallback_and_or.py rename to tests/st/graph_syntax/operators/test_and_or.py diff --git a/tests/st/syntax/test_bitwise_operator.py b/tests/st/graph_syntax/operators/test_bitwise_operator.py similarity index 100% rename from tests/st/syntax/test_bitwise_operator.py rename to tests/st/graph_syntax/operators/test_bitwise_operator.py diff --git a/tests/st/graph_syntax/python_builtin_functions/test_abs.py b/tests/st/graph_syntax/python_builtin_functions/test_abs.py new file mode 100644 index 00000000000..32f0b42d065 --- /dev/null +++ b/tests/st/graph_syntax/python_builtin_functions/test_abs.py @@ -0,0 +1,41 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""test python built-in functions in graph mode""" +import pytest +import numpy as np +from mindspore import Tensor, context, nn + +context.set_context(mode=context.GRAPH_MODE) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_abs_tensor(): + """ + Feature: JIT Fallback + Description: Test abs(Tensor) with a variable tensor in graph mode + Expectation: No exception + """ + + class Net(nn.Cell): + def construct(self, y): + x = Tensor([-1, 2]) + return abs(x + y) + + net = Net() + assert np.all(net(Tensor([-1, 2])).asnumpy() == np.array([2, 4])) diff --git a/tests/st/graph_syntax/python_builtin_functions/test_all_any.py b/tests/st/graph_syntax/python_builtin_functions/test_all_any.py new file mode 100644 index 00000000000..9a3245728d4 --- /dev/null +++ b/tests/st/graph_syntax/python_builtin_functions/test_all_any.py @@ -0,0 +1,96 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""test python built-in functions in graph mode""" +import pytest +import numpy as np +from mindspore import Tensor, context, nn, ms_function + +context.set_context(mode=context.GRAPH_MODE) + + +@pytest.mark.skip(reason='Not support yet') +def test_fallback_all_tensor(): + """ + Feature: JIT Fallback + Description: Test all(Tensor) with a variable tensor in graph mode + Expectation: No exception + """ + + class Net(nn.Cell): + def construct(self, x, y): + return all(x), all(y) + + net = Net() + x = Tensor(np.array([0, 1, 2, 3])) + y = Tensor(np.array([1, 1])) + out1, out2 = net(x, y) + assert (not out1) and out2 + + +@pytest.mark.skip(reason='Not support yet') +def test_fallback_all_list_hybrid(): + """ + Feature: JIT Fallback + Description: Test all(List) in graph mode + Expectation: No exception + """ + + @ms_function + def foo(a, b): + x = [a, np.array([1]), Tensor(1)] + y = [a, np.array([0]), Tensor(1)] + z = [b, np.array([1]), Tensor(1)] + return all(x), all(y), all(z) + + x, y, z = foo(Tensor([1]), Tensor([0])) + assert x and (not y) and (not z) + + +@pytest.mark.skip(reason='Not support yet') +def test_fallback_any_tensor(): + """ + Feature: JIT Fallback + Description: Test any(Tensor) with a variable tensor in graph mode + Expectation: No exception + """ + + class Net(nn.Cell): + def construct(self, x, y): + return any(x), any(y) + + net = Net() + x = Tensor(np.array([0, 0])) + y = Tensor(np.array([1, 0])) + out1, out2 = net(x, y) + assert (not out1) and out2 + + +@pytest.mark.skip(reason='Not support yet') +def test_fallback_any_list_hybrid(): + """ + Feature: JIT Fallback + Description: Test any(List) in graph mode + Expectation: No exception + """ + + @ms_function + def foo(a, b): + x = [a, np.array([1]), Tensor(1)] + y = [a, np.array([0]), Tensor(1)] + z = [b, np.array([1]), Tensor(1)] + return any(x), any(y), any(z) + + x, y, z = foo(Tensor([1]), Tensor([0])) + assert x and y and z diff --git a/tests/st/graph_syntax/python_builtin_functions/test_bool.py b/tests/st/graph_syntax/python_builtin_functions/test_bool.py new file mode 100644 index 00000000000..977a81e2144 --- /dev/null +++ b/tests/st/graph_syntax/python_builtin_functions/test_bool.py @@ -0,0 +1,38 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""test python built-in functions in graph mode""" +import pytest +from mindspore import Tensor, context, ms_function + +context.set_context(mode=context.GRAPH_MODE) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_bool_with_input_tensor(): + """ + Feature: JIT Fallback + Description: Test bool() in graph mode with tensor input. + Expectation: No exception. + """ + @ms_function + def foo(): + x = Tensor([10]) + return bool(x) + + assert foo() diff --git a/tests/st/syntax/test_getattr_hasattr.py b/tests/st/graph_syntax/python_builtin_functions/test_getattr_hasattr.py similarity index 100% rename from tests/st/syntax/test_getattr_hasattr.py rename to tests/st/graph_syntax/python_builtin_functions/test_getattr_hasattr.py diff --git a/tests/st/fallback/test_graph_fallback_issubclass.py b/tests/st/graph_syntax/python_builtin_functions/test_issubclass.py similarity index 100% rename from tests/st/fallback/test_graph_fallback_issubclass.py rename to tests/st/graph_syntax/python_builtin_functions/test_issubclass.py diff --git a/tests/st/syntax/test_len.py b/tests/st/graph_syntax/python_builtin_functions/test_len.py similarity index 99% rename from tests/st/syntax/test_len.py rename to tests/st/graph_syntax/python_builtin_functions/test_len.py index c112a78a651..0d24665e9d9 100644 --- a/tests/st/syntax/test_len.py +++ b/tests/st/graph_syntax/python_builtin_functions/test_len.py @@ -17,7 +17,6 @@ import pytest import numpy as np from mindspore import ms_function, context, Tensor - context.set_context(mode=context.GRAPH_MODE) diff --git a/tests/st/graph_syntax/python_builtin_functions/test_list_tuple.py b/tests/st/graph_syntax/python_builtin_functions/test_list_tuple.py new file mode 100644 index 00000000000..d3399a2fd98 --- /dev/null +++ b/tests/st/graph_syntax/python_builtin_functions/test_list_tuple.py @@ -0,0 +1,168 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""test python built-in functions in graph mode""" +import pytest +import numpy as np +from mindspore import Tensor, context, ms_function + +context.set_context(mode=context.GRAPH_MODE) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_list_with_input_constant_tensor(): + """ + Feature: JIT Fallback + Description: Test list() in graph mode with constant tensor. + Expectation: No exception. + """ + @ms_function + def foo(): + x = list(Tensor([1, 2, 3])) + x.append(Tensor([4])) + return x + out = foo() + assert isinstance(out, tuple) + assert len(out) == 4 + assert isinstance(out[0], Tensor) + assert out[0].asnumpy() == 1 + assert isinstance(out[1], Tensor) + assert out[1].asnumpy() == 2 + assert isinstance(out[2], Tensor) + assert out[2].asnumpy() == 3 + assert isinstance(out[3], Tensor) + assert out[3].asnumpy() == 4 + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_list_with_input_constant_tensor_2(): + """ + Feature: JIT Fallback + Description: Test list() in graph mode with constant tensor. + Expectation: No exception. + """ + @ms_function + def foo(): + x = list(Tensor([[1, 2], [3, 4]])) + x.append(Tensor([5, 6])) + return x + out = foo() + assert isinstance(out, tuple) + assert len(out) == 3 + assert isinstance(out[0], Tensor) + assert np.allclose(out[0].asnumpy(), np.array([1, 2])) + assert isinstance(out[1], Tensor) + assert np.allclose(out[1].asnumpy(), np.array([3, 4])) + assert isinstance(out[2], Tensor) + assert np.allclose(out[2].asnumpy(), np.array([5, 6])) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_builtin_function_list_with_non_constant_tensor(): + """ + Feature: Graph list function. + Description: When the input to list() is non constant tensor, list function will return correct result. + Expectation: No exception. + """ + @ms_function + def foo(x): + return list(x) + + ret = foo(Tensor([[1, 2, 3], [4, 5, 6]])) + assert len(ret) == 2 + assert np.all(ret[0].asnumpy() == np.array([1, 2, 3])) + assert np.all(ret[1].asnumpy() == np.array([4, 5, 6])) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_tuple_with_input_constant_tensor(): + """ + Feature: JIT Fallback + Description: Test tuple() in graph mode with constant tensor. + Expectation: No exception. + """ + @ms_function + def foo(): + x = tuple(Tensor([1, 2, 3])) + return x + out = foo() + assert isinstance(out, tuple) + assert len(out) == 3 + assert isinstance(out[0], Tensor) + assert out[0].asnumpy() == 1 + assert isinstance(out[1], Tensor) + assert out[1].asnumpy() == 2 + assert isinstance(out[2], Tensor) + assert out[2].asnumpy() == 3 + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_tuple_with_input_constant_tensor_2(): + """ + Feature: JIT Fallback + Description: Test tuple() in graph mode with constant tensor. + Expectation: No exception. + """ + @ms_function + def foo(): + x = list(Tensor([[1, 2], [3, 4]])) + return x + out = foo() + assert isinstance(out, tuple) + assert len(out) == 2 + assert isinstance(out[0], Tensor) + assert np.allclose(out[0].asnumpy(), np.array([1, 2])) + assert isinstance(out[1], Tensor) + assert np.allclose(out[1].asnumpy(), np.array([3, 4])) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_builtin_function_tuple_with_non_constant_tensor(): + """ + Feature: Graph tuple function. + Description: When the input to tuple() is non constant tensor, list function will return correct result. + Expectation: No exception. + """ + @ms_function + def foo(x): + return tuple(x) + + ret = foo(Tensor([[1, 2, 3], [4, 5, 6]])) + assert len(ret) == 2 + assert np.all(ret[0].asnumpy() == np.array([1, 2, 3])) + assert np.all(ret[1].asnumpy() == np.array([4, 5, 6])) diff --git a/tests/st/syntax/test_max_min_tensor.py b/tests/st/graph_syntax/python_builtin_functions/test_max_min.py similarity index 100% rename from tests/st/syntax/test_max_min_tensor.py rename to tests/st/graph_syntax/python_builtin_functions/test_max_min.py diff --git a/tests/st/graph_syntax/python_builtin_functions/test_round.py b/tests/st/graph_syntax/python_builtin_functions/test_round.py new file mode 100644 index 00000000000..ba864ba19f2 --- /dev/null +++ b/tests/st/graph_syntax/python_builtin_functions/test_round.py @@ -0,0 +1,66 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""test python built-in functions in graph mode""" +import pytest +import numpy as np +from mindspore import Tensor, context, nn +from mindspore import dtype as mstype + +context.set_context(mode=context.GRAPH_MODE) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_round_tensor(): + """ + Feature: JIT Fallback + Description: Test round(Tensor) with a variable tensor in graph mode + Expectation: No exception + """ + + class Net(nn.Cell): + def construct(self, x): + return round(x) + + net = Net() + x = Tensor(np.array([0.1, 4.51, 9.9]), mstype.float32) + out = net(x) + expect = Tensor(np.array([0.0, 5.0, 10.0])) + np.testing.assert_almost_equal(out.asnumpy(), expect.asnumpy()) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_round_tensor_constant(): + """ + Feature: JIT Fallback + Description: Test any(Tensor) with a constant tensor in graph mode + Expectation: No exception. + """ + class Net(nn.Cell): + def construct(self): + x = Tensor(np.array([0.1, 4.51, 9.9]), mstype.float32) + return round(x) + + net = Net() + out = net() + expect = Tensor(np.array([0.0, 5.0, 10.0])) + np.testing.assert_almost_equal(out.asnumpy(), expect.asnumpy()) diff --git a/tests/st/graph_syntax/python_builtin_functions/test_sum.py b/tests/st/graph_syntax/python_builtin_functions/test_sum.py new file mode 100644 index 00000000000..f359fae2094 --- /dev/null +++ b/tests/st/graph_syntax/python_builtin_functions/test_sum.py @@ -0,0 +1,126 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""test python built-in functions in graph mode""" +import pytest +import numpy as np +from mindspore import Tensor, context, nn +from mindspore import dtype as mstype + +context.set_context(mode=context.GRAPH_MODE) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_sum_tensor_n_default_1(): + """ + Feature: JIT Fallback + Description: Description: Test sum(Tensor) in graph mode with tensor and input n is default. + Expectation: No exception + """ + class Net(nn.Cell): + def construct(self, x): + return sum(x) + + net = Net() + x = Tensor([3, 4, 5], dtype=mstype.float32) + out = net(x) + assert out == 12 + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_sum_tensor_n_default_2(): + """ + Feature: JIT Fallback + Description: Description: Test sum(Tensor) in graph mode with tensor and input n is default. + Expectation: No exception + """ + class Net(nn.Cell): + def construct(self, x): + return sum(x) + + net = Net() + x = Tensor([[1, 2], [3, 4]], dtype=mstype.float32) + out = net(x) + assert np.allclose(out.asnumpy(), np.array([4, 6])) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_sum_with_x_tensor_n_not_default_1(): + """ + Feature: JIT Fallback + Description: Test sum() in graph mode with input x tensor and input n not default. + Expectation: No exception. + """ + class Net(nn.Cell): + def construct(self, x, y): + return sum(x, y) + + net = Net() + x, y = Tensor([3, 4, 5], dtype=mstype.float32), 4 + out = net(x, y) + assert out == 16 + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_sum_with_x_tensor_n_not_default_2(): + """ + Feature: JIT Fallback + Description: Test sum() in graph mode with input x tensor and input n not default. + Expectation: No exception. + """ + class Net(nn.Cell): + def construct(self, x, y): + return sum(x, y) + + net = Net() + x, y = Tensor([[1, 2], [3, 4]], dtype=mstype.float32), [5, 6] + out = net(x, y) + assert np.allclose(out.asnumpy(), np.array([9, 12])) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard +def test_fallback_sum_with_x_list_of_tensor(): + """ + Feature: JIT Fallback + Description: Test sum() in graph mode when input x is list of tensor. + Expectation: No exception. + """ + class Net(nn.Cell): + def construct(self, x, y): + return sum(x, y) + + net = Net() + x, y = [1, Tensor([[1, 2], [3, 4]]), Tensor([[1, 2], [3, 4]])], Tensor([[1, 1], [1, 1]]) + out = net(x, y) + assert np.allclose(out.asnumpy(), np.array([[4, 6], [8, 10]])) diff --git a/tests/st/syntax/test_graph_raise.py b/tests/st/graph_syntax/statements/test_graph_raise.py similarity index 100% rename from tests/st/syntax/test_graph_raise.py rename to tests/st/graph_syntax/statements/test_graph_raise.py diff --git a/tests/st/syntax/test_list_comprehension.py b/tests/st/graph_syntax/statements/test_list_comprehension.py similarity index 100% rename from tests/st/syntax/test_list_comprehension.py rename to tests/st/graph_syntax/statements/test_list_comprehension.py diff --git a/tests/st/syntax/test_with_as.py b/tests/st/graph_syntax/statements/test_with_as.py similarity index 100% rename from tests/st/syntax/test_with_as.py rename to tests/st/graph_syntax/statements/test_with_as.py diff --git a/tests/st/syntax/test_expr_clear.py b/tests/st/graph_syntax/test_expr_clear.py similarity index 100% rename from tests/st/syntax/test_expr_clear.py rename to tests/st/graph_syntax/test_expr_clear.py diff --git a/tests/st/syntax/test_graph_joinedstr.py b/tests/st/graph_syntax/test_graph_joinedstr.py similarity index 100% rename from tests/st/syntax/test_graph_joinedstr.py rename to tests/st/graph_syntax/test_graph_joinedstr.py diff --git a/tests/syntax/simple_expression/test_hyper_param.py b/tests/st/graph_syntax/test_hyper_param.py similarity index 88% rename from tests/syntax/simple_expression/test_hyper_param.py rename to tests/st/graph_syntax/test_hyper_param.py index 274c72da4be..a3ad7a601f3 100644 --- a/tests/syntax/simple_expression/test_hyper_param.py +++ b/tests/st/graph_syntax/test_hyper_param.py @@ -13,11 +13,17 @@ # limitations under the License. # ============================================================================ +import pytest import mindspore as ms from mindspore import Tensor, Parameter from mindspore.nn import Cell +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard def test_hyper_param(): """ Feature: Resolve parameter. @@ -47,6 +53,11 @@ def test_hyper_param(): assert output == output_expect +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.platform_arm_ascend_training +@pytest.mark.platform_x86_ascend_training +@pytest.mark.env_onecard def test_hyper_param_with_control_sink(): """ Feature: Resolve parameter. diff --git a/tests/st/fallback/test_graph_fallback_class.py b/tests/st/graph_syntax/test_ms_class.py similarity index 95% rename from tests/st/fallback/test_graph_fallback_class.py rename to tests/st/graph_syntax/test_ms_class.py index 7ddb31651ea..7d3017e0076 100644 --- a/tests/st/fallback/test_graph_fallback_class.py +++ b/tests/st/graph_syntax/test_ms_class.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -""" test graph fallback """ +""" test ms_class """ import pytest import numpy as np @@ -28,7 +28,7 @@ context.set_context(mode=context.GRAPH_MODE) @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_attr(): +def test_ms_class_attr(): """ Feature: JIT Fallback Description: Access the attributes of user-defined classes decorated by ms_class. @@ -58,7 +58,7 @@ def test_fallback_class_attr(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_method(): +def test_ms_class_method(): """ Feature: JIT Fallback Description: Access the methods of user-defined classes decorated by ms_class. @@ -93,7 +93,7 @@ def test_fallback_class_method(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_call(): +def test_ms_class_call(): """ Feature: JIT Fallback Description: Call the __call__ function of user-defined classes decorated by ms_class. @@ -129,7 +129,7 @@ def test_fallback_class_call(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_input_attr(): +def test_ms_class_input_attr(): """ Feature: JIT Fallback Description: Access the attributes of user-defined classes decorated by ms_class. @@ -160,7 +160,7 @@ def test_fallback_class_input_attr(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_input_method(): +def test_ms_class_input_method(): """ Feature: JIT Fallback Description: Access the methods of user-defined classes decorated by ms_class. @@ -193,7 +193,7 @@ def test_fallback_class_input_method(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_class_nested(): +def test_ms_class_nested(): """ Feature: JIT Fallback Description: Test nested ms_class in graph. @@ -228,7 +228,7 @@ def test_fallback_class_class_nested(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_cell_nested(): +def test_ms_class_cell_nested(): """ Feature: JIT Fallback Description: Test nested ms_class and cell in graph. @@ -278,7 +278,7 @@ def test_fallback_class_cell_nested(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_type_attr(): +def test_ms_class_type_attr(): """ Feature: JIT Fallback Description: Access the attributes of class type. @@ -312,7 +312,7 @@ def test_fallback_class_type_attr(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_create_instance_attr(): +def test_ms_class_create_instance_attr(): """ Feature: JIT Fallback Description: Access the attributes of the created class instance. @@ -342,7 +342,7 @@ def test_fallback_class_create_instance_attr(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_create_instance_method(): +def test_ms_class_create_instance_method(): """ Feature: JIT Fallback Description: Access the methods of the created class instance. @@ -378,7 +378,7 @@ def test_fallback_class_create_instance_method(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_class_create_instance_call(): +def test_ms_class_create_instance_call(): """ Feature: JIT Fallback Description: Call the __call__ function of the created class instance. @@ -415,7 +415,7 @@ def test_fallback_class_create_instance_call(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_raise_error_not_class_type(): +def test_raise_error_not_class_type(): """ Feature: JIT Fallback Description: Decorator ms_class cannot be used for non-class types. @@ -434,7 +434,7 @@ def test_fallback_raise_error_not_class_type(): @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training @pytest.mark.env_onecard -def test_fallback_raise_error_decorate_cell(): +def test_raise_error_decorate_cell(): """ Feature: JIT Fallback Description: Decorator ms_class cannot be used for nn.Cell diff --git a/tests/st/syntax/test_graph_fallback_python_builtin_tensor.py b/tests/st/syntax/test_graph_fallback_python_builtin_tensor.py deleted file mode 100644 index 4aa28fbba35..00000000000 --- a/tests/st/syntax/test_graph_fallback_python_builtin_tensor.py +++ /dev/null @@ -1,435 +0,0 @@ -# Copyright 2022 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ -"""test python built-in functions in graph mode""" -import pytest -import numpy as np -from mindspore import Tensor, context, nn, ms_function -from mindspore import dtype as mstype - -context.set_context(mode=context.GRAPH_MODE) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_abs_tensor(): - """ - Feature: JIT Fallback - Description: Test abs(Tensor) with a variable tensor in graph mode - Expectation: No exception - """ - - class Net(nn.Cell): - def construct(self, y): - x = Tensor([-1, 2]) - return abs(x + y) - - net = Net() - assert np.all(net(Tensor([-1, 2])).asnumpy() == np.array([2, 4])) - - -@pytest.mark.skip(reason='Not support yet') -def test_fallback_all_tensor(): - """ - Feature: JIT Fallback - Description: Test all(Tensor) with a variable tensor in graph mode - Expectation: No exception - """ - - class Net(nn.Cell): - def construct(self, x, y): - return all(x), all(y) - - net = Net() - x = Tensor(np.array([0, 1, 2, 3])) - y = Tensor(np.array([1, 1])) - out1, out2 = net(x, y) - assert (not out1) and out2 - - -@pytest.mark.skip(reason='Not support yet') -def test_fallback_all_list_hybrid(): - """ - Feature: JIT Fallback - Description: Test all(List) in graph mode - Expectation: No exception - """ - - @ms_function - def foo(a, b): - x = [a, np.array([1]), Tensor(1)] - y = [a, np.array([0]), Tensor(1)] - z = [b, np.array([1]), Tensor(1)] - return all(x), all(y), all(z) - - x, y, z = foo(Tensor([1]), Tensor([0])) - assert x and (not y) and (not z) - - -@pytest.mark.skip(reason='Not support yet') -def test_fallback_any_tensor(): - """ - Feature: JIT Fallback - Description: Test any(Tensor) with a variable tensor in graph mode - Expectation: No exception - """ - - class Net(nn.Cell): - def construct(self, x, y): - return any(x), any(y) - - net = Net() - x = Tensor(np.array([0, 0])) - y = Tensor(np.array([1, 0])) - out1, out2 = net(x, y) - assert (not out1) and out2 - - -@pytest.mark.skip(reason='Not support yet') -def test_fallback_any_list_hybrid(): - """ - Feature: JIT Fallback - Description: Test any(List) in graph mode - Expectation: No exception - """ - - @ms_function - def foo(a, b): - x = [a, np.array([1]), Tensor(1)] - y = [a, np.array([0]), Tensor(1)] - z = [b, np.array([1]), Tensor(1)] - return any(x), any(y), any(z) - - x, y, z = foo(Tensor([1]), Tensor([0])) - assert x and y and z - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_round_tensor(): - """ - Feature: JIT Fallback - Description: Test round(Tensor) with a variable tensor in graph mode - Expectation: No exception - """ - - class Net(nn.Cell): - def construct(self, x): - return round(x) - - net = Net() - x = Tensor(np.array([0.1, 4.51, 9.9]), mstype.float32) - out = net(x) - expect = Tensor(np.array([0.0, 5.0, 10.0])) - np.testing.assert_almost_equal(out.asnumpy(), expect.asnumpy()) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_round_tensor_constant(): - """ - Feature: JIT Fallback - Description: Test any(Tensor) with a constant tensor in graph mode - Expectation: No exception. - """ - class Net(nn.Cell): - def construct(self): - x = Tensor(np.array([0.1, 4.51, 9.9]), mstype.float32) - return round(x) - - net = Net() - out = net() - expect = Tensor(np.array([0.0, 5.0, 10.0])) - np.testing.assert_almost_equal(out.asnumpy(), expect.asnumpy()) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_sum_tensor_n_default_1(): - """ - Feature: JIT Fallback - Description: Description: Test sum(Tensor) in graph mode with tensor and input n is default. - Expectation: No exception - """ - class Net(nn.Cell): - def construct(self, x): - return sum(x) - - net = Net() - x = Tensor([3, 4, 5], dtype=mstype.float32) - out = net(x) - assert out == 12 - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_sum_tensor_n_default_2(): - """ - Feature: JIT Fallback - Description: Description: Test sum(Tensor) in graph mode with tensor and input n is default. - Expectation: No exception - """ - class Net(nn.Cell): - def construct(self, x): - return sum(x) - - net = Net() - x = Tensor([[1, 2], [3, 4]], dtype=mstype.float32) - out = net(x) - assert np.allclose(out.asnumpy(), np.array([4, 6])) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_sum_with_x_tensor_n_not_default_1(): - """ - Feature: JIT Fallback - Description: Test sum() in graph mode with input x tensor and input n not default. - Expectation: No exception. - """ - class Net(nn.Cell): - def construct(self, x, y): - return sum(x, y) - - net = Net() - x, y = Tensor([3, 4, 5], dtype=mstype.float32), 4 - out = net(x, y) - assert out == 16 - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_sum_with_x_tensor_n_not_default_2(): - """ - Feature: JIT Fallback - Description: Test sum() in graph mode with input x tensor and input n not default. - Expectation: No exception. - """ - class Net(nn.Cell): - def construct(self, x, y): - return sum(x, y) - - net = Net() - x, y = Tensor([[1, 2], [3, 4]], dtype=mstype.float32), [5, 6] - out = net(x, y) - assert np.allclose(out.asnumpy(), np.array([9, 12])) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_sum_with_x_list_of_tensor(): - """ - Feature: JIT Fallback - Description: Test sum() in graph mode when input x is list of tensor. - Expectation: No exception. - """ - class Net(nn.Cell): - def construct(self, x, y): - return sum(x, y) - - net = Net() - x, y = [1, Tensor([[1, 2], [3, 4]]), Tensor([[1, 2], [3, 4]])], Tensor([[1, 1], [1, 1]]) - out = net(x, y) - assert np.allclose(out.asnumpy(), np.array([[4, 6], [8, 10]])) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_list_with_input_constant_tensor(): - """ - Feature: JIT Fallback - Description: Test list() in graph mode with constant tensor. - Expectation: No exception. - """ - @ms_function - def foo(): - x = list(Tensor([1, 2, 3])) - x.append(Tensor([4])) - return x - out = foo() - assert isinstance(out, tuple) - assert len(out) == 4 - assert isinstance(out[0], Tensor) - assert out[0].asnumpy() == 1 - assert isinstance(out[1], Tensor) - assert out[1].asnumpy() == 2 - assert isinstance(out[2], Tensor) - assert out[2].asnumpy() == 3 - assert isinstance(out[3], Tensor) - assert out[3].asnumpy() == 4 - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_list_with_input_constant_tensor_2(): - """ - Feature: JIT Fallback - Description: Test list() in graph mode with constant tensor. - Expectation: No exception. - """ - @ms_function - def foo(): - x = list(Tensor([[1, 2], [3, 4]])) - x.append(Tensor([5, 6])) - return x - out = foo() - assert isinstance(out, tuple) - assert len(out) == 3 - assert isinstance(out[0], Tensor) - assert np.allclose(out[0].asnumpy(), np.array([1, 2])) - assert isinstance(out[1], Tensor) - assert np.allclose(out[1].asnumpy(), np.array([3, 4])) - assert isinstance(out[2], Tensor) - assert np.allclose(out[2].asnumpy(), np.array([5, 6])) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_builtin_function_list_with_non_constant_tensor(): - """ - Feature: Graph list function. - Description: When the input to list() is non constant tensor, list function will return correct result. - Expectation: No exception. - """ - @ms_function - def foo(x): - return list(x) - - ret = foo(Tensor([[1, 2, 3], [4, 5, 6]])) - assert len(ret) == 2 - assert np.all(ret[0].asnumpy() == np.array([1, 2, 3])) - assert np.all(ret[1].asnumpy() == np.array([4, 5, 6])) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_tuple_with_input_constant_tensor(): - """ - Feature: JIT Fallback - Description: Test tuple() in graph mode with constant tensor. - Expectation: No exception. - """ - @ms_function - def foo(): - x = tuple(Tensor([1, 2, 3])) - return x - out = foo() - assert isinstance(out, tuple) - assert len(out) == 3 - assert isinstance(out[0], Tensor) - assert out[0].asnumpy() == 1 - assert isinstance(out[1], Tensor) - assert out[1].asnumpy() == 2 - assert isinstance(out[2], Tensor) - assert out[2].asnumpy() == 3 - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_tuple_with_input_constant_tensor_2(): - """ - Feature: JIT Fallback - Description: Test tuple() in graph mode with constant tensor. - Expectation: No exception. - """ - @ms_function - def foo(): - x = list(Tensor([[1, 2], [3, 4]])) - return x - out = foo() - assert isinstance(out, tuple) - assert len(out) == 2 - assert isinstance(out[0], Tensor) - assert np.allclose(out[0].asnumpy(), np.array([1, 2])) - assert isinstance(out[1], Tensor) - assert np.allclose(out[1].asnumpy(), np.array([3, 4])) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_builtin_function_tuple_with_non_constant_tensor(): - """ - Feature: Graph tuple function. - Description: When the input to tuple() is non constant tensor, list function will return correct result. - Expectation: No exception. - """ - @ms_function - def foo(x): - return tuple(x) - - ret = foo(Tensor([[1, 2, 3], [4, 5, 6]])) - assert len(ret) == 2 - assert np.all(ret[0].asnumpy() == np.array([1, 2, 3])) - assert np.all(ret[1].asnumpy() == np.array([4, 5, 6])) - - -@pytest.mark.level0 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.platform_arm_ascend_training -@pytest.mark.platform_x86_ascend_training -@pytest.mark.env_onecard -def test_fallback_bool_with_input_tensor_2(): - """ - Feature: JIT Fallback - Description: Test bool() in graph mode with tensor input. - Expectation: No exception. - """ - @ms_function - def foo(): - x = Tensor([10]) - return bool(x) - - assert foo() diff --git a/tests/ut/python/graph_syntax/__init__.py b/tests/ut/python/graph_syntax/__init__.py new file mode 100644 index 00000000000..0eb37a40587 --- /dev/null +++ b/tests/ut/python/graph_syntax/__init__.py @@ -0,0 +1,21 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""setup for pytest""" +import mindspore.context as context + + +# pylint: disable=unused-argument +def setup_module(module): + context.set_context(mode=context.GRAPH_MODE) diff --git a/tests/ut/python/dtype/__init__.py b/tests/ut/python/graph_syntax/control_flow/__init__.py similarity index 100% rename from tests/ut/python/dtype/__init__.py rename to tests/ut/python/graph_syntax/control_flow/__init__.py diff --git a/tests/ut/python/pipeline/parse/test_cont_break.py b/tests/ut/python/graph_syntax/control_flow/test_cont_break.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_cont_break.py rename to tests/ut/python/graph_syntax/control_flow/test_cont_break.py index 578df0c287d..96eee801e42 100644 --- a/tests/ut/python/pipeline/parse/test_cont_break.py +++ b/tests/ut/python/graph_syntax/control_flow/test_cont_break.py @@ -71,6 +71,7 @@ class for_loop_with_continue(Cell): def test_for_loop_with_continue(): run_test(for_loop_with_continue, 10) + # pylint: disable=unnecessary-pass class for_loop_with_cont_break(Cell): def __init__(self): @@ -84,7 +85,6 @@ class for_loop_with_cont_break(Cell): if i > 5: x *= 3 break - # x *= 2 x = x * 2 pass return x diff --git a/tests/ut/python/pipeline/parse/test_for_stmt.py b/tests/ut/python/graph_syntax/control_flow/test_for_stmt.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_for_stmt.py rename to tests/ut/python/graph_syntax/control_flow/test_for_stmt.py diff --git a/tests/ut/python/pipeline/parse/test_if_function.py b/tests/ut/python/graph_syntax/control_flow/test_if_function.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_if_function.py rename to tests/ut/python/graph_syntax/control_flow/test_if_function.py index 3ba3eb64ed2..0aa93b8f72b 100644 --- a/tests/ut/python/pipeline/parse/test_if_function.py +++ b/tests/ut/python/graph_syntax/control_flow/test_if_function.py @@ -21,6 +21,7 @@ from mindspore import context context.set_context(mode=context.GRAPH_MODE) + def test_if_function(): class Net(nn.Cell): def __init__(self, func): diff --git a/tests/ut/python/pipeline/parse/test_while_param.py b/tests/ut/python/graph_syntax/control_flow/test_while_param.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_while_param.py rename to tests/ut/python/graph_syntax/control_flow/test_while_param.py index 7853074b5d8..555f2d27957 100644 --- a/tests/ut/python/pipeline/parse/test_while_param.py +++ b/tests/ut/python/graph_syntax/control_flow/test_while_param.py @@ -44,6 +44,7 @@ def test_while_loop_phi(): net = WhileSubGraphParam() net(x, y, z) + class WhileSubGraphParam2(Cell): def __init__(self): super().__init__() @@ -91,6 +92,7 @@ def test_while_loop_phi_3(): net = WhileSubGraphParam3(x) net() + class ControlMixedWhileIf(nn.Cell): def __init__(self): super().__init__() @@ -130,6 +132,7 @@ class ControlMixedWhileIf(nn.Cell): out = out + x return out + def test_mixed_while_if(): context.set_context(mode=context.PYNATIVE_MODE) x = np.array(2).astype(np.int32) diff --git a/tests/ut/python/ops/test_dict_clear.py b/tests/ut/python/graph_syntax/dict/test_dict_clear.py similarity index 100% rename from tests/ut/python/ops/test_dict_clear.py rename to tests/ut/python/graph_syntax/dict/test_dict_clear.py diff --git a/tests/ut/python/ops/test_dict_fromkeys.py b/tests/ut/python/graph_syntax/dict/test_dict_fromkeys.py similarity index 100% rename from tests/ut/python/ops/test_dict_fromkeys.py rename to tests/ut/python/graph_syntax/dict/test_dict_fromkeys.py diff --git a/tests/ut/python/ops/test_dict_get.py b/tests/ut/python/graph_syntax/dict/test_dict_get.py similarity index 100% rename from tests/ut/python/ops/test_dict_get.py rename to tests/ut/python/graph_syntax/dict/test_dict_get.py diff --git a/tests/ut/python/ops/test_dict_haskey.py b/tests/ut/python/graph_syntax/dict/test_dict_haskey.py similarity index 100% rename from tests/ut/python/ops/test_dict_haskey.py rename to tests/ut/python/graph_syntax/dict/test_dict_haskey.py diff --git a/tests/ut/python/ops/test_dict_update.py b/tests/ut/python/graph_syntax/dict/test_dict_update.py similarity index 100% rename from tests/ut/python/ops/test_dict_update.py rename to tests/ut/python/graph_syntax/dict/test_dict_update.py diff --git a/tests/ut/python/pipeline/parse/test_dictionary.py b/tests/ut/python/graph_syntax/dict/test_dictionary.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_dictionary.py rename to tests/ut/python/graph_syntax/dict/test_dictionary.py diff --git a/tests/ut/python/dtype/test_dictionary.py b/tests/ut/python/graph_syntax/dict/test_dtype_dictionary.py similarity index 100% rename from tests/ut/python/dtype/test_dictionary.py rename to tests/ut/python/graph_syntax/dict/test_dtype_dictionary.py diff --git a/tests/ut/python/dtype/test_list.py b/tests/ut/python/graph_syntax/list/test_dtype_list.py similarity index 100% rename from tests/ut/python/dtype/test_list.py rename to tests/ut/python/graph_syntax/list/test_dtype_list.py diff --git a/tests/ut/python/pipeline/parse/test_list.py b/tests/ut/python/graph_syntax/list/test_list.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_list.py rename to tests/ut/python/graph_syntax/list/test_list.py diff --git a/tests/ut/python/pipeline/parse/test_list_add_list.py b/tests/ut/python/graph_syntax/list/test_list_add_list.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_list_add_list.py rename to tests/ut/python/graph_syntax/list/test_list_add_list.py index d0e53c09177..2acb5e52c14 100644 --- a/tests/ut/python/pipeline/parse/test_list_add_list.py +++ b/tests/ut/python/graph_syntax/list/test_list_add_list.py @@ -29,6 +29,7 @@ class Net(nn.Cell): def construct(self): return self.value1 + self.value2 + def test_list_add_list(): context.set_context(mode=context.GRAPH_MODE) net = Net() diff --git a/tests/ut/python/pipeline/parse/test_sequence_assign.py b/tests/ut/python/graph_syntax/list/test_list_assign.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_sequence_assign.py rename to tests/ut/python/graph_syntax/list/test_list_assign.py diff --git a/tests/ut/python/pipeline/parse/test_list_mul_number.py b/tests/ut/python/graph_syntax/list/test_list_mul_number.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_list_mul_number.py rename to tests/ut/python/graph_syntax/list/test_list_mul_number.py index 70d37ade1f9..9face1095bd 100644 --- a/tests/ut/python/pipeline/parse/test_list_mul_number.py +++ b/tests/ut/python/graph_syntax/list/test_list_mul_number.py @@ -29,6 +29,7 @@ class Net(nn.Cell): def construct(self): return self.list_ * self.number1, self.list_ * self.number2 + def test_list_mul_number(): """ Description: test_list_mul_number diff --git a/tests/ut/python/pipeline/parse/test_number_mul_list.py b/tests/ut/python/graph_syntax/list/test_number_mul_list.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_number_mul_list.py rename to tests/ut/python/graph_syntax/list/test_number_mul_list.py index 4bfa2b664c5..bf413479e5e 100644 --- a/tests/ut/python/pipeline/parse/test_number_mul_list.py +++ b/tests/ut/python/graph_syntax/list/test_number_mul_list.py @@ -29,6 +29,7 @@ class Net(nn.Cell): def construct(self): return self.number1 * self.list_, self.number2 * self.list_ + def test_number_mul_list(): """ Description: test_number_mul_list diff --git a/tests/ut/python/fallback/test_graph_fallback_numpy.py b/tests/ut/python/graph_syntax/numpy/test_graph_fallback_numpy.py similarity index 100% rename from tests/ut/python/fallback/test_graph_fallback_numpy.py rename to tests/ut/python/graph_syntax/numpy/test_graph_fallback_numpy.py diff --git a/tests/ut/python/pipeline/parse/test_parse_numpy.py b/tests/ut/python/graph_syntax/numpy/test_parse_numpy.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_parse_numpy.py rename to tests/ut/python/graph_syntax/numpy/test_parse_numpy.py index 748cc9182ef..1b2069e2cba 100644 --- a/tests/ut/python/pipeline/parse/test_parse_numpy.py +++ b/tests/ut/python/graph_syntax/numpy/test_parse_numpy.py @@ -51,6 +51,7 @@ def test_use_numpy_method(): net() assert "Should not use Python object in runtime" in str(err.value) + def test_use_numpy_module(): class Net(nn.Cell): def __init__(self): diff --git a/tests/ut/python/python_builtin/__init__.py b/tests/ut/python/graph_syntax/operators/__init__.py similarity index 100% rename from tests/ut/python/python_builtin/__init__.py rename to tests/ut/python/graph_syntax/operators/__init__.py diff --git a/tests/ut/python/pipeline/parse/test_bitwise_operator.py b/tests/ut/python/graph_syntax/operators/test_bitwise_operator.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_bitwise_operator.py rename to tests/ut/python/graph_syntax/operators/test_bitwise_operator.py diff --git a/tests/ut/python/pipeline/parse/test_equal_two_mstype.py b/tests/ut/python/graph_syntax/operators/test_equal_two_mstype.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_equal_two_mstype.py rename to tests/ut/python/graph_syntax/operators/test_equal_two_mstype.py diff --git a/tests/ut/python/pipeline/parse/test_invert.py b/tests/ut/python/graph_syntax/operators/test_invert.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_invert.py rename to tests/ut/python/graph_syntax/operators/test_invert.py diff --git a/tests/ut/python/pipeline/infer/test_mod.py b/tests/ut/python/graph_syntax/operators/test_mod.py similarity index 100% rename from tests/ut/python/pipeline/infer/test_mod.py rename to tests/ut/python/graph_syntax/operators/test_mod.py diff --git a/tests/ut/python/pipeline/infer/test_not_in.py b/tests/ut/python/graph_syntax/operators/test_not_in.py similarity index 100% rename from tests/ut/python/pipeline/infer/test_not_in.py rename to tests/ut/python/graph_syntax/operators/test_not_in.py diff --git a/tests/ut/python/pipeline/parse/test_operator.py b/tests/ut/python/graph_syntax/operators/test_operator.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_operator.py rename to tests/ut/python/graph_syntax/operators/test_operator.py diff --git a/tests/ut/python/pipeline/parse/test_shift_operator.py b/tests/ut/python/graph_syntax/operators/test_shift_operator.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_shift_operator.py rename to tests/ut/python/graph_syntax/operators/test_shift_operator.py diff --git a/tests/ut/python/pipeline/parse/test_unaryop.py b/tests/ut/python/graph_syntax/operators/test_unaryop.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_unaryop.py rename to tests/ut/python/graph_syntax/operators/test_unaryop.py diff --git a/tests/ut/python/graph_syntax/python_builtin_functions/__init__.py b/tests/ut/python/graph_syntax/python_builtin_functions/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/ut/python/python_builtin/test_abs.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_abs.py similarity index 100% rename from tests/ut/python/python_builtin/test_abs.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_abs.py diff --git a/tests/ut/python/python_builtin/test_all_any.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_all_any.py similarity index 100% rename from tests/ut/python/python_builtin/test_all_any.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_all_any.py diff --git a/tests/ut/python/python_builtin/test_bool.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_bool.py similarity index 100% rename from tests/ut/python/python_builtin/test_bool.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_bool.py diff --git a/tests/ut/python/fallback/python_builtin/test_graph_fallback_python_builtin_bool.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_bool2.py similarity index 100% rename from tests/ut/python/fallback/python_builtin/test_graph_fallback_python_builtin_bool.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_bool2.py diff --git a/tests/ut/python/fallback/python_builtin/test_graph_fallback_python_builtin_dict.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_dict.py similarity index 100% rename from tests/ut/python/fallback/python_builtin/test_graph_fallback_python_builtin_dict.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_dict.py diff --git a/tests/ut/python/pipeline/parse/test_enumerate.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_enumerate.py similarity index 94% rename from tests/ut/python/pipeline/parse/test_enumerate.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_enumerate.py index a1de60fdea8..c0844f2b0ac 100644 --- a/tests/ut/python/pipeline/parse/test_enumerate.py +++ b/tests/ut/python/graph_syntax/python_builtin_functions/test_enumerate.py @@ -13,12 +13,12 @@ # limitations under the License. # ============================================================================ """ test enumerate""" +import operator import numpy as np import pytest import mindspore.nn as nn -from mindspore import Tensor -from mindspore import context +from mindspore import ms_function, context, Tensor context.set_context(mode=context.GRAPH_MODE) @@ -287,3 +287,19 @@ def test_enumerate_start_type_error(): with pytest.raises(TypeError) as ex: net(x) assert "For 'enumerate', the 'start'" in str(ex.value) + + +def test_fallback_enumerate_with_numpy(): + """ + Feature: JIT Fallback + Description: Test enumerate in graph mode with numpy input. + Expectation: No exception. + """ + @ms_function + def foo(): + x = np.array([1, 2]) + y = enumerate(x) + return tuple(y) + + out = foo() + assert operator.eq(out, ((0, 1), (1, 2))) diff --git a/tests/ut/python/graph_syntax/python_builtin_functions/test_filter.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_filter.py new file mode 100644 index 00000000000..b97ec0a09b8 --- /dev/null +++ b/tests/ut/python/graph_syntax/python_builtin_functions/test_filter.py @@ -0,0 +1,56 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" test graph fallback hybrid syntax""" +import operator +import numpy as np +from mindspore import ms_function, context + +context.set_context(mode=context.GRAPH_MODE) + + +def test_fallback_filter_with_numpy_and_tensor(): + """ + Feature: JIT Fallback + Description: Test filter in graph mode with numpy. + Expectation: No exception. + """ + @ms_function + def foo(): + x = np.array([1, 2, 3, 4]) + ret = filter(lambda x: x > 2, x) + return tuple(ret) + + out = foo() + assert operator.eq(out, (3, 4)) + + +def filter_fn(x): + return x > 2 + + +def test_fallback_filter_with_numpy_and_tensor_2(): + """ + Feature: JIT Fallback + Description: Test filter in graph mode with numpy. + Expectation: No exception. + """ + @ms_function + def foo(): + x = np.array([1, 2, 3, 4]) + ret = filter(filter_fn, x) + return tuple(ret) + + out = foo() + assert operator.eq(out, (3, 4)) diff --git a/tests/ut/python/python_builtin/test_getattr.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_getattr.py similarity index 100% rename from tests/ut/python/python_builtin/test_getattr.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_getattr.py diff --git a/tests/ut/python/fallback/test_graph_fallback_python_builtin.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_graph_fallback_python_builtin.py similarity index 99% rename from tests/ut/python/fallback/test_graph_fallback_python_builtin.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_graph_fallback_python_builtin.py index af84e28a047..f18ea022258 100644 --- a/tests/ut/python/fallback/test_graph_fallback_python_builtin.py +++ b/tests/ut/python/graph_syntax/python_builtin_functions/test_graph_fallback_python_builtin.py @@ -19,6 +19,7 @@ from mindspore import ms_function, context, Tensor context.set_context(mode=context.GRAPH_MODE) + def test_fallback_bin(): """ Feature: JIT Fallback @@ -31,6 +32,7 @@ def test_fallback_bin(): return x assert foo() == '0b11' + def test_fallback_chr(): """ Feature: JIT Fallback @@ -98,6 +100,7 @@ def test_fallback_hex(): return x assert foo() == '0xff' + def test_fallback_oct(): """ Feature: JIT Fallback diff --git a/tests/ut/python/python_builtin/test_hasattr.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_hasattr.py similarity index 100% rename from tests/ut/python/python_builtin/test_hasattr.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_hasattr.py diff --git a/tests/ut/python/python_builtin/test_int_float.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_int_float.py similarity index 100% rename from tests/ut/python/python_builtin/test_int_float.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_int_float.py diff --git a/tests/ut/python/pipeline/parse/test_isinstance.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_isinstance.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_isinstance.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_isinstance.py diff --git a/tests/ut/python/python_builtin/test_isinstance.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_isinstance2.py similarity index 100% rename from tests/ut/python/python_builtin/test_isinstance.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_isinstance2.py diff --git a/tests/ut/python/python_builtin/test_len.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_len.py similarity index 100% rename from tests/ut/python/python_builtin/test_len.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_len.py diff --git a/tests/ut/python/pipeline/parse/test_len_of_array.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_len_of_array.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_len_of_array.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_len_of_array.py diff --git a/tests/ut/python/python_builtin/test_list_tuple.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_list_tuple.py similarity index 100% rename from tests/ut/python/python_builtin/test_list_tuple.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_list_tuple.py diff --git a/tests/ut/python/fallback/python_builtin/test_graph_fallback_hybrid_syntax.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_map.py similarity index 52% rename from tests/ut/python/fallback/python_builtin/test_graph_fallback_hybrid_syntax.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_map.py index 828472d07e3..0e67ee3dacc 100644 --- a/tests/ut/python/fallback/python_builtin/test_graph_fallback_hybrid_syntax.py +++ b/tests/ut/python/graph_syntax/python_builtin_functions/test_map.py @@ -20,71 +20,6 @@ from mindspore import ms_function, context, Tensor context.set_context(mode=context.GRAPH_MODE) -def test_fallback_len_with_numpy(): - """ - Feature: JIT Fallback - Description: Test len in graph mode with numpy input. - Expectation: No exception. - """ - @ms_function - def foo(): - x = np.array([1, 2, 3, 4]) - return len(x) - - out = foo() - assert out == 4 - - -def test_fallback_enumerate_with_numpy(): - """ - Feature: JIT Fallback - Description: Test enumerate in graph mode with numpy input. - Expectation: No exception. - """ - @ms_function - def foo(): - x = np.array([1, 2]) - y = enumerate(x) - return tuple(y) - - out = foo() - assert operator.eq(out, ((0, 1), (1, 2))) - - -def test_fallback_zip_with_numpy(): - """ - Feature: JIT Fallback - Description: Test zip in graph mode with numpy input. - Expectation: No exception. - """ - @ms_function - def foo(): - x = np.array([1, 2]) - y = np.array([10, 20]) - ret = zip(x, y) - return tuple(ret) - - out = foo() - assert operator.eq(out, ((1, 10), (2, 20))) - - -def test_fallback_zip_with_numpy_and_tensor(): - """ - Feature: JIT Fallback - Description: Test zip in graph mode with numpy and tensor input. - Expectation: No exception. - """ - @ms_function - def foo(): - x = np.array([1, 2]) - y = Tensor([10, 20]) - ret = zip(x, y) - return tuple(ret) - - out = foo() - assert operator.eq(out, ((1, 10), (2, 20))) - - def test_fallback_map_with_numpy(): """ Feature: JIT Fallback @@ -156,39 +91,3 @@ def test_fallback_map_with_numpy_and_tensor_2(): out = foo() assert operator.eq(out, (2, 3, 4, 5)) - - -def test_fallback_filter_with_numpy_and_tensor(): - """ - Feature: JIT Fallback - Description: Test filter in graph mode with numpy. - Expectation: No exception. - """ - @ms_function - def foo(): - x = np.array([1, 2, 3, 4]) - ret = filter(lambda x: x > 2, x) - return tuple(ret) - - out = foo() - assert operator.eq(out, (3, 4)) - - -def filter_fn(x): - return x > 2 - - -def test_fallback_filter_with_numpy_and_tensor_2(): - """ - Feature: JIT Fallback - Description: Test filter in graph mode with numpy. - Expectation: No exception. - """ - @ms_function - def foo(): - x = np.array([1, 2, 3, 4]) - ret = filter(filter_fn, x) - return tuple(ret) - - out = foo() - assert operator.eq(out, (3, 4)) diff --git a/tests/ut/python/python_builtin/test_max_min.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_max_min.py similarity index 100% rename from tests/ut/python/python_builtin/test_max_min.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_max_min.py diff --git a/tests/ut/python/pipeline/parse/test_partial.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_partial.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_partial.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_partial.py diff --git a/tests/ut/python/pipeline/infer/test_range.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_range.py similarity index 100% rename from tests/ut/python/pipeline/infer/test_range.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_range.py diff --git a/tests/ut/python/python_builtin/test_round.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_round.py similarity index 100% rename from tests/ut/python/python_builtin/test_round.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_round.py diff --git a/tests/ut/python/python_builtin/test_str.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_str.py similarity index 100% rename from tests/ut/python/python_builtin/test_str.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_str.py diff --git a/tests/ut/python/python_builtin/test_sum.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_sum.py similarity index 100% rename from tests/ut/python/python_builtin/test_sum.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_sum.py diff --git a/tests/ut/python/pipeline/parse/test_super.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_super.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_super.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_super.py diff --git a/tests/ut/python/fallback/python_builtin/test_graph_fallback_type.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_type.py similarity index 99% rename from tests/ut/python/fallback/python_builtin/test_graph_fallback_type.py rename to tests/ut/python/graph_syntax/python_builtin_functions/test_type.py index 67890efa133..9c46ec3ca94 100644 --- a/tests/ut/python/fallback/python_builtin/test_graph_fallback_type.py +++ b/tests/ut/python/graph_syntax/python_builtin_functions/test_type.py @@ -18,6 +18,7 @@ from mindspore import ms_function, context, Tensor context.set_context(mode=context.GRAPH_MODE) + def test_fallback_type_with_input_int(): """ Feature: JIT Fallback diff --git a/tests/ut/python/graph_syntax/python_builtin_functions/test_zip.py b/tests/ut/python/graph_syntax/python_builtin_functions/test_zip.py new file mode 100644 index 00000000000..fae405effae --- /dev/null +++ b/tests/ut/python/graph_syntax/python_builtin_functions/test_zip.py @@ -0,0 +1,54 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" test graph fallback hybrid syntax""" +import operator +import numpy as np +from mindspore import ms_function, context, Tensor + +context.set_context(mode=context.GRAPH_MODE) + + +def test_fallback_zip_with_numpy(): + """ + Feature: JIT Fallback + Description: Test zip in graph mode with numpy input. + Expectation: No exception. + """ + @ms_function + def foo(): + x = np.array([1, 2]) + y = np.array([10, 20]) + ret = zip(x, y) + return tuple(ret) + + out = foo() + assert operator.eq(out, ((1, 10), (2, 20))) + + +def test_fallback_zip_with_numpy_and_tensor(): + """ + Feature: JIT Fallback + Description: Test zip in graph mode with numpy and tensor input. + Expectation: No exception. + """ + @ms_function + def foo(): + x = np.array([1, 2]) + y = Tensor([10, 20]) + ret = zip(x, y) + return tuple(ret) + + out = foo() + assert operator.eq(out, ((1, 10), (2, 20))) diff --git a/tests/ut/python/pipeline/parse/test_assert.py b/tests/ut/python/graph_syntax/statements/test_assert.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_assert.py rename to tests/ut/python/graph_syntax/statements/test_assert.py diff --git a/tests/ut/python/pipeline/parse/test_list_comp.py b/tests/ut/python/graph_syntax/statements/test_list_comp.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_list_comp.py rename to tests/ut/python/graph_syntax/statements/test_list_comp.py index 4a95bb0ab07..1f174ae71e7 100644 --- a/tests/ut/python/pipeline/parse/test_list_comp.py +++ b/tests/ut/python/graph_syntax/statements/test_list_comp.py @@ -17,26 +17,31 @@ import pytest from mindspore import context, ms_function + @ms_function def get_list_comp_1(): l = [x for x in range(1, 6)] return l + @ms_function def get_list_comp_2(): l = [x * x for x in range(1, 6)] return l + @ms_function def get_list_comp_3(): l = [x * x for x in range(1, 11) if x % 2 == 0] return l + @ms_function def get_list_comp_4(): l = [x * x for x in range(1, 11) if x > 5 if x % 2 == 0] return l + @ms_function def get_list_comp_5(): # Create a ListComp with multiple comprehension. @@ -44,16 +49,19 @@ def get_list_comp_5(): l = [y for x in ((1, 2), (3, 4), (5, 6)) for y in x] # [1, 2, 3, 4, 5, 6] return l + @ms_function def get_generator_exp_1(): t = (x for x in range(1, 6)) return t + @ms_function def get_generator_exp_2(): t = (x * x for x in range(1, 11) if x > 5 if x % 2 == 0) return t + def test_list_comp(): context.set_context(mode=context.GRAPH_MODE) assert get_list_comp_1() == (1, 2, 3, 4, 5) diff --git a/tests/ut/python/python_builtin/test_list_comprehension.py b/tests/ut/python/graph_syntax/statements/test_list_comprehension.py similarity index 100% rename from tests/ut/python/python_builtin/test_list_comprehension.py rename to tests/ut/python/graph_syntax/statements/test_list_comprehension.py diff --git a/tests/ut/python/fallback/test_graph_fallback_str_format.py b/tests/ut/python/graph_syntax/string/test_str_format.py similarity index 100% rename from tests/ut/python/fallback/test_graph_fallback_str_format.py rename to tests/ut/python/graph_syntax/string/test_str_format.py diff --git a/tests/ut/python/pipeline/parse/test_string_ops.py b/tests/ut/python/graph_syntax/string/test_string_ops.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_string_ops.py rename to tests/ut/python/graph_syntax/string/test_string_ops.py diff --git a/tests/ut/python/pipeline/parse/test_abs.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_abs.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_abs.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_abs.py diff --git a/tests/ut/python/pipeline/infer/test_interface_all_and_any_of_tensor.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_all_any.py similarity index 100% rename from tests/ut/python/pipeline/infer/test_interface_all_and_any_of_tensor.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_all_any.py diff --git a/tests/ut/python/pipeline/parse/test_astype.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_astype.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_astype.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_astype.py diff --git a/tests/ut/python/pipeline/parse/test_dtype_and_shape_as_attr.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_dtype_shape.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_dtype_and_shape_as_attr.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_dtype_shape.py diff --git a/tests/ut/python/pipeline/parse/test_expand_as.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_expand_as.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_expand_as.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_expand_as.py diff --git a/tests/ut/python/pipeline/parse/test_flatten.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_flatten.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_flatten.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_flatten.py diff --git a/tests/ut/python/pipeline/parse/test_mean.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_mean.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_mean.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_mean.py diff --git a/tests/ut/python/pipeline/parse/test_properties.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_properties.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_properties.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_properties.py diff --git a/tests/ut/python/pipeline/parse/test_reshape.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_reshape.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_reshape.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_reshape.py diff --git a/tests/ut/python/pipeline/parse/test_transpose.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_transpose.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_transpose.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_transpose.py diff --git a/tests/ut/python/pipeline/parse/test_view.py b/tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_view.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_view.py rename to tests/ut/python/graph_syntax/tensor/tensor_methods/test_tensor_view.py diff --git a/tests/ut/python/fallback/test_graph_fallback_tensor.py b/tests/ut/python/graph_syntax/tensor/test_graph_fallback_create_tensor.py similarity index 100% rename from tests/ut/python/fallback/test_graph_fallback_tensor.py rename to tests/ut/python/graph_syntax/tensor/test_graph_fallback_create_tensor.py diff --git a/tests/ut/python/pipeline/parse/test_tensor_zero_dimension.py b/tests/ut/python/graph_syntax/tensor/test_tensor_zero_dimension.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_tensor_zero_dimension.py rename to tests/ut/python/graph_syntax/tensor/test_tensor_zero_dimension.py index 2fc30051c89..abeb729c150 100644 --- a/tests/ut/python/pipeline/parse/test_tensor_zero_dimension.py +++ b/tests/ut/python/graph_syntax/tensor/test_tensor_zero_dimension.py @@ -25,6 +25,7 @@ from mindspore.common.initializer import One context.set_context(mode=context.GRAPH_MODE) + def test_zero_dimension_list(): Tensor([]) with pytest.raises(ValueError) as ex: diff --git a/tests/ut/python/pipeline/parse/test_call_innetr_net_attr.py b/tests/ut/python/graph_syntax/test_call_innetr_net_attr.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_call_innetr_net_attr.py rename to tests/ut/python/graph_syntax/test_call_innetr_net_attr.py diff --git a/tests/ut/python/pipeline/parse/test_celllist.py b/tests/ut/python/graph_syntax/test_celllist.py similarity index 98% rename from tests/ut/python/pipeline/parse/test_celllist.py rename to tests/ut/python/graph_syntax/test_celllist.py index 8a11c967067..ceac938f3b1 100644 --- a/tests/ut/python/pipeline/parse/test_celllist.py +++ b/tests/ut/python/graph_syntax/test_celllist.py @@ -17,7 +17,7 @@ import numpy as np from mindspore import context, nn, Tensor, Model, ParameterTuple from mindspore import dtype as mstype -from ...ut_filter import non_graph_engine +from ..ut_filter import non_graph_engine class Net(nn.Cell): diff --git a/tests/ut/python/pipeline/parse/test_number_mul_tuple.py b/tests/ut/python/graph_syntax/tuple/test_number_mul_tuple.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_number_mul_tuple.py rename to tests/ut/python/graph_syntax/tuple/test_number_mul_tuple.py index 3f88d1fe45c..fbac8a5de36 100644 --- a/tests/ut/python/pipeline/parse/test_number_mul_tuple.py +++ b/tests/ut/python/graph_syntax/tuple/test_number_mul_tuple.py @@ -29,6 +29,7 @@ class Net(nn.Cell): def construct(self): return self.number1 * self.tuple_, self.number2 * self.tuple_ + def test_number_mul_tuple(): """ Description: test_number_mul_tuple diff --git a/tests/ut/python/dtype/test_tuple.py b/tests/ut/python/graph_syntax/tuple/test_tuple.py similarity index 100% rename from tests/ut/python/dtype/test_tuple.py rename to tests/ut/python/graph_syntax/tuple/test_tuple.py diff --git a/tests/ut/python/pipeline/parse/test_tuple_index_by_negative.py b/tests/ut/python/graph_syntax/tuple/test_tuple_index_by_negative.py similarity index 100% rename from tests/ut/python/pipeline/parse/test_tuple_index_by_negative.py rename to tests/ut/python/graph_syntax/tuple/test_tuple_index_by_negative.py diff --git a/tests/ut/python/pipeline/parse/test_tuple_mul_number.py b/tests/ut/python/graph_syntax/tuple/test_tuple_mul_number.py similarity index 99% rename from tests/ut/python/pipeline/parse/test_tuple_mul_number.py rename to tests/ut/python/graph_syntax/tuple/test_tuple_mul_number.py index 5fa9ee9985a..12c426be45f 100644 --- a/tests/ut/python/pipeline/parse/test_tuple_mul_number.py +++ b/tests/ut/python/graph_syntax/tuple/test_tuple_mul_number.py @@ -29,6 +29,7 @@ class Net(nn.Cell): def construct(self): return self.tuple_ * self.number1, self.tuple_ * self.number2 + def test_tuple_mul_number(): """ Description: test_tuple_mul_number diff --git a/tests/ut/python/dtype/test_hypermap.py b/tests/ut/python/pipeline/infer/test_hypermap.py similarity index 100% rename from tests/ut/python/dtype/test_hypermap.py rename to tests/ut/python/pipeline/infer/test_hypermap.py