Convert connections attribute to list

This commit is contained in:
Marko Durkovic
2022-04-21 15:15:10 +02:00
parent f7d69e35d5
commit 34ffe96692
14 changed files with 72 additions and 74 deletions
+20 -22
View File
@@ -146,12 +146,12 @@ def test_convert_1to2(tmp_path: Path) -> None:
Connection(3, '/other', 'typ', '', '', -1, ConnectionExtRosbag2('cdr', ''), None),
]
readerinst.connections = {
1: connections[0],
2: connections[1],
3: connections[2],
4: connections[3],
}
readerinst.connections = [
connections[0],
connections[1],
connections[2],
connections[3],
]
readerinst.messages.return_value = [
(connections[0], 42, b'\x42'),
@@ -160,14 +160,13 @@ def test_convert_1to2(tmp_path: Path) -> None:
(connections[3], 45, b'\x45'),
]
writerinst.connections = {}
writerinst.connections = []
def add_connection(*_: Any) -> Connection: # noqa: ANN401
"""Mock for Writer.add_connection."""
writerinst.connections = {
conn.id: conn
for _, conn in zip(range(len(writerinst.connections) + 1), wconnections)
}
writerinst.connections = [
conn for _, conn in zip(range(len(writerinst.connections) + 1), wconnections)
]
return wconnections[len(writerinst.connections) - 1]
writerinst.add_connection.side_effect = add_connection
@@ -311,12 +310,12 @@ def test_convert_2to1(tmp_path: Path) -> None:
),
]
readerinst.connections = {
1: connections[0],
2: connections[1],
3: connections[2],
4: connections[3],
}
readerinst.connections = [
connections[0],
connections[1],
connections[2],
connections[3],
]
readerinst.messages.return_value = [
(connections[0], 42, b'\x42'),
@@ -325,14 +324,13 @@ def test_convert_2to1(tmp_path: Path) -> None:
(connections[3], 45, b'\x45'),
]
writerinst.connections = {}
writerinst.connections = []
def add_connection(*_: Any) -> Connection: # noqa: ANN401
"""Mock for Writer.add_connection."""
writerinst.connections = {
conn.id: conn
for _, conn in zip(range(len(writerinst.connections) + 1), wconnections)
}
writerinst.connections = [
conn for _, conn in zip(range(len(writerinst.connections) + 1), wconnections)
]
return wconnections[len(writerinst.connections) - 1]
writerinst.add_connection.side_effect = add_connection
+2 -2
View File
@@ -126,7 +126,7 @@ def test_reader(bag: Path) -> None:
assert reader.message_count == 4
if reader.compression_mode:
assert reader.compression_format == 'zstd'
assert [*reader.connections.keys()] == [1, 2, 3]
assert [x.id for x in reader.connections] == [1, 2, 3]
assert [*reader.topics.keys()] == ['/poly', '/magn', '/joint']
gen = reader.messages()
@@ -154,7 +154,7 @@ def test_reader(bag: Path) -> None:
def test_message_filters(bag: Path) -> None:
"""Test reader filters messages."""
with Reader(bag) as reader:
magn_connections = [x for x in reader.connections.values() if x.topic == '/magn']
magn_connections = [x for x in reader.connections if x.topic == '/magn']
gen = reader.messages(connections=magn_connections)
connection, _, _ = next(gen)
assert connection.topic == '/magn'
+1 -1
View File
@@ -274,7 +274,7 @@ def test_reader(tmp_path: Path) -> None: # pylint: disable=too-many-statements
assert msgs[0][2] == b'MSGCONTENT5'
assert msgs[1][2] == b'MSGCONTENT10'
connections = [x for x in reader.connections.values() if x.topic == '/topic0']
connections = [x for x in reader.connections if x.topic == '/topic0']
msgs = list(reader.messages(connections))
assert len(msgs) == 1
assert msgs[0][2] == b'MSGCONTENT10'