3 # Copyright (c) 2016 Ericsson AB and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 """Tier and TestCase classes to wrap the testcases config file"""
11 # pylint: disable=missing-docstring
22 def split_text(text, max_len):
27 if len(line) + len(word) < max_len - 1:
39 def __init__(self, name, order, ci_loop, description=""):
41 self.skipped_tests_array = []
44 self.ci_loop = ci_loop
45 self.description = description
47 def add_test(self, testcase):
48 self.tests_array.append(testcase)
50 def skip_test(self, testcase):
51 self.skipped_tests_array.append(testcase)
55 for test in self.tests_array:
56 array_tests.append(test)
59 def get_skipped_test(self):
60 return self.skipped_tests_array
62 def get_test_names(self):
64 for test in self.tests_array:
65 array_tests.append(test.get_name())
68 def get_test(self, test_name):
69 if self.is_test(test_name):
70 for test in self.tests_array + self.skipped_tests_array:
71 if test.get_name() == test_name:
75 def is_test(self, test_name):
76 for test in self.tests_array + self.skipped_tests_array:
77 if test.get_name() == test_name:
87 def get_ci_loop(self):
91 msg = prettytable.PrettyTable(
92 header_style='upper', padding_width=5,
93 field_names=['tiers', 'order', 'CI Loop', 'description',
96 [self.name, self.order, self.ci_loop,
97 textwrap.fill(self.description, width=40),
98 textwrap.fill(' '.join([str(x.get_name(
99 )) for x in self.get_tests()]), width=40)])
100 return msg.get_string()
103 class TestCase(object): # pylint: disable=too-many-instance-attributes
105 def __init__(self, name, enabled, skipped, dependency, criteria, blocking,
106 description="", project=""):
107 # pylint: disable=too-many-arguments
109 self.enabled = enabled
110 self.dependency = dependency
111 self.skipped = skipped
112 self.criteria = criteria
113 self.blocking = blocking
114 self.description = description
115 self.project = project
117 def is_compatible(self, ci_installer, ci_scenario):
119 if not re.search(self.dependency.get_installer(), ci_installer):
121 if not re.search(self.dependency.get_scenario(), ci_scenario):
130 def is_enabled(self):
133 def is_skipped(self):
136 def get_criteria(self):
139 def is_blocking(self):
142 def get_project(self):
146 msg = prettytable.PrettyTable(
147 header_style='upper', padding_width=5,
148 field_names=['test case', 'description', 'criteria', 'dependency'])
149 msg.add_row([self.name, textwrap.fill(self.description, width=40),
150 self.criteria, self.dependency])
151 return msg.get_string()
154 class Dependency(object):
156 def __init__(self, installer='.*', scenario='.*'):
157 self.installer = installer
158 self.scenario = scenario
160 def get_installer(self):
161 return self.installer
163 def get_scenario(self):
167 delimitator = "\n" if self.get_installer(
168 ) and self.get_scenario() else ""
169 return "{}{}{}".format(self.get_installer(), delimitator,