Skip to content

Commit 9138f32

Browse files
authored
chore: enable ruff SIM108, SIM102, SIM202 in tests (#1687)
1 parent 7d14578 commit 9138f32

4 files changed

Lines changed: 8 additions & 19 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,9 @@ select = [
170170
"FLY002", # too many to fix right now
171171
"PT018", # too many to fix right now
172172
"PLR0124", # too many to fix right now
173-
"SIM202" , # too many to fix right now
174173
"PT012" , # too many to fix right now
175174
"TID252", # too many to fix right now
176175
"PLR0913", # skip this one
177-
"SIM102" , # too many to fix right now
178-
"SIM108", # too many to fix right now
179176
"T201", # too many to fix right now
180177
"PT004", # nice to have
181178
]

tests/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ def time_changed_millis(millis: float | None = None) -> None:
9595
"""Call all scheduled events for a time."""
9696
loop = asyncio.get_running_loop()
9797
loop_time = loop.time()
98-
if millis is not None:
99-
mock_seconds_into_future = millis / 1000
100-
else:
101-
mock_seconds_into_future = loop_time
98+
mock_seconds_into_future = millis / 1000 if millis is not None else loop_time
10299

103100
with mock.patch("time.monotonic", return_value=mock_seconds_into_future):
104101
for task in list(loop._scheduled): # type: ignore[attr-defined]

tests/services/test_browser.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,7 @@ def mock_record_update_incoming_msg(
227227
generated = r.DNSOutgoing(const._FLAGS_QR_RESPONSE)
228228
assert generated.is_response() is True
229229

230-
if service_state_change == r.ServiceStateChange.Removed:
231-
ttl = 0
232-
else:
233-
ttl = 120
230+
ttl = 0 if service_state_change == r.ServiceStateChange.Removed else 120
234231

235232
generated.add_answer_at_time(
236233
r.DNSText(
@@ -1575,9 +1572,8 @@ async def test_close_zeroconf_without_browser_before_start_up_queries():
15751572
registration_name = f"xxxyyy.{type_}"
15761573

15771574
def on_service_state_change(zeroconf, service_type, state_change, name):
1578-
if name == registration_name:
1579-
if state_change is ServiceStateChange.Added:
1580-
service_added.set()
1575+
if name == registration_name and state_change is ServiceStateChange.Added:
1576+
service_added.set()
15811577

15821578
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
15831579
zeroconf_browser = aiozc.zeroconf
@@ -1644,9 +1640,8 @@ async def test_close_zeroconf_without_browser_after_start_up_queries():
16441640
registration_name = f"xxxyyy.{type_}"
16451641

16461642
def on_service_state_change(zeroconf, service_type, state_change, name):
1647-
if name == registration_name:
1648-
if state_change is ServiceStateChange.Added:
1649-
service_added.set()
1643+
if name == registration_name and state_change is ServiceStateChange.Added:
1644+
service_added.set()
16501645

16511646
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
16521647
zeroconf_browser = aiozc.zeroconf

tests/test_dns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_dns_address_repr(self):
7676
def test_dns_question_repr(self):
7777
question = r.DNSQuestion("irrelevant", const._TYPE_SRV, const._CLASS_IN | const._CLASS_UNIQUE)
7878
repr(question)
79-
assert not question != question
79+
assert (question != question) is False
8080

8181
def test_dns_service_repr(self):
8282
service = r.DNSService(
@@ -112,7 +112,7 @@ def test_service_info_dunder(self):
112112
addresses=[socket.inet_aton("10.0.1.2")],
113113
)
114114

115-
assert not info != info
115+
assert (info != info) is False
116116
repr(info)
117117

118118
def test_service_info_text_properties_not_given(self):

0 commit comments

Comments
 (0)