• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding=utf-8
3
4#
5# Copyright (c) 2020-2023 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import uuid
20
21from xdevice import SuiteResult
22from xdevice import CaseResult
23
24__all__ = ["StackCaseResult", "StackStateRecorder"]
25
26
27class StackCaseResult(CaseResult):
28    parent_index = ""
29
30
31class StackStateRecorder:
32
33    def __init__(self):
34        self.current_suite_list = []
35        self.current_test = None
36        self.trace_logs = []
37        self.running_test_index = 0
38
39    def suite(self, reset=False):
40        if reset or not self.current_suite_list:
41            suite = SuiteResult()
42            suite.index = uuid.uuid4().hex
43            self.current_suite_list.append(suite)
44        return self.current_suite_list[len(self.current_suite_list) - 1]
45
46    def test(self, reset=False, test_index=None):
47        if reset or not self.current_test:
48            self.current_test = CaseResult()
49            if test_index:
50                self.current_test.index = test_index
51            else:
52                self.current_test.index = uuid.uuid4().hex
53        return self.current_test
54
55    def add_cur_suite(self, suite):
56        self.current_suite_list.append(suite)
57
58    def is_suite_empty(self):
59        return len(self.current_suite_list) == 0
60
61    def pop_last_suite(self):
62        if self.current_suite_list:
63            return self.current_suite_list.pop()
64        return None
65