예제 #1
0
 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()
예제 #2
0
    def test_ITG_run_simulation(self, mock_print, mock_input):
        simulator = Simulator()
        mock_input.side_effect = [
            "i",  # 초기화
            "200430.055000",  # 시뮬레이션 기간 시작점
            "200430.073000",  # 시뮬레이션 기간 종료점
            "0.1",  # interval
            "1000000",  # budget
            "0",  # strategy
            "ETH",  # currency
            "1",  # 상태 출력
            "r",  # 시뮬레이션 시작
            "1",  # 상태 출력
            "s",  # 시뮬레이션 종료
            "3",  # 거래 내역 출력
            "1",  # 상태 출력
            "2",  # 수익률 출력
            "t",  # 시뮬레이터 종료
        ]
        simulator.main()

        expected_score = [
            "ready",
            "current score ==========",
            "Good Bye~",
        ]

        self.assertEqual(mock_print.call_args_list[-1][0][0],
                         expected_score[2])
        self.assertEqual(mock_print.call_args_list[-6][0][0],
                         expected_score[1])
        self.assertEqual(mock_print.call_args_list[-7][0][0],
                         expected_score[0])
예제 #3
0
 def test_print_help_print_guide_correctly(self, mock_print):
     simulator = Simulator()
     simulator.command_list = [{"guide": "orange"}]
     simulator.print_help()
     self.assertEqual(mock_print.call_args_list[0][0][0],
                      "command list =================")
     self.assertEqual(mock_print.call_args_list[1][0][0], "orange")
예제 #4
0
 def test_on_command_call_action_correclty(self):
     simulator = Simulator()
     simulator.command_list = [
         {
             "guide": "h, help          print command info",
             "cmd": ["help", "h"],
             "action": MagicMock(),
         },
         {
             "guide": "c, count         set simulation count",
             "cmd": ["count", "c"],
             "action": MagicMock(),
         },
         {
             "guide": "i, interval         set simulation interval",
             "cmd": ["interval", "i"],
             "action": MagicMock(),
         },
     ]
     simulator.on_command("h")
     simulator.on_command("coun")
     simulator.command_list[0]["action"].assert_called_once()
     simulator.command_list[1]["action"].assert_not_called()
     simulator.on_command("iNTERval")
     simulator.command_list[2]["action"].assert_called_once()
예제 #5
0
    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()
예제 #6
0
 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")
예제 #7
0
    def test_ITG_run_single_simulation(self, mock_print):
        budget = 100000
        interval = 0.01
        from_dash_to = "200430.055000-200430.073000"
        simulator = Simulator(
            budget=1000000,
            interval=interval,
            strategy=0,
            from_dash_to=from_dash_to,
            currency="BTC",
        )

        simulator.run_single()
        self.assertEqual(mock_print.call_args[0][0], "Good Bye~")
예제 #8
0
 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()
예제 #9
0
    def test__set_budget_should_set_value(self):
        simulator = Simulator()
        simulator._set_budget("1000000000")
        self.assertEqual(simulator.budget, 1000000000)
        self.assertEqual(type(simulator.budget), int)

        simulator._set_budget("-500")
        self.assertEqual(simulator.budget, 1000000000)
예제 #10
0
 def test_initialize_with_command_print_guide_and_call_action_correctly(
         self, mock_input):
     simulator = Simulator()
     simulator.config_list = [
         {
             "guide": "년월일.시분초 형식으로 시작 시점 입력. 예. 201220.162300",
             "value": "time_value",
             "action": MagicMock(),
         },
         {
             "guide": "년월일.시분초 형식으로 종료 시점 입력. 예. 201220.162300",
             "value": "end_value",
             "action": MagicMock(),
         },
         {
             "guide": "거래 간격 입력. 예. 1",
             "value": "interval_value",
             "action": MagicMock(),
         },
     ]
     simulator.initialize_with_command()
     simulator.config_list[0]["action"].assert_called_with("time_value")
     simulator.config_list[1]["action"].assert_called_with("end_value")
     simulator.config_list[2]["action"].assert_called_with("5")
예제 #11
0
 def test_on_command_just_print_error_message_when_invalid_command(
         self, mock_print):
     simulator = Simulator()
     simulator.command_list = [
         {
             "guide": "h, help          print command info",
             "cmd": ["help", "h"],
             "need_value": False,
         },
     ]
     simulator.execute_command = MagicMock()
     simulator.on_command("hell")
     simulator.execute_command.assert_not_called()
     mock_print.assert_called_once_with("invalid command")
예제 #12
0
 def test_initialize_call_initialize(self, mock_initialize,
                                     mock_set_interval, mock_dp, mock_tr):
     simulator = Simulator(budget=7000,
                           from_dash_to="201220.170000-201220.180000")
     simulator._make_tag = MagicMock(return_value="orange")
     simulator.interval = 0.1
     simulator.initialize()
     self.assertEqual(simulator.need_init, False)
     mock_initialize.assert_called_once()
     mock_set_interval.assert_called_once_with(0.1)
     mock_dp.assert_called_once_with(end="2020-12-20T18:00:00", count=60)
     mock_tr.assert_called_once_with(end="2020-12-20T18:00:00",
                                     count=60,
                                     budget=7000)
     simulator._make_tag.assert_called_once()
     self.assertEqual(simulator.operator.tag, "orange")
예제 #13
0
 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()
예제 #14
0
 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)
예제 #15
0
 def test_main_call_signal_to_listen_sigterm(self, mock_input, mock_signal):
     simulator = Simulator()
     simulator.main()
     mock_signal.assert_called_with(ANY, simulator.stop)
예제 #16
0
 def test_terminate_call_operator_stop(self):
     simulator = Simulator()
     simulator.operator = MagicMock()
     simulator.terminate()
     simulator.operator.stop.assert_called()
예제 #17
0
 def test__set_start_str_should_set_value(self):
     simulator = Simulator()
     simulator._set_start_str("mango")
     self.assertEqual(simulator.start_str, "mango")
예제 #18
0
 def test__set_end_str_should_set_value(self):
     simulator = Simulator()
     simulator._set_end_str("banana")
     self.assertEqual(simulator.end_str, "banana")
예제 #19
0
 def test__set_interval_should_set_value(self):
     simulator = Simulator()
     simulator._set_interval("1000.7")
     self.assertEqual(type(simulator.interval), float)
예제 #20
0
 def test__set_strategy_should_set_value(self):
     simulator = Simulator()
     simulator._set_strategy("2")
     self.assertEqual(simulator.strategy, 2)
     self.assertEqual(type(simulator.budget), int)