Beispiel #1
0
    def test_log_splitter_wrong_log(self):
        """
        log_splitter should not call any other function
        if the received log is not on the correct format or
        if the log does not match any of the predicted logs
        """
        with mock.patch('core.Parser.init_game') as mockFunc1:
            with mock.patch('core.Parser.shutdown_game') as mockFunc2:
                with mock.patch('core.Parser.score_kill') as mockFunc3:
                    with mock.patch(
                            'core.Parser.userinfo_changed') as mockFunc4:
                        with mock.patch(
                                'core.Parser.client_begin') as mockFunc5:
                            with mock.patch('core.Parser.client_disconnect'
                                            ) as mockFunc6:
                                parser = Parser()
                                parser.log_splitter('blablabla anything')
                                parser.log_splitter('21:32 Item: whatever')

                                mockFunc1.assert_not_called()
                                mockFunc2.assert_not_called()
                                mockFunc3.assert_not_called()
                                mockFunc4.assert_not_called()
                                mockFunc5.assert_not_called()
                                mockFunc6.assert_not_called()
Beispiel #2
0
 def test_log_splitter(self):
     """
     log_splitter should call the correct functions, with the
     correct arguments depending on what is passed by as argument
     """
     test_cases = [{
         'path_name': 'init_game',
         'log': '0:00 InitGame: the game has begun',
         'argument': None
     }, {
         'path_name': 'shutdown_game',
         'log': '78:32 ShutdownGame: game over',
         'argument': None
     }, {
         'path_name': 'score_kill',
         'log': '89:12 Kill: Somebody died!',
         'argument': 'Somebody died!'
     }, {
         'path_name': 'userinfo_changed',
         'log': '34:45 ClientUserinfoChanged: Some info has changed',
         'argument': 'Some info has changed'
     }, {
         'path_name': 'client_disconnect',
         'log': '58:62 ClientDisconnect: Fulano DC',
         'argument': 'Fulano DC'
     }, {
         'path_name': 'client_begin',
         'log': '58:62 ClientBegin: Fulano begin',
         'argument': 'Fulano begin'
     }]
     parser = Parser()
     for params in test_cases:
         with mock.patch('core.Parser.' + params['path_name']) as mockFunc:
             parser.log_splitter(params['log'])
             if params['argument'] is None:
                 mockFunc.assert_called_with()
             else:
                 mockFunc.assert_called_once_with(params['argument'])