@@ -29,6 +29,10 @@ def assert_not_observable(fn, *args, **kwargs):
29
29
assert False , "Did not raise a 'missing label values' exception"
30
30
31
31
32
+ def assert_between (lower , value , upper , msg = "" ):
33
+ assert lower <= value <= upper , "%s is not between %s and %s%s" % (value , lower , upper , " : %s" % msg if msg else "" )
34
+
35
+
32
36
class TestCounter (aiounittest .AsyncTestCase ):
33
37
def setUp (self ):
34
38
self .registry = CollectorRegistry ()
@@ -215,7 +219,7 @@ def f():
215
219
self .assertEqual (([], None , None , None ), getargspec (f ))
216
220
217
221
f ()
218
- self . assertTrue (0.05 <= self .registry .get_sample_value ('g' ) <= 0.1 )
222
+ assert_between (0.05 , self .registry .get_sample_value ('g' ), 0.1 )
219
223
220
224
async def test_time_async_function_decorator (self ):
221
225
self .assertEqual (0 , self .registry .get_sample_value ('g' ))
@@ -227,7 +231,7 @@ async def f():
227
231
self .assertEqual (([], None , None , None ), getargspec (f ))
228
232
229
233
await f ()
230
- self . assertTrue (0.05 <= self .registry .get_sample_value ('g' ) <= 0.1 )
234
+ assert_between (0.05 , self .registry .get_sample_value ('g' ), 0.1 )
231
235
232
236
def test_function_decorator_multithread (self ):
233
237
self .assertEqual (0 , self .registry .get_sample_value ('g' ))
@@ -307,7 +311,7 @@ def f():
307
311
308
312
f ()
309
313
self .assertEqual (1 , self .registry .get_sample_value ('s_count' ))
310
- self . assertTrue (.05 < self .registry .get_sample_value ('s_sum' ) < 0.1 )
314
+ assert_between (.05 , self .registry .get_sample_value ('s_sum' ), 0.1 )
311
315
312
316
async def test_async_function_decorator (self ):
313
317
self .assertEqual (0 , self .registry .get_sample_value ('s_count' ))
@@ -320,7 +324,7 @@ async def f():
320
324
321
325
await f ()
322
326
self .assertEqual (1 , self .registry .get_sample_value ('s_count' ))
323
- self . assertTrue (.05 < self .registry .get_sample_value ('s_sum' ) < 0.1 )
327
+ assert_between (.05 , self .registry .get_sample_value ('s_sum' ), 0.1 )
324
328
325
329
def test_function_decorator_multithread (self ):
326
330
self .assertEqual (0 , self .registry .get_sample_value ('s_count' ))
@@ -475,7 +479,7 @@ def f():
475
479
f ()
476
480
self .assertEqual (1 , self .registry .get_sample_value ('h_count' ))
477
481
self .assertEqual (1 , self .registry .get_sample_value ('h_bucket' , {'le' : '+Inf' }))
478
- self . assertTrue (.05 < self .registry .get_sample_value ('h_sum' ) < 0.1 )
482
+ assert_between (.05 , self .registry .get_sample_value ('h_sum' ), 0.1 )
479
483
480
484
async def test_async_function_decorator (self ):
481
485
self .assertEqual (0 , self .registry .get_sample_value ('h_count' ))
@@ -490,7 +494,7 @@ async def f():
490
494
await f ()
491
495
self .assertEqual (1 , self .registry .get_sample_value ('h_count' ))
492
496
self .assertEqual (1 , self .registry .get_sample_value ('h_bucket' , {'le' : '+Inf' }))
493
- self . assertTrue (.05 < self .registry .get_sample_value ('h_sum' ) < 0.1 )
497
+ assert_between (.05 , self .registry .get_sample_value ('h_sum' ), 0.1 )
494
498
495
499
def test_function_decorator_multithread (self ):
496
500
self .assertEqual (0 , self .registry .get_sample_value ('h_count' ))
0 commit comments