• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2021-2024 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
17from functools import cached_property
18from typing import Dict, Optional
19
20from runner.options.decorator_value import value, _to_bool, _to_enum, _to_str, _to_path
21from runner.reports.report_format import ReportFormat
22
23
24class ReportOptions:
25    __DEFAULT_REPORT_FORMAT = ReportFormat.LOG
26
27    def __str__(self) -> str:
28        return _to_str(self, 1)
29
30    def to_dict(self) -> Dict[str, object]:
31        return {
32            "report-format": self.report_format.value.upper(),
33            "detailed-report": self.detailed_report,
34            "detailed-report-file": self.detailed_report_file,
35            "spec-report": self.spec_report,
36            "spec-report-file": self.spec_report_file,
37            "spec-report-yaml": self.spec_report_yaml,
38            "spec-file": self.spec_file
39        }
40
41    @cached_property
42    @value(
43        yaml_path="report.report-format",
44        cli_name="report_formats",
45        cast_to_type=lambda x: _to_enum(x, ReportFormat)
46    )
47    def report_format(self) -> ReportFormat:
48        return ReportOptions.__DEFAULT_REPORT_FORMAT
49
50    @cached_property
51    @value(
52        yaml_path="report.detailed-report",
53        cli_name="detailed_report",
54        cast_to_type=_to_bool
55    )
56    def detailed_report(self) -> bool:
57        return False
58
59    @cached_property
60    @value(
61        yaml_path="report.detailed-report-file",
62        cli_name="detailed_report_file",
63        cast_to_type=_to_path
64    )
65    def detailed_report_file(self) -> Optional[str]:
66        return None
67
68    @cached_property
69    @value(
70        yaml_path="report.spec-report",
71        cli_name="spec_report",
72        cast_to_type=_to_bool
73    )
74    def spec_report(self) -> bool:
75        return False
76
77    @cached_property
78    @value(
79        yaml_path="report.spec-report-file",
80        cli_name="spec_report_file",
81        cast_to_type=_to_path
82    )
83    def spec_report_file(self) -> Optional[str]:
84        return None
85
86    @cached_property
87    @value(
88        yaml_path="report.spec-report-yaml",
89        cli_name="spec_report_yaml",
90        cast_to_type=_to_path
91    )
92    def spec_report_yaml(self) -> Optional[str]:
93        return None
94
95    @cached_property
96    @value(
97        yaml_path="report.spec-file",
98        cli_name="spec_file",
99        cast_to_type=_to_path
100    )
101    def spec_file(self) -> Optional[str]:
102        return None
103
104    def get_command_line(self) -> str:
105        options = [
106            f'--report-format={self.report_format.value}'
107            if self.report_format != ReportOptions.__DEFAULT_REPORT_FORMAT else '',
108            '--detailed-report' if self.detailed_report else '',
109            f'--detailed-report-file={self.detailed_report_file}'
110            if self.detailed_report_file else '',
111            '--spec-report' if self.spec_report else '',
112            f'--spec-report-file={self.spec_report_file}'
113            if self.spec_report_file else '',
114            f'--spec-report-yaml={self.spec_report_yaml}'
115            if self.spec_report_yaml else '',
116            f'--spec-file={self.spec_file}'
117            if self.spec_file else ''
118        ]
119        return ' '.join(options)
120