Skip to content

Commit fdfe1b1

Browse files
python(chore): enable ruff PT linter (#341)
1 parent ed9b20d commit fdfe1b1

7 files changed

Lines changed: 21 additions & 17 deletions

File tree

python/lib/sift_client/.ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ select = [
3939
"LOG", # flake8-logging - logging best practices
4040

4141
# Tests
42-
# "PT", # flake8-pytest-style - pytest best practices # TODO: FD-59
42+
"PT", # flake8-pytest-style - pytest best practices
4343

4444
]
4545

python/lib/sift_client/_tests/resources/test_calculated_channels.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_calculated_channel(calculated_channels_api_sync):
5252
return calculated_channels[0]
5353

5454

55-
@pytest.fixture(scope="function")
55+
@pytest.fixture
5656
def new_calculated_channel(calculated_channels_api_sync, sift_client):
5757
"""Create a test calculated channel for update tests."""
5858
from datetime import datetime, timezone
@@ -450,7 +450,9 @@ async def test_update_with_invalid_expression(
450450
assert updated_calc_channel.expression == "invalid_expression"
451451
except Exception as e:
452452
# If server validates and rejects, that's also acceptable behavior
453-
assert "expression" in str(e).lower() or "invalid" in str(e).lower()
453+
assert ( # noqa: PT017
454+
"expression" in str(e).lower() or "invalid" in str(e).lower()
455+
)
454456
finally:
455457
await calculated_channels_api_async.archive(new_calculated_channel.id_)
456458

python/lib/sift_client/_tests/resources/test_ingestion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_client_binding(sift_client):
2929
assert sift_client.async_.ingestion
3030

3131

32-
@pytest.fixture(scope="function")
32+
@pytest.fixture
3333
def test_run(sift_client: SiftClient):
3434
"""Create a test run for ingestion tests."""
3535
run = sift_client.runs.create(

python/lib/sift_client/_tests/resources/test_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def test_archive_and_delete_test_report(self, sift_client):
321321
assert deleted_report is None # Shouldn't reach here so error if we get something.
322322
except aiogrpc.AioRpcError as e:
323323
self.test_reports.pop("basic_test_report")
324-
assert e.code() == grpc.StatusCode.NOT_FOUND
324+
assert e.code() == grpc.StatusCode.NOT_FOUND # noqa: PT017
325325

326326
def test_import_test_report(self, sift_client):
327327
# Import a test report from a file

python/lib/sift_client/_tests/resources/test_rules.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_rule(rules_api_sync):
5454
return rules[0]
5555

5656

57-
@pytest.fixture(scope="function")
57+
@pytest.fixture
5858
def new_rule(rules_api_sync, sift_client):
5959
"""Create a test rule for update tests."""
6060
from datetime import datetime, timezone
@@ -558,7 +558,9 @@ async def test_update_with_invalid_expression(self, rules_api_async, new_rule):
558558
assert updated_rule.expression == "invalid_expression"
559559
except Exception as e:
560560
# If server validates and rejects, that's also acceptable behavior
561-
assert "expression" in str(e).lower() or "invalid" in str(e).lower()
561+
assert ( # noqa: PT017
562+
"expression" in str(e).lower() or "invalid" in str(e).lower()
563+
)
562564
finally:
563565
await rules_api_async.archive(new_rule.id_)
564566

python/lib/sift_client/_tests/resources/test_runs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_run(runs_api_sync):
4646
return runs[0]
4747

4848

49-
@pytest.fixture(scope="function")
49+
@pytest.fixture
5050
def new_run(runs_api_sync):
5151
"""Create a test run for update tests."""
5252
run_name = f"test_run_update_{datetime.now(timezone.utc).isoformat()}"

python/lib/sift_client/_tests/sift_types/test_base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,18 @@ def test_multiple_nested_fields_same_parent(self):
288288

289289
def test_validation_error_on_invalid_helper_field(self):
290290
"""Test that MappingHelper validation catches mismatched fields."""
291-
with pytest.raises(ValueError, match="MappingHelper created for"):
292291

293-
class InvalidModel(ModelCreate[CreateCalculatedChannelRequest]):
294-
name: str
292+
class InvalidModel(ModelCreate[CreateCalculatedChannelRequest]):
293+
name: str
295294

296-
_to_proto_helpers: ClassVar[dict[str, MappingHelper]] = {
297-
"nonexistent_field": MappingHelper(proto_attr_path="some.path"),
298-
}
295+
_to_proto_helpers: ClassVar[dict[str, MappingHelper]] = {
296+
"nonexistent_field": MappingHelper(proto_attr_path="some.path"),
297+
}
299298

300-
def _get_proto_class(self):
301-
return CreateCalculatedChannelRequest
299+
def _get_proto_class(self):
300+
return CreateCalculatedChannelRequest
302301

302+
with pytest.raises(ValueError, match="MappingHelper created for"):
303303
# This should raise during __init__
304304
InvalidModel(name="test")
305305

@@ -495,7 +495,7 @@ def _from_proto(cls, proto, sift_client=None):
495495
model = TestModel(name="test")
496496

497497
# Should not be able to modify frozen model
498-
with pytest.raises(Exception): # Pydantic raises ValidationError # noqa: B017
498+
with pytest.raises(Exception): # noqa: B017, PT011
499499
model.name = "new_name"
500500

501501

0 commit comments

Comments
 (0)