Add owner field to connection instances
This commit is contained in:
parent
d32742b904
commit
657032ce9f
@ -68,6 +68,7 @@ def upgrade_connection(rconn: Connection) -> Connection:
|
||||
'cdr',
|
||||
LATCH if rconn.ext.latching else '',
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
@ -94,6 +95,7 @@ def downgrade_connection(rconn: Connection) -> Connection:
|
||||
None,
|
||||
int('durability: 1' in rconn.ext.offered_qos_profiles),
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -34,6 +34,7 @@ class Connection(NamedTuple):
|
||||
md5sum: str
|
||||
msgcount: int
|
||||
ext: Union[ConnectionExtRosbag1, ConnectionExtRosbag2]
|
||||
owner: object
|
||||
|
||||
|
||||
class TopicInfo(NamedTuple):
|
||||
|
||||
@ -408,7 +408,7 @@ class Reader:
|
||||
self.connections[cid] = Connection(
|
||||
*connection[0:5],
|
||||
len(self.indexes[cid]),
|
||||
connection[6],
|
||||
*connection[6:],
|
||||
)
|
||||
except ReaderError:
|
||||
self.close()
|
||||
@ -488,6 +488,7 @@ class Reader:
|
||||
callerid,
|
||||
latching,
|
||||
),
|
||||
self,
|
||||
)
|
||||
|
||||
def read_chunk_info(self) -> ChunkInfo:
|
||||
|
||||
@ -255,6 +255,7 @@ class Writer:
|
||||
callerid,
|
||||
latching,
|
||||
),
|
||||
self,
|
||||
)
|
||||
|
||||
if any(x[1:] == connection[1:] for x in self.connections.values()):
|
||||
|
||||
@ -148,6 +148,7 @@ class Reader:
|
||||
serialization_format=x['topic_metadata']['serialization_format'],
|
||||
offered_qos_profiles=x['topic_metadata'].get('offered_qos_profiles', ''),
|
||||
),
|
||||
owner=self,
|
||||
) for idx, x in enumerate(self.metadata['topics_with_message_count'])
|
||||
}
|
||||
noncdr = {
|
||||
|
||||
@ -162,6 +162,7 @@ class Writer: # pylint: disable=too-many-instance-attributes
|
||||
serialization_format=serialization_format,
|
||||
offered_qos_profiles=offered_qos_profiles,
|
||||
),
|
||||
owner=self,
|
||||
)
|
||||
for conn in self.connections.values():
|
||||
if (
|
||||
|
||||
@ -125,16 +125,25 @@ def test_convert_1to2(tmp_path: Path) -> None:
|
||||
writerinst = writer.return_value.__enter__.return_value
|
||||
|
||||
connections = [
|
||||
Connection(1, '/topic', 'typ', 'def', '', -1, ConnectionExtRosbag1(None, False)),
|
||||
Connection(2, '/topic', 'typ', 'def', '', -1, ConnectionExtRosbag1(None, True)),
|
||||
Connection(3, '/other', 'typ', 'def', '', -1, ConnectionExtRosbag1(None, False)),
|
||||
Connection(4, '/other', 'typ', 'def', '', -1, ConnectionExtRosbag1('caller', False)),
|
||||
Connection(1, '/topic', 'typ', 'def', '', -1, ConnectionExtRosbag1(None, False), None),
|
||||
Connection(2, '/topic', 'typ', 'def', '', -1, ConnectionExtRosbag1(None, True), None),
|
||||
Connection(3, '/other', 'typ', 'def', '', -1, ConnectionExtRosbag1(None, False), None),
|
||||
Connection(
|
||||
4,
|
||||
'/other',
|
||||
'typ',
|
||||
'def',
|
||||
'',
|
||||
-1,
|
||||
ConnectionExtRosbag1('caller', False),
|
||||
None,
|
||||
),
|
||||
]
|
||||
|
||||
wconnections = [
|
||||
Connection(1, '/topic', 'typ', '', '', -1, ConnectionExtRosbag2('cdr', '')),
|
||||
Connection(2, '/topic', 'typ', '', '', -1, ConnectionExtRosbag2('cdr', LATCH)),
|
||||
Connection(3, '/other', 'typ', '', '', -1, ConnectionExtRosbag2('cdr', '')),
|
||||
Connection(1, '/topic', 'typ', '', '', -1, ConnectionExtRosbag2('cdr', ''), None),
|
||||
Connection(2, '/topic', 'typ', '', '', -1, ConnectionExtRosbag2('cdr', LATCH), None),
|
||||
Connection(3, '/other', 'typ', '', '', -1, ConnectionExtRosbag2('cdr', ''), None),
|
||||
]
|
||||
|
||||
readerinst.connections = {
|
||||
@ -227,7 +236,16 @@ def test_convert_2to1(tmp_path: Path) -> None:
|
||||
writerinst = writer.return_value.__enter__.return_value
|
||||
|
||||
connections = [
|
||||
Connection(1, '/topic', 'std_msgs/msg/Bool', '', '', -1, ConnectionExtRosbag2('', '')),
|
||||
Connection(
|
||||
1,
|
||||
'/topic',
|
||||
'std_msgs/msg/Bool',
|
||||
'',
|
||||
'',
|
||||
-1,
|
||||
ConnectionExtRosbag2('', ''),
|
||||
None,
|
||||
),
|
||||
Connection(
|
||||
2,
|
||||
'/topic',
|
||||
@ -236,9 +254,28 @@ def test_convert_2to1(tmp_path: Path) -> None:
|
||||
'',
|
||||
-1,
|
||||
ConnectionExtRosbag2('', LATCH),
|
||||
None,
|
||||
),
|
||||
Connection(
|
||||
3,
|
||||
'/other',
|
||||
'std_msgs/msg/Bool',
|
||||
'',
|
||||
'',
|
||||
-1,
|
||||
ConnectionExtRosbag2('', ''),
|
||||
None,
|
||||
),
|
||||
Connection(
|
||||
4,
|
||||
'/other',
|
||||
'std_msgs/msg/Bool',
|
||||
'',
|
||||
'',
|
||||
-1,
|
||||
ConnectionExtRosbag2('', '0'),
|
||||
None,
|
||||
),
|
||||
Connection(3, '/other', 'std_msgs/msg/Bool', '', '', -1, ConnectionExtRosbag2('', '')),
|
||||
Connection(4, '/other', 'std_msgs/msg/Bool', '', '', -1, ConnectionExtRosbag2('', '0')),
|
||||
]
|
||||
|
||||
wconnections = [
|
||||
@ -250,6 +287,7 @@ def test_convert_2to1(tmp_path: Path) -> None:
|
||||
'8b94c1b53db61fb6aed406028ad6332a',
|
||||
-1,
|
||||
ConnectionExtRosbag1(None, False),
|
||||
None,
|
||||
),
|
||||
Connection(
|
||||
2,
|
||||
@ -259,6 +297,7 @@ def test_convert_2to1(tmp_path: Path) -> None:
|
||||
'8b94c1b53db61fb6aed406028ad6332a',
|
||||
-1,
|
||||
ConnectionExtRosbag1(None, True),
|
||||
None,
|
||||
),
|
||||
Connection(
|
||||
3,
|
||||
@ -268,6 +307,7 @@ def test_convert_2to1(tmp_path: Path) -> None:
|
||||
'8b94c1b53db61fb6aed406028ad6332a',
|
||||
-1,
|
||||
ConnectionExtRosbag1(None, False),
|
||||
None,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@ -82,7 +82,16 @@ def test_failure_cases(tmp_path: Path) -> None:
|
||||
bag = Writer(tmp_path / 'write')
|
||||
with pytest.raises(WriterError, match='was not opened'):
|
||||
bag.write(
|
||||
Connection(1, '/tf', 'tf_msgs/msg/tf2', '', '', 0, ConnectionExtRosbag2('cdr', '')),
|
||||
Connection(
|
||||
1,
|
||||
'/tf',
|
||||
'tf_msgs/msg/tf2',
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
ConnectionExtRosbag2('cdr', ''),
|
||||
None,
|
||||
),
|
||||
0,
|
||||
b'',
|
||||
)
|
||||
@ -95,6 +104,15 @@ def test_failure_cases(tmp_path: Path) -> None:
|
||||
|
||||
bag = Writer(tmp_path / 'notopic')
|
||||
bag.open()
|
||||
connection = Connection(1, '/tf', 'tf_msgs/msg/tf2', '', '', 0, ConnectionExtRosbag2('cdr', ''))
|
||||
connection = Connection(
|
||||
1,
|
||||
'/tf',
|
||||
'tf_msgs/msg/tf2',
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
ConnectionExtRosbag2('cdr', ''),
|
||||
None,
|
||||
)
|
||||
with pytest.raises(WriterError, match='unknown connection'):
|
||||
bag.write(connection, 42, b'\x00')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user