Skip testcases by any env var
[functest-xtesting.git] / xtesting / ci / tier_handler.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016 Ericsson AB and others.
4 #
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
9
10 """Tier and TestCase classes to wrap the testcases config file"""
11 # pylint: disable=missing-docstring
12
13 import textwrap
14
15 import prettytable
16
17
18 LINE_LENGTH = 72
19
20
21 def split_text(text, max_len):
22     words = text.split()
23     lines = []
24     line = ""
25     for word in words:
26         if len(line) + len(word) < max_len - 1:
27             line += word + " "
28         else:
29             lines.append(line)
30             line = word + " "
31     if line != "":
32         lines.append(line)
33     return lines
34
35
36 class Tier(object):
37
38     def __init__(self, name, order, description=""):
39         self.tests_array = []
40         self.skipped_tests_array = []
41         self.name = name
42         self.order = order
43         self.description = description
44
45     def add_test(self, testcase):
46         self.tests_array.append(testcase)
47
48     def skip_test(self, testcase):
49         self.skipped_tests_array.append(testcase)
50
51     def get_tests(self):
52         array_tests = []
53         for test in self.tests_array:
54             array_tests.append(test)
55         return array_tests
56
57     def get_skipped_test(self):
58         return self.skipped_tests_array
59
60     def get_test_names(self):
61         array_tests = []
62         for test in self.tests_array:
63             array_tests.append(test.get_name())
64         return array_tests
65
66     def get_test(self, test_name):
67         if self.is_test(test_name):
68             for test in self.tests_array:
69                 if test.get_name() == test_name:
70                     return test
71         return None
72
73     def is_test(self, test_name):
74         for test in self.tests_array:
75             if test.get_name() == test_name:
76                 return True
77         return False
78
79     def get_name(self):
80         return self.name
81
82     def get_order(self):
83         return self.order
84
85     def __str__(self):
86         msg = prettytable.PrettyTable(
87             header_style='upper', padding_width=5,
88             field_names=['tiers', 'order', 'description',
89                          'testcases'])
90         msg.add_row(
91             [self.name, self.order,
92              textwrap.fill(self.description, width=40),
93              textwrap.fill(' '.join([str(x.get_name(
94                  )) for x in self.get_tests()]), width=40)])
95         return msg.get_string()
96
97
98 class TestCase(object):
99
100     def __init__(self, name, enabled, criteria, blocking,
101                  description="", project=""):
102         # pylint: disable=too-many-arguments
103         self.name = name
104         self.enabled = enabled
105         self.criteria = criteria
106         self.blocking = blocking
107         self.description = description
108         self.project = project
109
110     def get_name(self):
111         return self.name
112
113     def is_enabled(self):
114         return self.enabled
115
116     def get_criteria(self):
117         return self.criteria
118
119     def is_blocking(self):
120         return self.blocking
121
122     def get_project(self):
123         return self.project
124
125     def __str__(self):
126         msg = prettytable.PrettyTable(
127             header_style='upper', padding_width=5,
128             field_names=['test case', 'description', 'criteria'])
129         msg.add_row([self.name, textwrap.fill(self.description, width=40),
130                      self.criteria])
131         return msg.get_string()