def test_stop(ea):
 def mock_loop():
  for i in range(3):
   assert ea.running
   (yield)
  ea.stop()
 with mock.patch.object(ea, 'sleep_for', return_value=None):
  with mock.patch.object(ea, 'run_all_rules') as mock_run:
   mock_run.side_effect = mock_loop()
   start_thread = threading.Thread(target=ea.start)
   start_thread.daemon = True
   start_thread.start()
   start_thread.join(5)
   assert (not ea.running)
   assert (not start_thread.is_alive())
   assert (mock_run.call_count == 4)

def test_stop ( ea ) : def mock_loop ( ) : for i in range ( 3 ) : assert ea . running ( yield ) ea . stop ( ) with mock . patch . object ( ea , 'sleep_for' , return_value = None ) : with mock . patch . object ( ea , 'run_all_rules' ) as mock_run : mock_run . side_effect = mock_loop ( ) start_thread = threading . Thread ( target = ea . start ) start_thread . daemon = True start_thread . start ( ) start_thread . join ( 5 ) assert ( not ea . running ) assert ( not start_thread . is_alive ( ) ) assert ( mock_run . call_count == 4 )
the purpose of this test is to make sure that calling elastalerter .