Update code for current linter

This commit is contained in:
Marko Durkovic
2023-03-01 20:18:38 +01:00
parent 53e3209cd5
commit 56df6c40f6
11 changed files with 37 additions and 38 deletions
+2 -2
View File
@@ -274,13 +274,13 @@ def serialize_array(
if desc.valtype == Valtype.BASE:
if desc.args == 'string':
for item in val:
pos = serialize_string(rawdata, bmap, pos, cast(str, item))
pos = serialize_string(rawdata, bmap, pos, cast('str', item))
return pos
size = SIZEMAP[desc.args]
pos = (pos + size - 1) & -size
size *= len(val)
val = cast(NDArray[numpy.int_], val)
val = cast('NDArray[numpy.int_]', val)
if (bmap is BASETYPEMAP_LE) != (sys.byteorder == 'little'):
val = val.byteswap() # no inplace on readonly array
rawdata[pos:pos + size] = memoryview(val.tobytes())
+1 -1
View File
@@ -87,7 +87,7 @@ def test_anyreader1(bags1: Sequence[Path]) -> None: # pylint: disable=redefined
reader = AnyReader(bags1)
with pytest.raises(AnyReaderError, match='seems to be empty'):
reader.open()
assert all(not x.bio for x in reader.readers)
assert all(not x.bio for x in reader.readers) # type: ignore[union-attr]
with AnyReader(bags1[:3]) as reader:
assert reader.duration == 15
+19 -18
View File
@@ -69,8 +69,7 @@ def create_message(
}, f'MSGCONTENT{msg}'.encode()
def write_bag( # pylint: disable=too-many-locals,too-many-statements
def write_bag( # pylint: disable=too-many-locals
bag: Path,
header: dict[str, bytes],
chunks: Sequence[Any] = (),
@@ -129,8 +128,8 @@ def write_bag( # pylint: disable=too-many-locals,too-many-statements
{
'op': b'\x05',
'compression': b'none',
'size': pack('<L', len(chunk_bytes))
}
'size': pack('<L', len(chunk_bytes)),
},
) + ser(chunk_bytes)
for conn, data in index.items():
chunk_bytes += ser(
@@ -139,7 +138,7 @@ def write_bag( # pylint: disable=too-many-locals,too-many-statements
'ver': pack('<L', 1),
'conn': pack('<L', conn),
'count': pack('<L', data['count']),
}
},
) + ser(data['msgs'])
chunks_bytes += chunk_bytes
@@ -151,7 +150,7 @@ def write_bag( # pylint: disable=too-many-locals,too-many-statements
'start_time': pack('<LL', start_time, 0),
'end_time': pack('<LL', end_time, 0),
'count': pack('<L', len(counts.keys())),
}
},
) + ser(b''.join([pack('<LL', x, y) for x, y in counts.items()]))
pos += len(chunk_bytes)
@@ -178,18 +177,16 @@ def test_indexdata() -> None:
x42_2_0 = IndexData(42, 2, 0)
x43_3_0 = IndexData(43, 3, 0)
# flake8: noqa
# pylint: disable=unneeded-not
assert not x42_1_0 < x42_2_0
assert x42_1_0 <= x42_2_0
assert x42_1_0 == x42_2_0
assert not x42_1_0 != x42_2_0
assert not x42_1_0 != x42_2_0 # noqa
assert x42_1_0 >= x42_2_0
assert not x42_1_0 > x42_2_0
assert x42_1_0 < x43_3_0
assert x42_1_0 <= x43_3_0
assert not x42_1_0 == x43_3_0
assert not x42_1_0 == x43_3_0 # noqa
assert x42_1_0 != x43_3_0
assert not x42_1_0 >= x43_3_0
assert not x42_1_0 > x43_3_0
@@ -215,10 +212,12 @@ def test_reader(tmp_path: Path) -> None: # pylint: disable=too-many-statements
# single message
write_bag(
bag, create_default_header(), chunks=[[
bag,
create_default_header(),
chunks=[[
create_connection(),
create_message(time=42),
]]
]],
)
with Reader(bag) as reader:
assert reader.message_count == 1
@@ -239,8 +238,8 @@ def test_reader(tmp_path: Path) -> None: # pylint: disable=too-many-statements
create_connection(),
create_message(time=10, msg=10),
create_message(time=5, msg=5),
]
]
],
],
)
with Reader(bag) as reader:
assert reader.message_count == 2
@@ -266,8 +265,8 @@ def test_reader(tmp_path: Path) -> None: # pylint: disable=too-many-statements
create_message(time=10, msg=10),
create_connection(cid=2, topic=2),
create_message(cid=2, time=5, msg=5),
]
]
],
],
)
with Reader(bag) as reader:
assert len(reader.topics.keys()) == 2
@@ -398,11 +397,13 @@ def test_failure_cases(tmp_path: Path) -> None: # pylint: disable=too-many-stat
# bad uint8 field
write_bag(
bag, create_default_header(), chunks=[[
bag,
create_default_header(),
chunks=[[
({}, {}),
create_connection(),
create_message(),
]]
]],
)
with Reader(bag) as reader, \
pytest.raises(ReaderError, match='field \'op\''):
+5 -5
View File
@@ -17,7 +17,7 @@ if TYPE_CHECKING:
def test_writer(tmp_path: Path) -> None:
"""Test Writer."""
path = (tmp_path / 'rosbag2')
path = tmp_path / 'rosbag2'
with Writer(path) as bag:
connection = bag.add_connection('/test', 'std_msgs/msg/Int8')
bag.write(connection, 42, b'\x00')
@@ -26,7 +26,7 @@ def test_writer(tmp_path: Path) -> None:
assert (path / 'rosbag2.db3').exists()
size = (path / 'rosbag2.db3').stat().st_size
path = (tmp_path / 'compress_none')
path = tmp_path / 'compress_none'
bag = Writer(path)
bag.set_compression(bag.CompressionMode.NONE, bag.CompressionFormat.ZSTD)
with bag:
@@ -37,7 +37,7 @@ def test_writer(tmp_path: Path) -> None:
assert (path / 'compress_none.db3').exists()
assert size == (path / 'compress_none.db3').stat().st_size
path = (tmp_path / 'compress_file')
path = tmp_path / 'compress_file'
bag = Writer(path)
bag.set_compression(bag.CompressionMode.FILE, bag.CompressionFormat.ZSTD)
with bag:
@@ -48,7 +48,7 @@ def test_writer(tmp_path: Path) -> None:
assert not (path / 'compress_file.db3').exists()
assert (path / 'compress_file.db3.zstd').exists()
path = (tmp_path / 'compress_message')
path = tmp_path / 'compress_message'
bag = Writer(path)
bag.set_compression(bag.CompressionMode.MESSAGE, bag.CompressionFormat.ZSTD)
with bag:
@@ -59,7 +59,7 @@ def test_writer(tmp_path: Path) -> None:
assert (path / 'compress_message.db3').exists()
assert size > (path / 'compress_message.db3').stat().st_size
path = (tmp_path / 'with_custom_data')
path = tmp_path / 'with_custom_data'
bag = Writer(path)
bag.open()
bag.set_custom_data('key1', 'value1')