Commit | Line | Data |
---|---|---|
c4239792 | 1 | from bt2 import value |
811644b8 PP |
2 | import unittest |
3 | import copy | |
4 | import bt2 | |
5 | ||
6 | ||
7 | class UserComponentTestCase(unittest.TestCase): | |
8 | @staticmethod | |
9 | def _create_comp(comp_cls, name=None): | |
10 | graph = bt2.Graph() | |
11 | ||
12 | if name is None: | |
13 | name = 'comp' | |
14 | ||
1c9ed2ff | 15 | return graph.add_sink_component(comp_cls, name) |
811644b8 PP |
16 | |
17 | def test_name(self): | |
18 | class MySink(bt2._UserSinkComponent): | |
19 | def __init__(comp_self, params): | |
20 | self.assertEqual(comp_self.name, 'yaes') | |
21 | ||
22 | def _consume(self): | |
23 | pass | |
24 | ||
25 | comp = self._create_comp(MySink, 'yaes') | |
26 | ||
811644b8 PP |
27 | def test_class(self): |
28 | class MySink(bt2._UserSinkComponent): | |
29 | def __init__(comp_self, params): | |
30 | self.assertEqual(comp_self.component_class, MySink) | |
31 | ||
32 | def _consume(self): | |
33 | pass | |
34 | ||
35 | self._create_comp(MySink) | |
36 | ||
37 | def test_addr(self): | |
38 | class MySink(bt2._UserSinkComponent): | |
39 | def __init__(comp_self, params): | |
40 | self.assertIsInstance(comp_self.addr, int) | |
41 | self.assertNotEqual(comp_self.addr, 0) | |
42 | ||
43 | def _consume(self): | |
44 | pass | |
45 | ||
46 | self._create_comp(MySink) | |
47 | ||
48 | def test_finalize(self): | |
49 | finalized = False | |
50 | ||
51 | class MySink(bt2._UserSinkComponent): | |
52 | def _consume(self): | |
53 | pass | |
54 | ||
55 | def _finalize(comp_self): | |
56 | nonlocal finalized | |
57 | finalized = True | |
58 | ||
59 | graph = bt2.Graph() | |
1c9ed2ff SM |
60 | comp = graph.add_sink_component(MySink, 'lel') |
61 | ||
811644b8 PP |
62 | del graph |
63 | del comp | |
64 | self.assertTrue(finalized) | |
65 | ||
66 | ||
67 | class GenericComponentTestCase(unittest.TestCase): | |
68 | @staticmethod | |
69 | def _create_comp(comp_cls, name=None): | |
70 | graph = bt2.Graph() | |
71 | ||
72 | if name is None: | |
73 | name = 'comp' | |
74 | ||
1c9ed2ff | 75 | return graph.add_sink_component(comp_cls, name) |
811644b8 PP |
76 | |
77 | def test_name(self): | |
78 | class MySink(bt2._UserSinkComponent): | |
79 | def _consume(self): | |
80 | pass | |
81 | ||
82 | comp = self._create_comp(MySink, 'yaes') | |
83 | self.assertEqual(comp.name, 'yaes') | |
84 | ||
811644b8 PP |
85 | def test_class(self): |
86 | class MySink(bt2._UserSinkComponent): | |
87 | def _consume(self): | |
88 | pass | |
89 | ||
90 | comp = self._create_comp(MySink) | |
91 | self.assertEqual(comp.component_class, MySink) | |
92 | ||
93 | def test_addr(self): | |
94 | class MySink(bt2._UserSinkComponent): | |
95 | def _consume(self): | |
96 | pass | |
97 | ||
98 | comp = self._create_comp(MySink) | |
99 | self.assertIsInstance(comp.addr, int) | |
100 | self.assertNotEqual(comp.addr, 0) |