tests: remove unnecessary message iterator classes
[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
5813b3a3 22from bt2 import port as bt2_port
811644b8
PP
23
24
25class ConnectionTestCase(unittest.TestCase):
26 def test_create(self):
5c61fb9d
SM
27 class MySource(
28 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
29 ):
59225a3e 30 def __init__(self, config, params, obj):
811644b8
PP
31 self._add_output_port('out')
32
33 class MySink(bt2._UserSinkComponent):
59225a3e 34 def __init__(self, config, params, obj):
811644b8
PP
35 self._add_input_port('in')
36
6a91742b 37 def _user_consume(self):
811644b8
PP
38 raise bt2.Stop
39
40 graph = bt2.Graph()
41 src = graph.add_component(MySource, 'src')
42 sink = graph.add_component(MySink, 'sink')
c7e5224b
FD
43 conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in'])
44 self.assertIs(type(conn), bt2_connection._ConnectionConst)
811644b8
PP
45
46 def test_downstream_port(self):
5c61fb9d
SM
47 class MySource(
48 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
49 ):
59225a3e 50 def __init__(self, config, params, obj):
811644b8
PP
51 self._add_output_port('out')
52
53 class MySink(bt2._UserSinkComponent):
59225a3e 54 def __init__(self, config, params, obj):
811644b8
PP
55 self._add_input_port('in')
56
6a91742b 57 def _user_consume(self):
811644b8
PP
58 raise bt2.Stop
59
60 graph = bt2.Graph()
61 src = graph.add_component(MySource, 'src')
62 sink = graph.add_component(MySink, 'sink')
cfbd7cf3 63 conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in'])
811644b8 64 self.assertEqual(conn.downstream_port.addr, sink.input_ports['in'].addr)
c7e5224b 65 self.assertIs(type(conn), bt2_connection._ConnectionConst)
5813b3a3 66 self.assertIs(type(conn.downstream_port), bt2_port._InputPortConst)
811644b8
PP
67
68 def test_upstream_port(self):
5c61fb9d
SM
69 class MySource(
70 bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
71 ):
59225a3e 72 def __init__(self, config, params, obj):
811644b8
PP
73 self._add_output_port('out')
74
75 class MySink(bt2._UserSinkComponent):
59225a3e 76 def __init__(self, config, params, obj):
811644b8
PP
77 self._add_input_port('in')
78
6a91742b 79 def _user_consume(self):
811644b8
PP
80 raise bt2.Stop
81
82 graph = bt2.Graph()
83 src = graph.add_component(MySource, 'src')
84 sink = graph.add_component(MySink, 'sink')
cfbd7cf3 85 conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in'])
811644b8 86 self.assertEqual(conn.upstream_port.addr, src.output_ports['out'].addr)
5813b3a3 87 self.assertIs(type(conn.upstream_port), bt2_port._OutputPortConst)
d14ddbba
SM
88
89
90if __name__ == '__main__':
91 unittest.main()
This page took 0.052918 seconds and 4 git commands to generate.