Skip to content

Commit 1e17998

Browse files
committed
lint
1 parent c0d2181 commit 1e17998

File tree

4 files changed

+46
-25
lines changed

4 files changed

+46
-25
lines changed

pyproject.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ disable_error_code = ["annotation-unchecked", "assignment"]
8989
warn_return_any = false
9090
warn_unused_configs = false
9191

92+
exclude = "tests/|setup.py"
93+
9294
ignore_errors = true
93-
omit = [
94-
"tests/*",
95-
"setup.py",
96-
]

src/tsignal/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ def wrapper(self, *args, **kwargs):
238238
current_thread = threading.current_thread()
239239
if current_thread != self._thread:
240240
logger.debug("Executing regular slot from different thread")
241-
# 동기 함수는 loop.call_soon_threadsafe와 Future를 사용
242241
future = concurrent.futures.Future()
243242

244243
def callback():

tests/unit/test_property.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,60 @@
1-
import pytest
1+
"""
2+
Test cases for the property pattern.
3+
"""
4+
5+
# pylint: disable=no-member
6+
# pylint: disable=unnecessary-lambda
7+
# pylint: disable=useless-with-lock
8+
29
import asyncio
310
import threading
11+
import logging
12+
import pytest
413
from tsignal.contrib.extensions.property import t_property
514
from tsignal import t_signal, t_with_signals
6-
import logging
715

816

917
logger = logging.getLogger(__name__)
1018

1119

1220
@t_with_signals
1321
class Temperature:
22+
"""Temperature class for testing"""
23+
1424
def __init__(self):
1525
super().__init__()
1626
self._celsius = -273
1727

1828
@t_signal
1929
def celsius_changed(self):
20-
pass
30+
"""Signal for celsius change"""
2131

2232
@t_property(notify=celsius_changed)
2333
def celsius(self) -> float:
34+
"""Getter for celsius"""
2435
return self._celsius
2536

2637
@celsius.setter
2738
def celsius(self, value: float):
39+
"""Setter for celsius"""
2840
self._celsius = value
2941

3042

3143
@t_with_signals
3244
class ReadOnlyTemperature:
45+
"""ReadOnlyTemperature class for testing"""
46+
3347
def __init__(self):
3448
super().__init__()
3549
self._celsius = 0
3650

3751
@t_signal
3852
def celsius_changed(self):
39-
pass
53+
"""Signal for celsius change"""
4054

4155
@t_property(notify=celsius_changed)
4256
def celsius(self) -> float:
57+
"""Getter for celsius"""
4358
return self._celsius
4459

4560

@@ -96,9 +111,7 @@ async def test_property_thread_safety():
96111
"""Test property thread safety and notifications across threads"""
97112
temp = Temperature()
98113
received_values = []
99-
logger.debug(f"test_property_thread_safety #3")
100114
task_completed = asyncio.Event()
101-
logger.debug(f"test_property_thread_safety #4")
102115
main_loop = asyncio.get_running_loop()
103116

104117
def background_task():
@@ -122,7 +135,6 @@ async def set_temp():
122135
thread = threading.Thread(target=background_task)
123136
thread.start()
124137

125-
# asyncio.Event의 wait() 사용
126138
await task_completed.wait()
127139

128140
thread.join()
@@ -138,18 +150,20 @@ async def test_property_multiple_threads():
138150
received_values = []
139151
values_lock = threading.Lock()
140152
threads_lock = threading.Lock()
141-
NUM_THREADS = 5
153+
num_threads = 5
142154
task_completed = asyncio.Event()
143155
threads_done = 0
144156
main_loop = asyncio.get_running_loop()
145157

146158
def on_celsius_changed(value):
159+
"""Handler for celsius change"""
147160
with values_lock:
148161
received_values.append(value)
149162

150163
temp.celsius_changed.connect(on_celsius_changed)
151164

152165
def background_task(value):
166+
"""Background task for thread safety testing"""
153167
nonlocal threads_done
154168
loop = asyncio.new_event_loop()
155169
asyncio.set_event_loop(loop)
@@ -164,31 +178,31 @@ def background_task(value):
164178
with threading.Lock():
165179
nonlocal threads_done
166180
threads_done += 1
167-
if threads_done == NUM_THREADS:
181+
if threads_done == num_threads:
168182
main_loop.call_soon_threadsafe(task_completed.set)
169183

170184
threads = [
171185
threading.Thread(target=background_task, args=(i * 10,))
172-
for i in range(NUM_THREADS)
186+
for i in range(num_threads)
173187
]
174188

175-
logger.debug("Starting threads")
189+
# Start threads
176190
for thread in threads:
177191
thread.start()
178192

179-
logger.debug("Waiting for task_completed event")
193+
# Wait for task completion
180194
try:
181195
await asyncio.wait_for(task_completed.wait(), timeout=2.0)
182196
except asyncio.TimeoutError:
183197
logger.warning("Timeout waiting for threads")
184198

185-
logger.debug("Joining threads")
199+
# Join threads
186200
for thread in threads:
187201
thread.join()
188202

189203
await asyncio.sleep(0.2)
190204

191-
expected_values = set(i * 10 for i in range(NUM_THREADS))
205+
expected_values = set(i * 10 for i in range(num_threads))
192206
received_set = set(received_values)
193207

194208
assert (
@@ -207,10 +221,12 @@ def test_property_exception_handling():
207221
received_values = []
208222

209223
def handler_with_exception(value):
224+
"""Handler with exception"""
210225
received_values.append(value)
211226
raise ValueError("Test exception")
212227

213228
def normal_handler(value):
229+
"""Normal handler"""
214230
received_values.append(value * 2)
215231

216232
# Connect multiple handlers

tests/unit/test_slot.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
Test cases for the slot pattern.
33
"""
44

5+
# pylint: disable=no-member
6+
57
import asyncio
68
import threading
79
import time
10+
import logging
811
import pytest
912
from tsignal import t_with_signals, t_slot
10-
import logging
1113

1214
logger = logging.getLogger(__name__)
1315

@@ -65,6 +67,8 @@ async def test_slot_thread_safety():
6567

6668
@t_with_signals
6769
class ThreadTestReceiver:
70+
"""Receiver class for thread safety testing"""
71+
6872
def __init__(self):
6973
super().__init__()
7074
self.received_value = None
@@ -73,13 +77,15 @@ def __init__(self):
7377

7478
@t_slot
7579
async def async_slot(self, value):
80+
"""Async slot for thread safety testing"""
7681
self.execution_thread = threading.current_thread()
7782
await asyncio.sleep(0.1) # work simulation with sleep
7883
self.received_value = value
7984
self.received_count += 1
8085

8186
@t_slot
8287
def sync_slot(self, value):
88+
"""Sync slot for thread safety testing"""
8389
self.execution_thread = threading.current_thread()
8490
time.sleep(0.1) # work simulation with sleep
8591
self.received_value = value
@@ -91,6 +97,7 @@ def sync_slot(self, value):
9197
initial_values = {"value": None, "count": 0} # save initial values
9298

9399
def background_task():
100+
"""Background task for thread safety testing"""
94101
try:
95102
# Before async_slot call
96103
initial_values["value"] = receiver.received_value
@@ -121,6 +128,7 @@ def background_task():
121128
task_completed.set()
122129

123130
async def run_test():
131+
"""Run test for thread safety"""
124132
thread = threading.Thread(target=background_task)
125133
thread.start()
126134

@@ -132,20 +140,20 @@ async def run_test():
132140
# Cleanup
133141
pending = asyncio.all_tasks(receiver._loop)
134142
if pending:
135-
logger.debug(f"Cleaning up {len(pending)} pending tasks")
143+
logger.debug("Cleaning up %d pending tasks", len(pending))
136144
for task in pending:
137145
if "test_slot_thread_safety" in str(task.get_coro()):
138-
logger.debug(f"Skipping test function task: {task}")
146+
logger.debug("Skipping test function task: %s", task)
139147
else:
140-
logger.debug(f"Found application task: {task}")
148+
logger.debug("Found application task: %s", task)
141149
try:
142150
await asyncio.gather(task, return_exceptions=True)
143151
except Exception as e:
144-
logger.error(f"Error during cleanup: {e}")
152+
logger.error("Error during cleanup: %s", e)
145153
else:
146154
logger.debug("No pending tasks to clean up")
147155

148156
try:
149157
await run_test()
150158
except Exception as e:
151-
logger.error(f"Error in test: {e}")
159+
logger.error("Error in test: %s", e)

0 commit comments

Comments
 (0)