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