''' Tests for CmdPilot ''' from evennia.commands.default.tests import CommandTest from evennia import create_object from mock import Mock from typeclasses import mech from commands.mech_cmds import * from evennia.commands.default.help import CmdHelp from evennia.commands.default.cmdset_character import CharacterCmdSet import re # TODO: Make [0][2]['text'][0] not a thing... # TODO: Test lockfunc cmdinside (self.call can't move location) class MechCmdHelper(CommandTest): 'Helper class for mech command tests' def setUp(self): 'Setup environment for testing mech commands' super().setUp() self.mech = create_object(mech.Mech, key='mech', location=self.room1, aliases=['mech']) # Need to remove permissions to test locks self.char1.account.permissions.remove('Developer') # Place Char 1 inside mech self.char1.move_to(self.mech) class TestCmdPilot(MechCmdHelper): 'Tests for CmdPilot' def setUp(self): 'Setup tests for pilot command' super().setUp() # Ensure characters start outside of the mech self.char1.move_to(self.mech.location) self.char2.move_to(self.mech.location) def test_func_without_arg(self): 'Tests func method' self.call(CmdPilot(), '', 'You must give a target') def test_func_with_arg(self): # Store messages received by char2 self.char1.msg = Mock() self.char2.msg = Mock() self.assertNotIn(self.char1, self.mech.contents) self.char1.execute_cmd('pilot mech') self.assertIn(self.char1, self.mech.contents) # Check messages sent self.assertEqual(self.char1.msg.mock_calls[0][1][0], 'You climb into the mech') self.assertEqual(self.char2.msg.mock_calls[0][2]['text'][0], 'Char climbs into the mech') def test_func_occupied(self): 'Test trying to pilot an occupied mech' # It's easier to use char2 to test because `char2.is_connected` returns true self.char1.move_to(self.mech) self.char2.msg = Mock() self.char2.execute_cmd('pilot mech') self.assertEqual(self.char2.msg.mock_calls[0][1][0], 'This mech is currently piloted by Char, you cannot enter') self.assertNotIn(self.char2, self.mech.contents) class TestCmdLeave(MechCmdHelper): 'Tests for CmdLeave' def test_func(self): 'Tests func method' # Store messages received by chararacters self.char1.msg = Mock() self.char2.msg = Mock() self.char1.execute_cmd('leave mech') self.assertEqual(self.char1.msg.mock_calls[0][1][0], 'You climb out of the mech') self.assertEqual(self.char2.msg.mock_calls[0][2]['text'][0], 'Char climbs out of the mech') class TestCmdHUD(MechCmdHelper): 'Tests for CmdHud' def test_func(self): 'Tests func method' self.char1.msg = Mock() self.char1.execute_cmd('hud') output = self.char1.msg.mock_calls[0][1][0] self.assertEqual(output, self.room1.return_appearance(self.char1, exclude=[self.mech])) class TestCmdDrive(MechCmdHelper): 'Tests for CmdDrive' def test_func(self): 'Tests func method' self.char1.execute_cmd('drive to out') self.assertEqual(self.mech.location, self.room2)