Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienVannson committed Nov 13, 2024
1 parent f487a1e commit fe1f4a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/betterproto/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def __new__(
mcs, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]
) -> Self:
value_map = {}

member_map = {}

new_mcs = type(
Expand Down
63 changes: 27 additions & 36 deletions tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@


def test_load_varint_too_long():
with (
BytesIO(b"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01") as stream,
pytest.raises(ValueError),
):
with BytesIO(
b"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01"
) as stream, pytest.raises(ValueError):
betterproto.load_varint(stream)

with BytesIO(b"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01") as stream:
Expand Down Expand Up @@ -84,10 +83,9 @@ def test_dump_varint_file(tmp_path):
betterproto.dump_varint(123456789, stream) # Multi-byte varint

# Check that file contents are as expected
with (
open(tmp_path / "dump_varint_file.out", "rb") as test_stream,
open(streams_path / "message_dump_file_single.expected", "rb") as exp_stream,
):
with open(tmp_path / "dump_varint_file.out", "rb") as test_stream, open(
streams_path / "message_dump_file_single.expected", "rb"
) as exp_stream:
assert betterproto.load_varint(test_stream) == betterproto.load_varint(
exp_stream
)
Expand All @@ -113,10 +111,9 @@ def test_message_dump_file_single(tmp_path):
oneof_example.dump(stream)

# Check that the outputted file is exactly as expected
with (
open(tmp_path / "message_dump_file_single.out", "rb") as test_stream,
open(streams_path / "message_dump_file_single.expected", "rb") as exp_stream,
):
with open(tmp_path / "message_dump_file_single.out", "rb") as test_stream, open(
streams_path / "message_dump_file_single.expected", "rb"
) as exp_stream:
assert test_stream.read() == exp_stream.read()


Expand All @@ -128,10 +125,9 @@ def test_message_dump_file_multiple(tmp_path):
nested_example.dump(stream)

# Check that all three Messages were outputted to the file correctly
with (
open(tmp_path / "message_dump_file_multiple.out", "rb") as test_stream,
open(streams_path / "message_dump_file_multiple.expected", "rb") as exp_stream,
):
with open(tmp_path / "message_dump_file_multiple.out", "rb") as test_stream, open(
streams_path / "message_dump_file_multiple.expected", "rb"
) as exp_stream:
assert test_stream.read() == exp_stream.read()


Expand All @@ -141,10 +137,9 @@ def test_message_dump_delimited(tmp_path):
oneof_example.dump(stream, betterproto.SIZE_DELIMITED)
nested_example.dump(stream, betterproto.SIZE_DELIMITED)

with (
open(tmp_path / "message_dump_delimited.out", "rb") as test_stream,
open(streams_path / "delimited_messages.in", "rb") as exp_stream,
):
with open(tmp_path / "message_dump_delimited.out", "rb") as test_stream, open(
streams_path / "delimited_messages.in", "rb"
) as exp_stream:
assert test_stream.read() == exp_stream.read()


Expand All @@ -170,10 +165,9 @@ def test_message_load_file_multiple():


def test_message_load_too_small():
with (
open(streams_path / "message_dump_file_single.expected", "rb") as stream,
pytest.raises(ValueError),
):
with open(
streams_path / "message_dump_file_single.expected", "rb"
) as stream, pytest.raises(ValueError):
oneof.Test().load(stream, len_oneof - 1)


Expand All @@ -186,10 +180,9 @@ def test_message_load_delimited():


def test_message_load_too_large():
with (
open(streams_path / "message_dump_file_single.expected", "rb") as stream,
pytest.raises(ValueError),
):
with open(
streams_path / "message_dump_file_single.expected", "rb"
) as stream, pytest.raises(ValueError):
oneof.Test().load(stream, len_oneof + 1)


Expand Down Expand Up @@ -279,10 +272,9 @@ def test_dump_varint_negative(tmp_path):
with pytest.raises(ValueError):
betterproto.dump_varint(beyond, stream)

with (
open(streams_path / "dump_varint_negative.expected", "rb") as exp_stream,
open(tmp_path / "dump_varint_negative.out", "rb") as test_stream,
):
with open(streams_path / "dump_varint_negative.expected", "rb") as exp_stream, open(
tmp_path / "dump_varint_negative.out", "rb"
) as test_stream:
assert test_stream.read() == exp_stream.read()


Expand All @@ -294,10 +286,9 @@ def test_dump_varint_positive(tmp_path):
betterproto.dump_varint(single_byte, stream)
betterproto.dump_varint(multi_byte, stream)

with (
open(tmp_path / "dump_varint_positive.out", "rb") as test_stream,
open(streams_path / "dump_varint_positive.expected", "rb") as exp_stream,
):
with open(tmp_path / "dump_varint_positive.out", "rb") as test_stream, open(
streams_path / "dump_varint_positive.expected", "rb"
) as exp_stream:
assert test_stream.read() == exp_stream.read()


Expand Down

0 comments on commit fe1f4a8

Please sign in to comment.