@@ -64,7 +64,7 @@ def setup_method(self):
64
64
65
65
def test_basic_timer (self ):
66
66
"""Test basic Timer context manager functionality."""
67
- timer = Timer (silent = True )
67
+ timer = Timer (verbose = False )
68
68
69
69
with timer :
70
70
time .sleep (self .sleep_time )
@@ -75,7 +75,7 @@ def test_basic_timer(self):
75
75
76
76
def test_timer_return_value (self ):
77
77
"""Test that Timer returns self for variable assignment."""
78
- with Timer (silent = True ) as timer :
78
+ with Timer (verbose = False ) as timer :
79
79
time .sleep (self .sleep_time )
80
80
81
81
assert timer .elapsed is not None
@@ -84,17 +84,17 @@ def test_timer_return_value(self):
84
84
def test_timer_units (self ):
85
85
"""Test different time units."""
86
86
# Test seconds (default)
87
- with Timer (silent = True ) as timer_sec :
87
+ with Timer (verbose = False ) as timer_sec :
88
88
time .sleep (self .sleep_time )
89
89
expected_sec = self .sleep_time
90
90
assert_allclose (timer_sec .elapsed , expected_sec , atol = 0.05 , rtol = 2 )
91
91
92
92
# Timer always stores elapsed time in seconds regardless of display unit
93
- with Timer (unit = "milliseconds" , silent = True ) as timer_ms :
93
+ with Timer (unit = "milliseconds" , verbose = False ) as timer_ms :
94
94
time .sleep (self .sleep_time )
95
95
assert_allclose (timer_ms .elapsed , expected_sec , atol = 0.05 , rtol = 2 )
96
96
97
- with Timer (unit = "microseconds" , silent = True ) as timer_us :
97
+ with Timer (unit = "microseconds" , verbose = False ) as timer_us :
98
98
time .sleep (self .sleep_time )
99
99
assert_allclose (timer_us .elapsed , expected_sec , atol = 0.05 , rtol = 2 )
100
100
@@ -109,33 +109,33 @@ def test_invalid_unit(self):
109
109
def test_timer_precision (self ):
110
110
"""Test that precision parameter is accepted (output format tested manually)."""
111
111
# Just verify it doesn't crash with different precision values
112
- with Timer (precision = 0 , silent = True ) as timer0 :
112
+ with Timer (precision = 0 , verbose = False ) as timer0 :
113
113
time .sleep (self .sleep_time )
114
- with Timer (precision = 6 , silent = True ) as timer6 :
114
+ with Timer (precision = 6 , verbose = False ) as timer6 :
115
115
time .sleep (self .sleep_time )
116
116
117
117
assert timer0 .elapsed is not None
118
118
assert timer6 .elapsed is not None
119
119
120
120
def test_timer_message (self ):
121
121
"""Test custom message parameter (output format tested manually)."""
122
- with Timer (message = "Test operation" , silent = True ) as timer :
122
+ with Timer (message = "Test operation" , verbose = False ) as timer :
123
123
time .sleep (self .sleep_time )
124
124
125
125
assert timer .elapsed is not None
126
126
127
- def test_timer_silent_mode (self ):
128
- """Test silent mode suppresses output."""
129
- # This mainly tests that silent=True doesn't crash
127
+ def test_timer_verbose_mode (self ):
128
+ """Test verbose mode controls output."""
129
+ # This mainly tests that verbose=False doesn't crash
130
130
# Output suppression is hard to test automatically
131
- with Timer (silent = True ) as timer :
131
+ with Timer (verbose = False ) as timer :
132
132
time .sleep (self .sleep_time )
133
133
134
134
assert timer .elapsed is not None
135
135
136
136
def test_timer_exception_handling (self ):
137
137
"""Test that Timer works correctly even when exceptions occur."""
138
- timer = Timer (silent = True )
138
+ timer = Timer (verbose = False )
139
139
140
140
try :
141
141
with timer :
@@ -153,7 +153,7 @@ def test_timeit_basic(self):
153
153
def test_func ():
154
154
time .sleep (self .sleep_time )
155
155
156
- result = timeit (test_func , runs = 3 , silent = True )
156
+ result = timeit (test_func , runs = 3 , verbose = False , results = True )
157
157
158
158
# Check that we have results
159
159
assert 'elapsed' in result
@@ -177,7 +177,7 @@ def test_func_with_args(sleep_time, multiplier=1):
177
177
178
178
# Use lambda to bind arguments
179
179
func_with_args = lambda : test_func_with_args (self .sleep_time , 0.5 )
180
- result = timeit (func_with_args , runs = 2 , silent = True )
180
+ result = timeit (func_with_args , runs = 2 , verbose = False , results = True )
181
181
182
182
# Check results
183
183
assert len (result ['elapsed' ]) == 2
@@ -214,7 +214,7 @@ def test_timeit_single_run(self):
214
214
def test_func ():
215
215
time .sleep (self .sleep_time )
216
216
217
- result = timeit (test_func , runs = 1 , silent = True )
217
+ result = timeit (test_func , runs = 1 , verbose = False , results = True )
218
218
219
219
assert len (result ['elapsed' ]) == 1
220
220
assert result ['average' ] == result ['elapsed' ][0 ]
@@ -226,12 +226,12 @@ def test_timeit_different_units(self):
226
226
def test_func ():
227
227
time .sleep (self .sleep_time )
228
228
229
- # Test milliseconds (silent mode to avoid output during tests)
230
- result_ms = timeit (test_func , runs = 2 , unit = "milliseconds" , silent = True )
229
+ # Test milliseconds (verbose=False to avoid output during tests)
230
+ result_ms = timeit (test_func , runs = 2 , unit = "milliseconds" , verbose = False , results = True )
231
231
assert len (result_ms ['elapsed' ]) == 2
232
232
233
233
# Test microseconds
234
- result_us = timeit (test_func , runs = 2 , unit = "microseconds" , silent = True )
234
+ result_us = timeit (test_func , runs = 2 , unit = "microseconds" , verbose = False , results = True )
235
235
assert len (result_us ['elapsed' ]) == 2
236
236
237
237
# All results should be in seconds regardless of display unit
@@ -246,7 +246,7 @@ def test_func():
246
246
time .sleep (self .sleep_time )
247
247
248
248
# This test is mainly to ensure stats_only doesn't crash
249
- result = timeit (test_func , runs = 2 , stats_only = True , silent = True )
249
+ result = timeit (test_func , runs = 2 , stats_only = True , verbose = False , results = True )
250
250
assert len (result ['elapsed' ]) == 2
251
251
252
252
def test_timeit_invalid_timer_kwargs (self ):
@@ -260,3 +260,34 @@ def test_func():
260
260
except ValueError as e :
261
261
assert "Unknown timer parameters" in str (e )
262
262
263
+ def test_timeit_verbose_parameter (self ):
264
+ """Test verbose parameter controls output."""
265
+ def test_func ():
266
+ time .sleep (self .sleep_time )
267
+
268
+ # Test verbose=True (default) - this test can't easily verify output
269
+ # but at least checks it doesn't crash
270
+ result1 = timeit (test_func , runs = 2 , results = True )
271
+ assert result1 is not None
272
+ assert len (result1 ['elapsed' ]) == 2
273
+
274
+ # Test verbose=False - should suppress output
275
+ result2 = timeit (test_func , runs = 2 , verbose = False , results = True )
276
+ assert result2 is not None
277
+ assert len (result2 ['elapsed' ]) == 2
278
+
279
+ def test_timeit_results_parameter (self ):
280
+ """Test results parameter controls return value."""
281
+ def test_func ():
282
+ time .sleep (self .sleep_time )
283
+
284
+ # Test results=False (default) - should return None
285
+ result1 = timeit (test_func , runs = 2 , verbose = False )
286
+ assert result1 is None
287
+
288
+ # Test results=True - should return timing data
289
+ result2 = timeit (test_func , runs = 2 , verbose = False , results = True )
290
+ assert result2 is not None
291
+ assert 'elapsed' in result2
292
+ assert len (result2 ['elapsed' ]) == 2
293
+
0 commit comments