Commit | Line | Data |
---|---|---|
0235b0db | 1 | # SPDX-License-Identifier: GPL-2.0-only |
f1f74173 PP |
2 | # |
3 | # Copyright (C) 2019 EfficiOS Inc. | |
4 | # | |
f1f74173 PP |
5 | |
6 | import unittest | |
5995b304 | 7 | |
f1f74173 PP |
8 | import bt2 |
9 | ||
10 | ||
11 | class MipTestCase(unittest.TestCase): | |
12 | def test_get_greatest_operative_mip_version(self): | |
13 | class Source1( | |
14 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
15 | ): | |
16 | @classmethod | |
17 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
18 | return [0, 1] | |
19 | ||
20 | class Source2( | |
21 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
22 | ): | |
23 | @classmethod | |
24 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
25 | return [0, 2] | |
26 | ||
27 | class Source3( | |
28 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
29 | ): | |
30 | pass | |
31 | ||
32 | descriptors = [ | |
33 | bt2.ComponentDescriptor(Source1), | |
34 | bt2.ComponentDescriptor(Source2), | |
35 | bt2.ComponentDescriptor(Source3), | |
36 | ] | |
37 | version = bt2.get_greatest_operative_mip_version(descriptors) | |
38 | self.assertEqual(version, 0) | |
39 | ||
40 | def test_get_greatest_operative_mip_version_no_match(self): | |
41 | class Source1( | |
42 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
43 | ): | |
44 | @classmethod | |
45 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
46 | return [0] | |
47 | ||
48 | class Source2( | |
49 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
50 | ): | |
51 | @classmethod | |
52 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
53 | return [1] | |
54 | ||
55 | descriptors = [ | |
56 | bt2.ComponentDescriptor(Source1), | |
57 | bt2.ComponentDescriptor(Source2), | |
58 | ] | |
59 | ||
60 | version = bt2.get_greatest_operative_mip_version(descriptors) | |
61 | self.assertIsNone(version) | |
62 | ||
63 | def test_get_greatest_operative_mip_version_empty_descriptors(self): | |
64 | with self.assertRaises(ValueError): | |
65 | bt2.get_greatest_operative_mip_version([]) | |
66 | ||
67 | def test_get_greatest_operative_mip_version_wrong_descriptor_type(self): | |
68 | class Source1( | |
69 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
70 | ): | |
71 | @classmethod | |
72 | def _user_get_supported_mip_versions(cls, params, obj, log_level): | |
73 | return [0, 1] | |
74 | ||
75 | descriptors = [bt2.ComponentDescriptor(Source1), object()] | |
76 | ||
77 | with self.assertRaises(TypeError): | |
78 | bt2.get_greatest_operative_mip_version(descriptors) | |
79 | ||
80 | def test_get_greatest_operative_mip_version_wrong_log_level_type(self): | |
81 | class Source1( | |
82 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
83 | ): | |
84 | pass | |
85 | ||
86 | descriptors = [bt2.ComponentDescriptor(Source1)] | |
87 | ||
88 | with self.assertRaises(TypeError): | |
f5567ea8 | 89 | bt2.get_greatest_operative_mip_version(descriptors, "lel") |
f1f74173 PP |
90 | |
91 | def test_get_greatest_operative_mip_version_wrong_log_level_value(self): | |
92 | class Source1( | |
93 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
94 | ): | |
95 | pass | |
96 | ||
97 | descriptors = [bt2.ComponentDescriptor(Source1)] | |
98 | ||
99 | with self.assertRaises(ValueError): | |
100 | bt2.get_greatest_operative_mip_version(descriptors, 12345) | |
101 | ||
102 | def test_get_maximal_mip_version(self): | |
103 | self.assertEqual(bt2.get_maximal_mip_version(), 0) | |
d14ddbba SM |
104 | |
105 | ||
f5567ea8 | 106 | if __name__ == "__main__": |
d14ddbba | 107 | unittest.main() |