-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestSuite.py
73 lines (60 loc) · 2.43 KB
/
TestSuite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Copyright (c) 2023-2024 tracetronic GmbH
#
# SPDX-License-Identifier: MIT
# -*- coding: utf-8 -*-
"""
This module contains the TestSuite class.
"""
from typing import Union
from testguide_report_generator.model.TestCase import TestCase
from testguide_report_generator.model.TestCaseFolder import TestCaseFolder
from testguide_report_generator.util.Json2AtxRepr import Json2AtxRepr
from testguide_report_generator.util.ValidityChecks import check_name_length, validate_testcase
class TestSuite(Json2AtxRepr):
"""
ATX-TestSuite. This is the top-level element from which the `.json` report will be generated. A
testsuite must contain at least one :class:`TestCase<testguide_report_generator.TestCase.TestCase>` or
:class:`TestCaseFolder<testguide_report_generator.TestCaseFolder.TestCaseFolder>` to be test.guide compliant
"""
__test__ = False # pytest ignore
NAME_ERROR_MSG = "The name of the TestSuite must have a length between 1-120 characters."
def __init__(self, name: str, timestamp: int):
"""
Constructor
:param name: name of the TestSuite
:type name: str
:param timestamp: timestamp in milliseconds
:type timestamp: int
"""
self.__name = check_name_length(name, self.NAME_ERROR_MSG)
self.__timestamp = timestamp
self.__testcases: list[Union[TestCase, TestCaseFolder]] = []
def add_testcase(self, testcase: Union[TestCase, TestCaseFolder]):
"""
Adds a TestCase or TestCaseFolder to the TestSuite.
:param testcase: testcase to be added
:type testcase: TestCase or TestCaseFolder
:raises: ValueError, if the argument is not a TestCase or TestCaseFolder, or if an empty
TestCaseFolder was added
:return: this object
:rtype: TestSuite
"""
if validate_testcase(testcase, TestCase, TestCaseFolder):
self.__testcases.append(testcase)
return self
def get_testcases(self) -> list:
"""
:return: Testcases or TestCaseFolders
:rtype: list
"""
return self.__testcases
def create_json_repr(self) -> dict:
"""
@see: :class:`Json2AtxRepr<testguide_report_generator.Json2AtxRepr>`
"""
result = {
'name': self.__name,
'timestamp': self.__timestamp,
'testcases': [each.create_json_repr() for each in self.__testcases]
}
return result