bt2: Add `Const` suffix to `_Connection` class and adapt tests
[babeltrace.git] / tests / bindings / python / bt2 / test_connection.py
CommitLineData
d2d857a8
MJ
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
811644b8 19import unittest
811644b8 20import bt2
c7e5224b 21from bt2 import connection as bt2_connection
811644b8
PP
22
23
24class ConnectionTestCase(unittest.TestCase):
25 def test_create(self):
5602ef81 26 class MyIter(bt2._UserMessageIterator):
811644b8
PP
27 def __next__(self):
28 raise bt2.Stop
29
cfbd7cf3 30 class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
66964f3f 31 def __init__(self, params, obj):
811644b8
PP
32 self._add_output_port('out')
33
34 class MySink(bt2._UserSinkComponent):
66964f3f 35 def __init__(self, params, obj):
811644b8
PP
36 self._add_input_port('in')
37
6a91742b 38 def _user_consume(self):
811644b8
PP
39 raise bt2.Stop
40
41 graph = bt2.Graph()
42 src = graph.add_component(MySource, 'src')
43 sink = graph.add_component(MySink, 'sink')
c7e5224b
FD
44 conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in'])
45 self.assertIs(type(conn), bt2_connection._ConnectionConst)
811644b8
PP
46
47 def test_downstream_port(self):
5602ef81 48 class MyIter(bt2._UserMessageIterator):
811644b8
PP
49 def __next__(self):
50 raise bt2.Stop
51
cfbd7cf3 52 class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
66964f3f 53 def __init__(self, params, obj):
811644b8
PP
54 self._add_output_port('out')
55
56 class MySink(bt2._UserSinkComponent):
66964f3f 57 def __init__(self, params, obj):
811644b8
PP
58 self._add_input_port('in')
59
6a91742b 60 def _user_consume(self):
811644b8
PP
61 raise bt2.Stop
62
63 graph = bt2.Graph()
64 src = graph.add_component(MySource, 'src')
65 sink = graph.add_component(MySink, 'sink')
cfbd7cf3 66 conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in'])
811644b8 67 self.assertEqual(conn.downstream_port.addr, sink.input_ports['in'].addr)
c7e5224b 68 self.assertIs(type(conn), bt2_connection._ConnectionConst)
811644b8
PP
69
70 def test_upstream_port(self):
5602ef81 71 class MyIter(bt2._UserMessageIterator):
811644b8
PP
72 def __next__(self):
73 raise bt2.Stop
74
cfbd7cf3 75 class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter):
66964f3f 76 def __init__(self, params, obj):
811644b8
PP
77 self._add_output_port('out')
78
79 class MySink(bt2._UserSinkComponent):
66964f3f 80 def __init__(self, params, obj):
811644b8
PP
81 self._add_input_port('in')
82
6a91742b 83 def _user_consume(self):
811644b8
PP
84 raise bt2.Stop
85
86 graph = bt2.Graph()
87 src = graph.add_component(MySource, 'src')
88 sink = graph.add_component(MySink, 'sink')
cfbd7cf3 89 conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in'])
811644b8 90 self.assertEqual(conn.upstream_port.addr, src.output_ports['out'].addr)
This page took 0.042881 seconds and 4 git commands to generate.