def test__print_trading_result_should_not_print_when_empty_result( self, mock_print): simulator = Simulator() simulator.operator = MagicMock() simulator.operator.get_trading_results.return_value = [] simulator._print_trading_result() simulator.operator.get_score.assert_not_called()
def test_start_call_operator_start(self): simulator = Simulator() simulator.operator = MagicMock() simulator.need_init = True simulator.start() simulator.operator.start.assert_not_called() simulator.need_init = False simulator.start() simulator.operator.start.assert_called()
def test_run_single_call_start_and_terminate(self): simulator = Simulator() simulator.start = MagicMock() simulator.initialize = MagicMock() simulator.terminate = MagicMock() simulator.operator = MagicMock() simulator.operator.state = "terminated" simulator.run_single() simulator.start.assert_called() simulator.initialize.assert_called() simulator.terminate.assert_called()
def test__print_trading_result_should_print_result_correctly( self, mock_print): simulator = Simulator() simulator.operator = MagicMock() simulator.operator.get_trading_results.return_value = [{ "date_time": "today", "type": "buy", "price": 5000, "amount": 3, }] simulator._print_trading_result() simulator.operator.get_trading_results.assert_called_once() self.assertEqual(mock_print.call_args_list[0][0][0], "@today, buy") self.assertEqual(mock_print.call_args_list[1][0][0], "5000 x 3")
def test__print_score_should_call_operator_get_score(self): simulator = Simulator() simulator.operator = MagicMock() simulator._print_score() simulator.operator.get_score.assert_called_once()
def test_terminate_call_operator_stop(self): simulator = Simulator() simulator.operator = MagicMock() simulator.terminate() simulator.operator.stop.assert_called()
def test_stop_call_operator_stop(self): simulator = Simulator() simulator.operator = MagicMock() simulator.stop(None, None) simulator.operator.stop.assert_called() self.assertEqual(simulator.need_init, True)