bt2: add bt2.get_{greatest_operative,maximal}_mip_version()
[babeltrace.git] / tests / bindings / python / bt2 / test_mip.py
CommitLineData
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
19import unittest
20import copy
21import bt2
22
23
24class MipTestCase(unittest.TestCase):
25 def test_get_greatest_operative_mip_version(self):
26 class Source1(
27 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
28 ):
29 @classmethod
30 def _user_get_supported_mip_versions(cls, params, obj, log_level):
31 return [0, 1]
32
33 class Source2(
34 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
35 ):
36 @classmethod
37 def _user_get_supported_mip_versions(cls, params, obj, log_level):
38 return [0, 2]
39
40 class Source3(
41 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
42 ):
43 pass
44
45 descriptors = [
46 bt2.ComponentDescriptor(Source1),
47 bt2.ComponentDescriptor(Source2),
48 bt2.ComponentDescriptor(Source3),
49 ]
50 version = bt2.get_greatest_operative_mip_version(descriptors)
51 self.assertEqual(version, 0)
52
53 def test_get_greatest_operative_mip_version_no_match(self):
54 class Source1(
55 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
56 ):
57 @classmethod
58 def _user_get_supported_mip_versions(cls, params, obj, log_level):
59 return [0]
60
61 class Source2(
62 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
63 ):
64 @classmethod
65 def _user_get_supported_mip_versions(cls, params, obj, log_level):
66 return [1]
67
68 descriptors = [
69 bt2.ComponentDescriptor(Source1),
70 bt2.ComponentDescriptor(Source2),
71 ]
72
73 version = bt2.get_greatest_operative_mip_version(descriptors)
74 self.assertIsNone(version)
75
76 def test_get_greatest_operative_mip_version_empty_descriptors(self):
77 with self.assertRaises(ValueError):
78 bt2.get_greatest_operative_mip_version([])
79
80 def test_get_greatest_operative_mip_version_wrong_descriptor_type(self):
81 class Source1(
82 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
83 ):
84 @classmethod
85 def _user_get_supported_mip_versions(cls, params, obj, log_level):
86 return [0, 1]
87
88 descriptors = [bt2.ComponentDescriptor(Source1), object()]
89
90 with self.assertRaises(TypeError):
91 bt2.get_greatest_operative_mip_version(descriptors)
92
93 def test_get_greatest_operative_mip_version_wrong_log_level_type(self):
94 class Source1(
95 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
96 ):
97 pass
98
99 descriptors = [bt2.ComponentDescriptor(Source1)]
100
101 with self.assertRaises(TypeError):
102 bt2.get_greatest_operative_mip_version(descriptors, 'lel')
103
104 def test_get_greatest_operative_mip_version_wrong_log_level_value(self):
105 class Source1(
106 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
107 ):
108 pass
109
110 descriptors = [bt2.ComponentDescriptor(Source1)]
111
112 with self.assertRaises(ValueError):
113 bt2.get_greatest_operative_mip_version(descriptors, 12345)
114
115 def test_get_maximal_mip_version(self):
116 self.assertEqual(bt2.get_maximal_mip_version(), 0)
This page took 0.027314 seconds and 4 git commands to generate.