forked from avast/retdec-regression-tests-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
94 lines (76 loc) · 3.22 KB
/
test.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
A base class for all regression tests.
"""
import inspect
import unittest
from regression_tests.test_settings import TestSettings
class Test(unittest.TestCase):
"""A base class for all regression tests."""
# Prevent nosetests from considering this class as a class containing unit
# tests.
__test__ = False
# Do not limit diffs in the output from asserts. The name is in camelCase
# because it is an attribute of unittest.TestCase.
maxDiff = None
def __init__(self, settings, **kwargs):
"""
:param ~regression_tests.test_settings.TestSettings settings: The
settings of the test.
All the other arguments are passed directly into the
``unittest.TestCase``'s constructor.
All the values in `settings` have to be single values, not lists. The
reason is that `settings` correspond to the single settings for the
actual test that is being run.
"""
self._store_settings(settings)
super().__init__(**kwargs)
@property
def settings(self):
"""The settings of the test."""
return self.__dict__['settings']
@classmethod
def settings_combinations(cls, only_for_tool=None):
"""Returns all single-test-settings combinations that can be created
from all the specified test settings.
:param str only_for_tool: When given, include only tests for the given
tool.
:returns: A list of
:class:`~regression_tests.test_settings.TestSettings` instances.
For example, when two different settings are specified in the class
(e.g. ``settings1`` and ``settings2``), where each setting yields two
combinations (see the description of
:func:`~regression_tests.test_settings.TestSettings.combinations()`),
this function returns a list of four
:class:`~regression_tests.test_settings.TestSettings` instances.
"""
def are_settings_to_consider(attr):
if not isinstance(attr, TestSettings):
return False
if (only_for_tool is not None and hasattr(attr, 'tool') and
attr.tool != only_for_tool):
return False
return True
combinations = []
for _, settings in inspect.getmembers(cls, are_settings_to_consider):
combinations.extend(settings.combinations)
return combinations
def _store_settings(self, settings):
"""Stores the given settings."""
# We need to store the settings into the object's dictionary to
# override the use of the class variable when it is also named
# 'settings'. Consider the following test:
#
# class SomeTest(Test):
# settings = TestSettings( # Store into SomeTest.settings.
# arch=['x86', 'arm']
# )
#
# def test_something(self):
# print(self.settings)
#
# If we didn't override SomeTest.settings, the above test would print
#
# ['x86', 'arm']
#
# When we override it, the test correctly prints a single architecture.
self.__dict__['settings'] = settings