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:
71 if test.get_name() == test_name:
75 def is_test(self, test_name):
76 for test in self.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):
105 def __init__(self, name, enabled, dependency, criteria, blocking,
106 description="", project=""):
107 # pylint: disable=too-many-arguments
109 self.enabled = enabled
110 self.dependency = dependency
111 self.criteria = criteria
112 self.blocking = blocking
113 self.description = description
114 self.project = project
118 return item is None or item == ""
120 def is_compatible(self, ci_installer, ci_scenario):
122 if not self.is_none(ci_installer):
123 if re.search(self.dependency.get_installer(),
124 ci_installer) is None:
126 if not self.is_none(ci_scenario):
127 if re.search(self.dependency.get_scenario(),
128 ci_scenario) is None:
137 def is_enabled(self):
140 def get_criteria(self):
143 def is_blocking(self):
146 def get_project(self):
150 msg = prettytable.PrettyTable(
151 header_style='upper', padding_width=5,
152 field_names=['test case', 'description', 'criteria', 'dependency'])
153 msg.add_row([self.name, textwrap.fill(self.description, width=40),
154 self.criteria, self.dependency])
155 return msg.get_string()
158 class Dependency(object):
160 def __init__(self, installer, scenario):
161 self.installer = installer
162 self.scenario = scenario
164 def get_installer(self):
165 return self.installer
167 def get_scenario(self):
171 delimitator = "\n" if self.get_installer(
172 ) and self.get_scenario() else ""
173 return "{}{}{}".format(self.get_installer(), delimitator,