Skip to content

Commit 072583d

Browse files
committed
Enable ruff PT rules and fix pytest style violations
Use tuples for parametrize arg names and narrow pytest.raises blocks to contain only the single statement expected to raise.
1 parent 825b6b7 commit 072583d

File tree

7 files changed

+31
-22
lines changed

7 files changed

+31
-22
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ select = [
7373
"C4",
7474
# pep8-naming
7575
"N",
76+
# flake8-pytest-style
77+
"PT",
7678
]
7779
ignore = ["E501"] # Line too long
7880

tests/test_auth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,10 @@ async def test_login_maps_invalid_credentials_client_error(self):
523523
with (
524524
patch("boto3.client", return_value=MagicMock()),
525525
patch("warrant_lite.WarrantLite", return_value=warrant_instance),
526-
pytest.raises(NexityBadCredentialsError),
527526
):
528527
strategy = NexityAuthStrategy(credentials, session, server_config, True)
529-
await strategy.login()
528+
with pytest.raises(NexityBadCredentialsError):
529+
await strategy.login()
530530

531531
@pytest.mark.asyncio
532532
async def test_login_propagates_non_auth_client_error(self):
@@ -551,10 +551,10 @@ async def test_login_propagates_non_auth_client_error(self):
551551
with (
552552
patch("boto3.client", return_value=MagicMock()),
553553
patch("warrant_lite.WarrantLite", return_value=warrant_instance),
554-
pytest.raises(ClientError, match="InternalErrorException"),
555554
):
556555
strategy = NexityAuthStrategy(credentials, session, server_config, True)
557-
await strategy.login()
556+
with pytest.raises(ClientError, match="InternalErrorException"):
557+
await strategy.login()
558558

559559

560560
class TestRexelAuthStrategy:

tests/test_case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_lowercase_key_unchanged(self):
4848
assert decamelize({"nparams": 0}) == {"nparams": 0}
4949

5050
@pytest.mark.parametrize(
51-
"camel, expected",
51+
("camel", "expected"),
5252
[
5353
("deviceURL", "device_url"),
5454
("placeOID", "place_oid"),

tests/test_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def test_get_devices_basic(self, client: OverkizClient):
7070
assert len(devices) == 23
7171

7272
@pytest.mark.parametrize(
73-
"fixture_name, event_length",
73+
("fixture_name", "event_length"),
7474
[
7575
("events.json", 16),
7676
("local_events.json", 3),
@@ -228,7 +228,7 @@ async def test_fetch_events_casting(self, client: OverkizClient, fixture_name: s
228228
assert isinstance(state.value, dict)
229229

230230
@pytest.mark.parametrize(
231-
"fixture_name, device_count, gateway_count",
231+
("fixture_name", "device_count", "gateway_count"),
232232
[
233233
("setup_3_gateways.json", 37, 3),
234234
("setup_cozytouch.json", 12, 1),
@@ -365,7 +365,7 @@ async def test_get_diagnostic_data_without_masking(self, client: OverkizClient):
365365
obfuscate.assert_not_called()
366366

367367
@pytest.mark.parametrize(
368-
"fixture_name, exception, status_code",
368+
("fixture_name", "exception", "status_code"),
369369
[
370370
("cloud/503-empty.html", exceptions.ServiceUnavailableError, 503),
371371
("cloud/503-maintenance.html", exceptions.MaintenanceError, 503),
@@ -550,16 +550,16 @@ async def test_check_response_exception_handling(
550550
exception: Exception,
551551
):
552552
"""Ensure client raises the correct error for various error fixtures/status codes."""
553-
with pytest.raises(exception):
554-
if fixture_name:
555-
with open(
556-
os.path.join(CURRENT_DIR, "fixtures/exceptions/" + fixture_name),
557-
encoding="utf-8",
558-
) as raw_events:
559-
resp = MockResponse(raw_events.read(), status_code)
560-
else:
561-
resp = MockResponse(None, status_code)
553+
if fixture_name:
554+
with open(
555+
os.path.join(CURRENT_DIR, "fixtures/exceptions/" + fixture_name),
556+
encoding="utf-8",
557+
) as raw_events:
558+
resp = MockResponse(raw_events.read(), status_code)
559+
else:
560+
resp = MockResponse(None, status_code)
562561

562+
with pytest.raises(exception):
563563
await check_response(resp)
564564

565565
@pytest.mark.asyncio
@@ -651,7 +651,7 @@ async def test_execute_action_group_omits_none_fields(self, client: OverkizClien
651651
assert cmd["name"] == "close"
652652

653653
@pytest.mark.parametrize(
654-
"fixture_name, option_name, instance",
654+
("fixture_name", "option_name", "instance"),
655655
[
656656
(
657657
"setup-options-developerMode.json",
@@ -685,7 +685,7 @@ async def test_get_setup_option(
685685
assert isinstance(option, instance)
686686

687687
@pytest.mark.parametrize(
688-
"fixture_name, scenario_count",
688+
("fixture_name", "scenario_count"),
689689
[
690690
("action-group-cozytouch.json", 9),
691691
("action-group-tahoma-box-v1.json", 17),

tests/test_models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ class TestDevice:
115115
"""Tests for Device model parsing and property extraction."""
116116

117117
@pytest.mark.parametrize(
118-
"device_url, protocol, gateway_id, device_address, subsystem_id, is_sub_device",
118+
(
119+
"device_url",
120+
"protocol",
121+
"gateway_id",
122+
"device_address",
123+
"subsystem_id",
124+
"is_sub_device",
125+
),
119126
[
120127
(
121128
"io://1234-5678-9012/10077486",

tests/test_obfuscate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TestObfucscate:
1212
"""Tests for obfuscation utilities (emails and sensitive data)."""
1313

1414
@pytest.mark.parametrize(
15-
"email, obfuscated",
15+
("email", "obfuscated"),
1616
[
1717
("contact@somfy.com", "c****@****y.com"),
1818
("contact_-_nexity.com", "c****@****y.com"),

tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_create_local_server_config_by_ip(self):
4343
assert local_server.configuration_url == "https://somfy.com"
4444

4545
@pytest.mark.parametrize(
46-
"gateway_id, overkiz_gateway",
46+
("gateway_id", "overkiz_gateway"),
4747
[
4848
("1234-5678-6968", True),
4949
("SOMFY_PROTECT-v0NT53occUBPyuJRzx59kalW1hFfzimN", False),

0 commit comments

Comments
 (0)