1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2021-2023 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17# This file does only contain a selection of the most common options. For a 18# full list see the documentation: 19# http://www.sphinx-doc.org/en/master/config 20 21from functools import cached_property 22from typing import Dict, List 23 24from runner.options.decorator_value import value, _to_str, _to_int 25 26 27class GroupsOptions: 28 __DEFAULT_GROUPS = 1 29 __DEFAULT_GROUP_NUMBER = 1 30 31 def __str__(self) -> str: 32 return _to_str(self, 2) 33 34 def to_dict(self) -> Dict[str, object]: 35 return { 36 "quantity": self.quantity, 37 "number": self.number, 38 "chapters": self.chapters, 39 "chapters-file": self.chapters_file 40 } 41 42 @cached_property 43 @value(yaml_path="test-lists.groups.quantity", cli_name="groups", cast_to_type=_to_int) 44 def quantity(self) -> int: 45 return GroupsOptions.__DEFAULT_GROUPS 46 47 @cached_property 48 @value(yaml_path="test-lists.groups.number", cli_name="group_number", cast_to_type=_to_int) 49 def number(self) -> int: 50 return GroupsOptions.__DEFAULT_GROUP_NUMBER 51 52 def get_command_line(self) -> str: 53 options = [ 54 f'--group={self.quantity}' if self.quantity != GroupsOptions.__DEFAULT_GROUPS else '', 55 f'--group-number={self.number}' if self.number != GroupsOptions.__DEFAULT_GROUP_NUMBER else '' 56 ] 57 return ' '.join(options) 58 59 @cached_property 60 @value(yaml_path="test-lists.groups.chapters", cli_name="chapters") 61 def chapters(self) -> List[str]: 62 return [] 63 64 @cached_property 65 @value(yaml_path="test-lists.groups.chapters-file", cli_name="chapters_file") 66 def chapters_file(self) -> str: 67 return "chapters.yaml" 68