Commit | Line | Data |
---|---|---|
f1f74173 PP |
1 | # |
2 | # Copyright (C) 2019 EfficiOS Inc. | |
3 | # | |
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; only version 2 | |
7 | # of the License. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | # | |
18 | ||
19 | import unittest | |
f1f74173 PP |
20 | import bt2 |
21 | ||
22 | ||
23 | class MipTestCase(unittest.TestCase): | |
24 | def test_get_greatest_operative_mip_version(self): | |
25 | class Source1( | |
26 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
27 | ): | |
28 | @classmethod | |
29 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
30 | return [0, 1] | |
31 | ||
32 | class Source2( | |
33 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
34 | ): | |
35 | @classmethod | |
36 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
37 | return [0, 2] | |
38 | ||
39 | class Source3( | |
40 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
41 | ): | |
42 | pass | |
43 | ||
44 | descriptors = [ | |
45 | bt2.ComponentDescriptor(Source1), | |
46 | bt2.ComponentDescriptor(Source2), | |
47 | bt2.ComponentDescriptor(Source3), | |
48 | ] | |
49 | version = bt2.get_greatest_operative_mip_version(descriptors) | |
50 | self.assertEqual(version, 0) | |
51 | ||
52 | def test_get_greatest_operative_mip_version_no_match(self): | |
53 | class Source1( | |
54 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
55 | ): | |
56 | @classmethod | |
57 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
58 | return [0] | |
59 | ||
60 | class Source2( | |
61 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
62 | ): | |
63 | @classmethod | |
64 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
65 | return [1] | |
66 | ||
67 | descriptors = [ | |
68 | bt2.ComponentDescriptor(Source1), | |
69 | bt2.ComponentDescriptor(Source2), | |
70 | ] | |
71 | ||
72 | version = bt2.get_greatest_operative_mip_version(descriptors) | |
73 | self.assertIsNone(version) | |
74 | ||
75 | def test_get_greatest_operative_mip_version_empty_descriptors(self): | |
76 | with self.assertRaises(ValueError): | |
77 | bt2.get_greatest_operative_mip_version([]) | |
78 | ||
79 | def test_get_greatest_operative_mip_version_wrong_descriptor_type(self): | |
80 | class Source1( | |
81 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
82 | ): | |
83 | @classmethod | |
84 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
85 | return [0, 1] | |
86 | ||
87 | descriptors = [bt2.ComponentDescriptor(Source1), object()] | |
88 | ||
89 | with self.assertRaises(TypeError): | |
90 | bt2.get_greatest_operative_mip_version(descriptors) | |
91 | ||
92 | def test_get_greatest_operative_mip_version_wrong_log_level_type(self): | |
93 | class Source1( | |
94 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
95 | ): | |
96 | pass | |
97 | ||
98 | descriptors = [bt2.ComponentDescriptor(Source1)] | |
99 | ||
100 | with self.assertRaises(TypeError): | |
101 | bt2.get_greatest_operative_mip_version(descriptors, 'lel') | |
102 | ||
103 | def test_get_greatest_operative_mip_version_wrong_log_level_value(self): | |
104 | class Source1( | |
105 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
106 | ): | |
107 | pass | |
108 | ||
109 | descriptors = [bt2.ComponentDescriptor(Source1)] | |
110 | ||
111 | with self.assertRaises(ValueError): | |
112 | bt2.get_greatest_operative_mip_version(descriptors, 12345) | |
113 | ||
114 | def test_get_maximal_mip_version(self): | |
115 | self.assertEqual(bt2.get_maximal_mip_version(), 0) | |
d14ddbba SM |
116 | |
117 | ||
118 | if __name__ == '__main__': | |
119 | unittest.main() |