• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024 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
16""" define marks """
17import pytest
18
19
20def arg_mark(plat_marks, level_mark, card_mark, essential_mark):
21    optional_plat_marks = ['platform_ascend', 'platform_ascend910b', 'platform_gpu', 'cpu_linux', 'cpu_windows',
22                           'cpu_macos']
23    optional_level_marks = ['level0', 'level1', 'level2', 'level3', 'level4']
24    optional_card_marks = ['onecard', 'allcards']
25    optional_essential_marks = ['essential', 'unessential']
26    if not plat_marks or not set(plat_marks).issubset(set(optional_plat_marks)):
27        raise ValueError("wrong plat_marks values")
28    if level_mark not in optional_level_marks:
29        raise ValueError("wrong level_mark value")
30    if card_mark not in optional_card_marks:
31        raise ValueError("wrong card_mark value")
32    if essential_mark not in optional_essential_marks:
33        raise ValueError("wrong essential_mark value")
34
35    def decorator(func):
36        for plat_mark in plat_marks:
37            func = getattr(pytest.mark, plat_mark)(func)
38        func = getattr(pytest.mark, level_mark)(func)
39        func = getattr(pytest.mark, card_mark)(func)
40        func = getattr(pytest.mark, essential_mark)(func)
41        return func
42
43    return decorator
44