1# Copyright 2022 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# ============================================================================ 15import pytest 16from mindspore.ops.primitive import constexpr 17from mindspore.common.api import jit 18 19 20def _temp_func(): 21 return 0 22 23 24@constexpr(check=False) 25def _is_need_compile(func): 26 # No matter what the value of mode is, in jit scenario, this function always returns true. 27 return func is None 28 29 30@jit 31def run_in_jit(): 32 return _is_need_compile(_temp_func) 33 34 35@constexpr 36def run_in_pyhon(func): 37 # No matter what the value of mode is, in jit scenario, this function always returns true. 38 return func is None 39 40 41@pytest.mark.level1 42@pytest.mark.platform_x86_gpu_training 43@pytest.mark.env_onecard 44def test_constexpr(): 45 """ 46 Feature: test const expr 47 Description: test const expr in python native and graph 48 Expectation: success 49 """ 50 assert not run_in_pyhon(_temp_func) 51 assert run_in_jit() 52