@@ -236,7 +236,8 @@ def test_messages_missing_duration(self):
236236 self .assertEqual (error .exception .args [0 ], f"{ message_id } is missing 'duration' configuration option." )
237237
238238 def test_no_messages_specified_in_message_section (self ):
239- message_id = random_string ()
239+ msg_id_int = random .randint (1000 , 9999 )
240+ message_id = str (msg_id_int )
240241 message = {
241242 message_id : {
242243 'duration' : random .randint (1 , 10 ),
@@ -255,7 +256,7 @@ def test_no_messages_specified_in_message_section(self):
255256 expected_throttle_config = {
256257 'category' : {},
257258 'message' : {
258- message_id : copy .deepcopy (message [message_id ])
259+ msg_id_int : copy .deepcopy (message [message_id ])
259260 },
260261 }
261262
@@ -264,7 +265,8 @@ def test_no_messages_specified_in_message_section(self):
264265
265266 def test_single_message_specified_in_message_section (self ):
266267 messages_name = random_string ()
267- message_ids = random_string ()
268+ msg_id_int = random .randint (1000 , 9999 )
269+ message_ids = str (msg_id_int )
268270 message = {
269271 messages_name : {
270272 'duration' : random .randint (1 , 10 ),
@@ -284,17 +286,17 @@ def test_single_message_specified_in_message_section(self):
284286 expected_throttle_config = {
285287 'category' : {},
286288 'message' : {
287- message_ids : copy .deepcopy (message [messages_name ])
289+ msg_id_int : copy .deepcopy (message [messages_name ])
288290 },
289291 }
290- del expected_throttle_config ['message' ][message_ids ]['messages' ]
292+ del expected_throttle_config ['message' ][msg_id_int ]['messages' ]
291293
292294 SUT = Logger (config )
293295 self .assertDictEqual (SUT .throttle_config , expected_throttle_config )
294296
295297 def test_multiple_messages_specified_in_message_section (self ):
296298 messages_name = random_string ()
297- message_ids = [random_string (), random_string ( )]
299+ message_ids = [str ( random . randint ( 1000 , 9999 )), str ( random . randint ( 1000 , 9999 ) )]
298300 duration = random .randint (1 , 10 )
299301 max_count = random .randint (1 , 10 )
300302 message = {
@@ -319,7 +321,7 @@ def test_multiple_messages_specified_in_message_section(self):
319321 },
320322 }
321323 for message_id in message_ids :
322- expected_throttle_config ['message' ][message_id ] = {
324+ expected_throttle_config ['message' ][int ( message_id ) ] = {
323325 'duration' : duration ,
324326 'max' : max_count ,
325327 }
@@ -329,7 +331,8 @@ def test_multiple_messages_specified_in_message_section(self):
329331
330332 def test_message_id_in_list_already_specified (self ):
331333 messages_name = random_string ()
332- message_ids = random_string ()
334+ msg_id_int = random .randint (1000 , 9999 )
335+ message_ids = str (msg_id_int )
333336 message = {
334337 message_ids : {
335338 'duration' : random .randint (1 , 10 ),
@@ -357,9 +360,10 @@ def test_message_id_in_list_already_specified(self):
357360
358361 def test_message_id_already_specified (self ):
359362 messages_name = random_string ()
360- message_ids = random_string ()
363+ msg_id_int = random .randint (1000 , 9999 )
364+ message_ids = str (msg_id_int )
361365 message = {
362- messages_name : {
366+ str ( messages_name ) : {
363367 'duration' : random .randint (1 , 10 ),
364368 'max' : random .randint (1 , 10 ),
365369 'messages' : message_ids ,
@@ -385,7 +389,8 @@ def test_message_id_already_specified(self):
385389
386390 def test_is_throttled_all_level_id_set (self ):
387391 logging_level = 'ERROR'
388- message_id = random_string ()
392+ msg_id_int = random .randint (1000 , 9999 )
393+ message_id = str (msg_id_int )
389394
390395 config_dict = {
391396 'mode' : random_string (),
@@ -412,13 +417,14 @@ def test_is_throttled_all_level_id_set(self):
412417
413418 SUT = Logger (config )
414419 with mock .patch .object (Logger , '_check_message' ) as mock_check_message :
415- SUT ._is_throttled (logging_level , message_id )
420+ SUT ._is_throttled (logging_level , msg_id_int )
416421
417- mock_check_message .assert_called_once_with (message_id , config_dict ['throttle' ]['messages' ][message_id ])
422+ mock_check_message .assert_called_once_with (msg_id_int , config_dict ['throttle' ]['messages' ][message_id ])
418423
419424 def test_is_throttled_all_level_set (self ):
420425 logging_level = 'ERROR'
421- message_id = random_string ()
426+ msg_id_int = random .randint (1000 , 9999 )
427+ message_id = str (msg_id_int )
422428 random_message_id = random_string ()
423429
424430 config_dict = {
@@ -452,7 +458,8 @@ def test_is_throttled_all_level_set(self):
452458
453459 def test_is_throttled_all_set (self ):
454460 logging_level = 'ERROR'
455- message_id = random_string ()
461+ msg_id_int = random .randint (1000 , 9999 )
462+ message_id = str (msg_id_int )
456463 random_message_id = random_string ()
457464
458465 config_dict = {
@@ -485,7 +492,8 @@ def test_is_throttled_all_set(self):
485492
486493 def test_is_throttled_no_match (self ):
487494 logging_level = 'ERROR'
488- message_id = random_string ()
495+ msg_id_int = random .randint (1000 , 9999 )
496+ message_id = str (msg_id_int )
489497 random_message_id = random_string ()
490498
491499 config_dict = {
@@ -598,7 +606,8 @@ def test_trace_logged_with_debug_not_set():
598606
599607class TestThrottling (BaseTestClass ):
600608 def test_duration_is_zero (self ):
601- msg_id = random_string ()
609+ msg_id_int = random .randint (1000 , 9999 )
610+ msg_id = str (msg_id_int )
602611 duration = 0
603612 max_count = random .randint (1 , 1000 )
604613
@@ -627,14 +636,15 @@ def test_duration_is_zero(self):
627636 }
628637 }
629638
630- throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id ])
639+ throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id_int ])
631640
632641 self .assertTrue (throttle , f"SUT logged ids: { SUT .logged_ids } " )
633642 self .assertEqual (len (SUT .logged_ids ), 1 )
634643 self .assertEqual (mock_time .timer .call_count , 0 )
635644
636645 def test_first_message_duration_is_zero (self ):
637- msg_id = random_string ()
646+ msg_id_int = random .randint (1000 , 9999 )
647+ msg_id = str (msg_id_int )
638648 duration = 0
639649 max_count = random .randint (1 , 1000 )
640650
@@ -657,14 +667,15 @@ def test_first_message_duration_is_zero(self):
657667
658668 SUT = Logger (config )
659669
660- throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id ])
670+ throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id_int ])
661671
662672 self .assertTrue (throttle )
663673 self .assertEqual (len (SUT .logged_ids ), 1 )
664674 self .assertEqual (mock_time .timer .call_count , 0 )
665675
666676 def test_max_is_none (self ):
667- msg_id = random_string ()
677+ msg_id_int = random .randint (1000 , 9999 )
678+ msg_id = str (msg_id_int )
668679 duration = random .randint (60 , 600 )
669680 max_count = 'None'
670681
@@ -687,14 +698,15 @@ def test_max_is_none(self):
687698
688699 SUT = Logger (config )
689700
690- throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id ])
701+ throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id_int ])
691702
692703 self .assertFalse (throttle )
693704 self .assertEqual (len (SUT .logged_ids ), 0 )
694705 self .assertEqual (mock_time .timer .call_count , 0 )
695706
696707 def test_first_time_message_is_logged (self ):
697- msg_id = random_string ()
708+ msg_id_int = random .randint (1000 , 9999 )
709+ msg_id = str (msg_id_int )
698710 duration = random .randint (60 , 600 )
699711 max_count = random .randint (1 , 1000 )
700712 now = int (time .time ())
@@ -719,7 +731,7 @@ def test_first_time_message_is_logged(self):
719731
720732 SUT = Logger (config )
721733
722- throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id ])
734+ throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id_int ])
723735
724736 logged_ids = {
725737 msg_id : {
@@ -734,6 +746,8 @@ def test_first_time_message_is_logged(self):
734746
735747 def test_new_window (self ):
736748 msg_id = random_string ()
749+ msg_id_int = random .randint (1000 , 9999 )
750+ msg_id = str (msg_id_int )
737751 duration = random .randint (60 , 600 )
738752 max_count = random .randint (1 , 1000 )
739753 count = random .randint (1 , 100 )
@@ -766,7 +780,7 @@ def test_new_window(self):
766780 }
767781 }
768782
769- throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id ])
783+ throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id_int ])
770784
771785 logged_ids = {
772786 msg_id : {
@@ -780,7 +794,8 @@ def test_new_window(self):
780794 self .assertDictEqual (SUT .logged_ids , logged_ids )
781795
782796 def test_message_within_threshold (self ):
783- msg_id = random_string ()
797+ msg_id_int = random .randint (1000 , 9999 )
798+ msg_id = str (msg_id_int )
784799 duration = random .randint (60 , 600 )
785800 count = random .randint (1 , 100 )
786801 max_count = count + 1
@@ -813,7 +828,7 @@ def test_message_within_threshold(self):
813828 }
814829 }
815830
816- throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id ])
831+ throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id_int ])
817832
818833 logged_ids = {
819834 msg_id : {
@@ -828,7 +843,8 @@ def test_message_within_threshold(self):
828843
829844 def test_passed_threshold_multiple_times (self ):
830845 mode = random_string ()
831- msg_id = random_string ()
846+ msg_id_int = random .randint (1000 , 9999 )
847+ msg_id = str (msg_id_int )
832848 duration = random .randint (60 , 600 )
833849 max_count = random .randint (1 , 100 )
834850 count = max_count * random .randint (2 , 9 ) - 1
@@ -866,7 +882,7 @@ def test_passed_threshold_multiple_times(self):
866882 }
867883 }
868884
869- throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id ])
885+ throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id_int ])
870886
871887 logged_ids = {
872888 msg_id : {
@@ -884,7 +900,8 @@ def test_passed_threshold_multiple_times(self):
884900
885901 def test_message_is_over_threshold (self ):
886902 mode = random_string ()
887- msg_id = random_string ()
903+ msg_id_int = random .randint (1000 , 9999 )
904+ msg_id = str (msg_id_int )
888905 duration = random .randint (60 , 600 )
889906 count = random .randint (10 , 100 )
890907 max_count = count - 3
@@ -920,7 +937,7 @@ def test_message_is_over_threshold(self):
920937 }
921938 }
922939
923- throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id ])
940+ throttle = SUT ._check_message (msg_id , SUT .throttle_config ['message' ][msg_id_int ])
924941
925942 logged_ids = {
926943 msg_id : {
0 commit comments