def test_get_state_quarantine_sticky(self): # A crash in get_dimensions() causes sticky quarantine in get_state. from config import bot_config obj = self.make_bot() def get_dimensions(botobj): self.assertEqual(obj, botobj) return 'invalid' self.mock(bot_config, 'get_dimensions', get_dimensions) def get_dimensions_os(): return {u'os': [u'safe']} self.mock(os_utilities, 'get_dimensions', get_dimensions_os) def get_state(botobj): self.assertEqual(obj, botobj) return {'yo': 'dawh'} self.mock(bot_config, 'get_state', get_state) expected = { u'os': [u'safe'], u'quarantined': [u'1'], u'server_version': [u'version1'], } self.assertEqual(expected, bot_main._get_dimensions(obj)) expected = { 'quarantined': "get_dimensions(): expected a dict, got 'invalid'", 'sleep_streak': 0.1, 'yo': 'dawh', } self.assertEqual(expected, bot_main._get_state(obj, 0.1))
def test_get_dimensions(self): from config import bot_config obj = self.make_bot() def get_dimensions(botobj): self.assertEqual(obj, botobj) return {u'yo': [u'dawh']} self.mock(bot_config, 'get_dimensions', get_dimensions) expected = {u'server_version': [u'version1'], u'yo': [u'dawh']} self.assertEqual(expected, bot_main._get_dimensions(obj))
def test_hook_restart(self): from config import bot_config obj = self.make_bot() def get_dimensions(botobj): self.assertEqual(obj, botobj) obj.bot_restart('Yo') return {u'id': [u'foo'], u'pool': [u'bar']} self.mock(bot_config, 'get_dimensions', get_dimensions) restarts = [] self.mock(bot_main, '_bot_restart', lambda *args: restarts.append(args)) expected = { u'id': [u'foo'], u'pool': [u'bar'], u'server_version': [u'version1']} self.assertEqual(expected, bot_main._get_dimensions(obj)) self.assertEqual('Yo', obj.bot_restart_msg()) self.assertEqual([(obj, 'Yo')], restarts)
def test_get_dimensions_extra(self): from config import bot_config obj = self.make_bot() def get_dimensions(botobj): self.assertEqual(obj, botobj) return {u'yo': [u'dawh']} self.mock(bot_config, 'get_dimensions', get_dimensions) # The extra version takes priority. class extra(object): def get_dimensions(self2, botobj): # pylint: disable=no-self-argument self.assertEqual(obj, botobj) return {u'alternative': [u'truth']} self.mock(bot_main, '_EXTRA_BOT_CONFIG', extra()) expected = {u'alternative': [u'truth'], u'server_version': [u'version1']} self.assertEqual(expected, bot_main._get_dimensions(obj))