How to use has_event method in Slash

Best Python code snippet using slash

test_actions.py

Source:test_actions.py Github

copy

Full Screen

...109 def test_not_active(self):110 self.entity.states.active = False111 result = self.action.take_action(self.entity, self.player)112 self.assertEqual(result, "For some reason you can't")113 def test_has_event(self):114 self.entity.events.has_event.return_value = True115 result = self.action.take_action(self.entity, None)116 self.entity.events.has_event.assert_called_with('go')117 self.entity.events.execute.assert_called_with('go', self.player)118 self.assertEqual(result, "Event executed")119 def test_no_event(self):120 self.entity.events.has_event.return_value = False121 result = self.action.take_action(self.entity, None)122 self.assertEqual(result, "Impossible!")123class TestGet(unittest.TestCase):124 def setUp(self):125 self.entity = mock.MagicMock()126 self.entity.spec.name = 'a hat'127 self.entity.events.execute.return_value = "Event executed"128 self.player = mock.MagicMock()129 self.player.inventory.has_item.return_value = False130 self.action = actions.Get(self.player)131 def test_no_entity(self):132 result = self.action.take_action(None, None)133 self.assertEqual(result, "Get What?")134 def test_already_have(self):135 self.player.inventory.has_item.return_value = True136 result = self.action.take_action(self.entity, None)137 self.player.inventory.has_item.assert_called_with(self.entity.spec.id)138 self.assertEqual(result, "You already have it!")139 @mock.patch('dgsl_engine.actions.move')140 def test_obtainable(self, mock_move):141 self.entity.states.obtainable = True142 self.entity.events.has_event.return_value = True143 self.entity.events.execute.return_value = "Event executed"144 result = self.action.take_action(self.entity, None)145 mock_move.assert_called_with(self.entity, self.player)146 self.assertEqual(result, "You take a hat\nEvent executed")147 def test_obtainable_no_event(self):148 self.entity.states.obtainable = True149 self.entity.events.has_event.return_value = False150 self.entity.events.execute.return_value = "Event executed"151 result = self.action.take_action(self.entity, None)152 self.assertEqual(result, "You take a hat")153 def test_get_not_obtainable(self):154 self.entity.states.obtainable = False155 result = self.action.take_action(self.entity, None)156 self.assertEqual(result, "You can't take that")157 def test_get_filter_entities_only_one(self):158 entities = [self.entity]159 result = self.action.filter_entities(entities)160 self.assertIs(result, entities)161 def test_get_filter_entities_filter_some(self):162 self.player.get.return_value = None163 entities = [self.entity, self.player]164 result = self.action.filter_entities(entities)165 self.assertTrue(len(result) == 1)166 self.assertIs(result[0], self.entity)167 def test_get_filter_entities_filter_some_player_has(self):168 self.player.get.return_value = self.entity169 entities = [self.entity, self.player]170 result = self.action.filter_entities(entities)171 self.assertFalse(result)172class TestDrop(unittest.TestCase):173 def setUp(self):174 self.entity = mock.MagicMock()175 self.entity.spec.name = 'a hat'176 self.entity.events.execute.return_value = "Event executed"177 self.player = mock.MagicMock()178 self.player.inventory.has_item.return_value = False179 self.action = actions.Drop(self.player)180 def test_use_no_entity(self):181 result = self.action.take_action(None, None)182 self.assertEqual(result, 'Drop What?')183 @mock.patch('dgsl_engine.actions.move')184 def test_drop_player_has_item(self, mock_move):185 self.player.inventory.has_item.return_value = True186 self.entity.events.has_event.return_value = True187 result = self.action.take_action(self.entity, None)188 self.player.inventory.has_item.assert_called_with(self.entity.spec.id)189 mock_move.assert_called_with(self.entity, self.player.owner)190 self.assertEqual(result, "You drop a hat\nEvent executed")191 def test_drop_player_has_item_no_result(self):192 self.player.inventory.has_item.return_value = True193 self.entity.events.has_event.return_value = True194 self.entity.events.execute.return_value = None195 result = self.action.take_action(self.entity, None)196 self.assertEqual(result, "You drop a hat")197 def test_drop_no_item(self):198 result = self.action.take_action(self.entity, None)199 self.assertEqual(result, "You don't have that")200# Interaction Actions ##################################################201class TestUse(unittest.TestCase):202 def setUp(self):203 self.entity = mock.MagicMock()204 self.entity.spec.name = 'a hat'205 self.entity.events.execute.return_value = "Event executed"206 self.player = mock.MagicMock()207 self.player.inventory.has_item.return_value = False208 self.action = actions.Use(self.player)209 def test_no_entity(self):210 result = self.action.take_action(None, None)211 self.assertEqual(result, 'Use What?')212 def test_not_active(self):213 self.entity.states.active = False214 result = self.action.take_action(self.entity, self.player)215 self.assertEqual(result, "For some reason you can't")216 def test_has_event(self):217 self.entity.events.has_event.return_value = True218 result = self.action.take_action(self.entity, None)219 self.entity.events.has_event.assert_called_with('use')220 self.entity.events.execute.assert_called_with('use', self.player)221 self.assertEqual(result, "Event executed")222 def test_has_event_no_result(self):223 self.entity.events.has_event.return_value = True224 self.entity.events.execute.return_value = ' '225 result = self.action.take_action(self.entity, None)226 self.assertEqual(result, "You use a hat")227 def test_no_event(self):228 self.entity.events.has_event.return_value = False229 result = self.action.take_action(self.entity, None)230 self.assertEqual(result, "You can't use that")231class TestLook(unittest.TestCase):232 def setUp(self):233 self.entity = mock.MagicMock()234 self.entity.describe.return_value = 'a very nice hat'235 self.entity.events.execute.return_value = "Event executed"236 self.player = mock.MagicMock()237 self.player.owner.describe.return_value = "A very large room"238 self.action = actions.Look(self.player)239 def test_no_entity(self):240 result = self.action.take_action(None, None)241 self.assertEqual(result, 'A very large room')242 def test_has_event(self):243 self.entity.events.has_event.return_value = True244 result = self.action.take_action(self.entity, None)245 self.entity.events.has_event.assert_called_with('look')246 self.entity.events.execute.assert_called_with('look', self.player)247 self.assertEqual(result, "You see a very nice hat\nEvent executed")248 def test_has_event_no_result(self):249 self.entity.events.has_event.return_value = True250 self.entity.events.execute.return_value = None251 result = self.action.take_action(self.entity, None)252 self.assertEqual(result, "You see a very nice hat")253class TestTalk(unittest.TestCase):254 def setUp(self):255 self.npc = mock.MagicMock()256 self.npc.events.execute.return_value = "Event executed"257 self.player = mock.MagicMock()258 self.action = actions.Talk(self.player)259 def test_no_entity(self):260 result = self.action.take_action(None, None)261 self.assertEqual(result, 'To Whom?')262 def test_not_active(self):263 self.npc.states.active = False264 result = self.action.take_action(self.npc, self.player)265 self.assertEqual(result, "They don't have anything to say right now")266 def test_has_event(self):267 self.npc.events.has_event.return_value = True268 self.npc.events.execute.return_value = "Hello there!"269 result = self.action.take_action(self.npc, None)270 self.npc.events.has_event.assert_called_with('talk')271 self.npc.events.execute.assert_called_with('talk', self.player)272 self.assertEqual(result, "Hello there!")273 def test_has_event_no_result(self):274 self.npc.events.execute.return_value = None275 result = self.action.take_action(self.npc, None)276 self.assertEqual(result, "That doesn't talk")277# Equipment Actions ####################################################278class TestInventory(unittest.TestCase):279 def setUp(self):280 self.entity = mock.MagicMock()...

Full Screen

Full Screen

test_parts_module.py

Source:test_parts_module.py Github

copy

Full Screen

...25 self.assertRaises(RuntimeError, module.get_field, 'DoesntExist')26 self.assertItemsEqual(['Control From Here', 'Rename Vessel',27 'Control Point: Default'],28 module.events)29 self.assertTrue(module.has_event('Control From Here'))30 self.assertFalse(module.has_event('DoesntExist'))31 module.trigger_event('Control From Here')32 self.assertRaises(RuntimeError, module.trigger_event, 'DoesntExist')33 self.assertEqual(['Control From Here', 'Toggle Hibernation'],34 module.actions)35 self.assertFalse(module.has_action('DoesntExist'))36 self.assertRaises(37 RuntimeError, module.set_action, 'DoesntExist', True)38 self.assertRaises(39 RuntimeError, module.set_action, 'DoesntExist', False)40 def test_solar_panel(self):41 part = self.parts.with_title('SP-L 1x6 Photovoltaic Panels')[0]42 module = next(m for m in part.modules43 if m.name == 'ModuleDeployableSolarPanel')44 self.assertEqual('ModuleDeployableSolarPanel', module.name)45 self.assertEqual(part, module.part)46 self.assertEqual({'Energy Flow': '0',47 'Status': 'Retracted',48 'Sun Exposure': '0'}, module.fields)49 self.assertTrue(module.has_field('Status'))50 self.assertFalse(module.has_field('DoesntExist'))51 self.assertEqual('Retracted', module.get_field('Status'))52 self.assertRaises(RuntimeError, module.get_field, 'DoesntExist')53 self.assertItemsEqual(['Extend Solar Panel'], module.events)54 self.assertTrue(module.has_event('Extend Solar Panel'))55 self.assertFalse(module.has_event('DoesntExist'))56 self.assertRaises(RuntimeError, module.trigger_event, 'DoesntExist')57 self.assertItemsEqual(['Extend Solar Panel', 'Retract Solar Panel',58 'Toggle Solar Panel'], module.actions)59 self.assertFalse(module.has_action('DoesntExist'))60 self.assertRaises(61 RuntimeError, module.set_action, 'DoesntExist', True)62 self.assertRaises(63 RuntimeError, module.set_action, 'DoesntExist', False)64 def test_set_field_int(self):65 part = self.parts.with_title('LY-10 Small Landing Gear')[0]66 module = next(m for m in part.modules if m.name == 'ModuleWheelBrakes')67 self.assertEqual({'Brakes': '100'}, module.fields)68 module.set_field_int('Brakes', 50)69 self.wait(1)70 self.assertEqual({'Brakes': '50'}, module.fields)71 module.set_field_int('Brakes', 100)72 self.assertEqual({'Brakes': '100'}, module.fields)73 def test_events(self):74 part = self.parts.with_title('Illuminator Mk1')[0]75 module = next(m for m in part.modules if m.name == 'ModuleLight')76 self.assertTrue(module.has_event('Lights On'))77 self.assertFalse(module.has_event('Lights Off'))78 module.trigger_event('Lights On')79 self.wait()80 self.assertFalse(module.has_event('Lights On'))81 self.assertTrue(module.has_event('Lights Off'))82 module.trigger_event('Lights Off')83 self.wait()84 self.assertTrue(module.has_event('Lights On'))85 self.assertFalse(module.has_event('Lights Off'))86 def test_actions(self):87 part = self.parts.with_title('Illuminator Mk1')[0]88 module = next(m for m in part.modules if m.name == 'ModuleLight')89 self.assertTrue(module.has_event('Lights On'))90 self.assertFalse(module.has_event('Lights Off'))91 module.set_action('Toggle Light', True)92 self.wait()93 self.assertFalse(module.has_event('Lights On'))94 self.assertTrue(module.has_event('Lights Off'))95 module.set_action('Toggle Light', False)96 self.wait()97 self.assertTrue(module.has_event('Lights On'))98 self.assertFalse(module.has_event('Lights Off'))99if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful