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+
29import asyncio
310import threading
11+ import logging
12+ import pytest
413from tsignal .contrib .extensions .property import t_property
514from tsignal import t_signal , t_with_signals
6- import logging
715
816
917logger = logging .getLogger (__name__ )
1018
1119
1220@t_with_signals
1321class 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
3244class 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
0 commit comments