X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_connection.py;h=e2f7f0108927caa05658a682dd833f4a22bdc069;hp=7c1cbe5715de45e2e2d8e61dd064ab0930c6eba0;hb=0235b0db7de5bcacdb3650c92461f2ce5eb2143d;hpb=a01b452be2f3ec30264a06cb1e3da09a5fe124e9 diff --git a/tests/bindings/python/bt2/test_connection.py b/tests/bindings/python/bt2/test_connection.py index 7c1cbe57..e2f7f010 100644 --- a/tests/bindings/python/bt2/test_connection.py +++ b/tests/bindings/python/bt2/test_connection.py @@ -1,103 +1,78 @@ +# SPDX-License-Identifier: GPL-2.0-only # # Copyright (C) 2019 EfficiOS Inc. # -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# import unittest import bt2 +from bt2 import connection as bt2_connection +from bt2 import port as bt2_port class ConnectionTestCase(unittest.TestCase): def test_create(self): - class MyIter(bt2._UserMessageIterator): - def __next__(self): - raise bt2.Stop - - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): - def __init__(self, params): + class MySource( + bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator + ): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params): + def __init__(self, config, params, obj): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - graph = bt2.Graph() src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') - conn = graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) - self.assertIsInstance(conn, bt2._Connection) + conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) + self.assertIs(type(conn), bt2_connection._ConnectionConst) def test_downstream_port(self): - class MyIter(bt2._UserMessageIterator): - def __next__(self): - raise bt2.Stop - - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): - def __init__(self, params): + class MySource( + bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator + ): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params): + def __init__(self, config, params, obj): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - graph = bt2.Graph() src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') - conn = graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) self.assertEqual(conn.downstream_port.addr, sink.input_ports['in'].addr) + self.assertIs(type(conn), bt2_connection._ConnectionConst) + self.assertIs(type(conn.downstream_port), bt2_port._InputPortConst) def test_upstream_port(self): - class MyIter(bt2._UserMessageIterator): - def __next__(self): - raise bt2.Stop - - class MySource(bt2._UserSourceComponent, - message_iterator_class=MyIter): - def __init__(self, params): + class MySource( + bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator + ): + def __init__(self, config, params, obj): self._add_output_port('out') class MySink(bt2._UserSinkComponent): - def __init__(self, params): + def __init__(self, config, params, obj): self._add_input_port('in') - def _consume(self): + def _user_consume(self): raise bt2.Stop - def _graph_is_configured(self): - pass - graph = bt2.Graph() src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') - conn = graph.connect_ports(src.output_ports['out'], - sink.input_ports['in']) + conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) self.assertEqual(conn.upstream_port.addr, src.output_ports['out'].addr) + self.assertIs(type(conn.upstream_port), bt2_port._OutputPortConst) + + +if __name__ == '__main__': + unittest.main()