Skip to content

Commit

Permalink
Update ruff and run ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshilliard authored and abn committed Jan 16, 2025
1 parent dbc612c commit 6a65ca9
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.9.1
hooks:
- id: ruff-format
args: ["--diff", "src", "tests"]
Expand Down
40 changes: 20 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dynamic = ["dependencies"]

[tool.poetry.dependencies]
# The Ruff version is pinned. To update it, also update it in .pre-commit-config.yaml
ruff = { version = "~0.7.4", optional = true }
ruff = { version = "~0.9.1", optional = true }
grpclib = "^0.4.1"
jinja2 = { version = ">=3.0.3", optional = true }
python-dateutil = "^2.8"
Expand Down
4 changes: 2 additions & 2 deletions src/betterproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,10 +2011,10 @@ def timestamp_to_json(dt: datetime) -> str:
return f"{result}Z"
if (nanos % 1e6) == 0:
# Serialize 3 fractional digits.
return f"{result}.{int(nanos // 1e6) :03d}Z"
return f"{result}.{int(nanos // 1e6):03d}Z"
if (nanos % 1e3) == 0:
# Serialize 6 fractional digits.
return f"{result}.{int(nanos // 1e3) :06d}Z"
return f"{result}.{int(nanos // 1e3):06d}Z"
# Serialize 9 fractional digits.
return f"{result}.{nanos:09d}"

Expand Down
18 changes: 9 additions & 9 deletions tests/grpc/test_grpclib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ async def _test_client(client: ThingServiceClient, name="clean room", **kwargs):

def _assert_request_meta_received(deadline, metadata):
def server_side_test(stream):
assert stream.deadline._timestamp == pytest.approx(
deadline._timestamp, 1
), "The provided deadline should be received serverside"
assert (
stream.metadata["authorization"] == metadata["authorization"]
), "The provided authorization metadata should be received serverside"
assert stream.deadline._timestamp == pytest.approx(deadline._timestamp, 1), (
"The provided deadline should be received serverside"
)
assert stream.metadata["authorization"] == metadata["authorization"], (
"The provided authorization metadata should be received serverside"
)

return server_side_test

Expand Down Expand Up @@ -265,9 +265,9 @@ async def test_async_gen_for_stream_stream_request():
else:
# No more things to send make sure channel is closed
request_chan.close()
assert response_index == len(
expected_things
), "Didn't receive all expected responses"
assert response_index == len(expected_things), (
"Didn't receive all expected responses"
)


@pytest.mark.asyncio
Expand Down
18 changes: 9 additions & 9 deletions tests/inputs/casing/test_casing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

def test_message_attributes():
message = Test()
assert hasattr(
message, "snake_case_message"
), "snake_case field name is same in python"
assert hasattr(message, "snake_case_message"), (
"snake_case field name is same in python"
)
assert hasattr(message, "camel_case"), "CamelCase field is snake_case in python"
assert hasattr(message, "uppercase"), "UPPERCASE field is lowercase in python"


def test_message_casing():
assert hasattr(
casing, "SnakeCaseMessage"
), "snake_case Message name is converted to CamelCase in python"
assert hasattr(casing, "SnakeCaseMessage"), (
"snake_case Message name is converted to CamelCase in python"
)


def test_enum_casing():
assert hasattr(
casing, "MyEnum"
), "snake_case Enum name is converted to CamelCase in python"
assert hasattr(casing, "MyEnum"), (
"snake_case Enum name is converted to CamelCase in python"
)
12 changes: 6 additions & 6 deletions tests/inputs/casing_inner_class/test_casing_inner_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


def test_message_casing_inner_class_name():
assert hasattr(
casing_inner_class, "TestInnerClass"
), "Inline defined Message is correctly converted to CamelCase"
assert hasattr(casing_inner_class, "TestInnerClass"), (
"Inline defined Message is correctly converted to CamelCase"
)


def test_message_casing_inner_class_attributes():
message = casing_inner_class.Test()
assert hasattr(
message.inner, "old_exp"
), "Inline defined Message attribute is snake_case"
assert hasattr(message.inner, "old_exp"), (
"Inline defined Message attribute is snake_case"
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

def test_message_casing():
message = Test()
assert hasattr(
message, "uppercase"
), "UPPERCASE attribute is converted to 'uppercase' in python"
assert hasattr(
message, "uppercase_v2"
), "UPPERCASE_V2 attribute is converted to 'uppercase_v2' in python"
assert hasattr(
message, "upper_camel_case"
), "UPPER_CAMEL_CASE attribute is converted to upper_camel_case in python"
assert hasattr(message, "uppercase"), (
"UPPERCASE attribute is converted to 'uppercase' in python"
)
assert hasattr(message, "uppercase_v2"), (
"UPPERCASE_V2 attribute is converted to 'uppercase_v2' in python"
)
assert hasattr(message, "upper_camel_case"), (
"UPPER_CAMEL_CASE attribute is converted to upper_camel_case in python"
)
6 changes: 3 additions & 3 deletions tests/inputs/enum/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def test_enum_is_comparable_with_int():


def test_enum_to_dict():
assert (
"choice" not in Test(choice=Choice.ZERO).to_dict()
), "Default enum value is not serialized"
assert "choice" not in Test(choice=Choice.ZERO).to_dict(), (
"Default enum value is not serialized"
)
assert (
Test(choice=Choice.ZERO).to_dict(include_default_values=True)["choice"]
== "ZERO"
Expand Down
12 changes: 6 additions & 6 deletions tests/test_get_ref_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def test_reference_google_wellknown_types_non_wrappers(
)

assert name == expected_name
assert imports.__contains__(
expected_import
), f"{expected_import} not found in {imports}"
assert imports.__contains__(expected_import), (
f"{expected_import} not found in {imports}"
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -102,9 +102,9 @@ def test_reference_google_wellknown_types_non_wrappers_pydantic(
)

assert name == expected_name
assert imports.__contains__(
expected_import
), f"{expected_import} not found in {imports}"
assert imports.__contains__(expected_import), (
f"{expected_import} not found in {imports}"
)


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
def test_version():
with PROJECT_TOML.open() as toml_file:
project_config = tomlkit.loads(toml_file.read())
assert (
__version__ == project_config["project"]["version"]
), "Project version should match in package and package config"
assert __version__ == project_config["project"]["version"], (
"Project version should match in package and package config"
)

0 comments on commit 6a65ca9

Please sign in to comment.