# HG changeset patch # User Jeremy Thurgood # Date 1282923315 -7200 # Node ID ca0c2875ad8f046b3ad075bc1a00d54c245c7abb # Parent 60a0757bee053e1d4461aa225c21668808e8aa9e More test fixes. diff -r 60a0757bee05 -r ca0c2875ad8f gamelib/tests/game_logic_utils.py --- a/gamelib/tests/game_logic_utils.py Fri Aug 27 17:32:05 2010 +0200 +++ b/gamelib/tests/game_logic_utils.py Fri Aug 27 17:35:15 2010 +0200 @@ -20,6 +20,11 @@ self.state = state.initial_state() self.state.set_current_scene(self.CURRENT_SCENE) + def tearDown(self): + for item in self.state.items.values(): + if isinstance(item, state.CloneableItem): + type(item)._counter = 0 + def set_game_data(self, key, value, thing=None): gizmo = self.state.current_scene if thing is not None: @@ -52,6 +57,7 @@ def interact_thing(self, thing, item=None): item_obj = None if item is not None: + self.assert_inventory_item(item) item_obj = self.state.items[item] thing_container = self.state.current_detail or self.state.current_scene result = thing_container.things[thing].interact(item_obj) @@ -59,3 +65,12 @@ self.state.set_current_detail(result.detail_view) return result + def interact_item(self, target_item, item): + self.assert_inventory_item(target_item) + item_obj = self.state.items[item] + target_obj = self.state.items[target_item] + result = target_obj.interact(item_obj, self.state) + if result and result.detail_view: + self.state.set_current_detail(result.detail_view) + return result + diff -r 60a0757bee05 -r ca0c2875ad8f gamelib/tests/test_scene_interactions_cryo.py --- a/gamelib/tests/test_scene_interactions_cryo.py Fri Aug 27 17:32:05 2010 +0200 +++ b/gamelib/tests/test_scene_interactions_cryo.py Fri Aug 27 17:35:15 2010 +0200 @@ -58,6 +58,7 @@ def test_cryo_door_open_titanium_leg(self): "The door is open and we touch it with the titanium leg. No change." + self.state.add_inventory_item('titanium_leg') self.set_game_data('door', 'open', 'cryo.door') self.interact_thing('cryo.door', 'titanium_leg') @@ -113,6 +114,7 @@ def test_pipes_unchopped_machete(self): "Touch the unchopped cryopipes with the machete. They chop." + self.state.add_inventory_item('machete') self.assert_game_data('fixed', True, 'cryo.pipe.left') self.assert_game_data('fixed', True, 'cryo.pipe.right') self.assert_item_exists('cryo_pipe.0', False) @@ -131,6 +133,7 @@ def test_pipes_chopped_machete(self): "Touch the chopped cryopipes with the machete. No change." + self.state.add_inventory_item('machete') self.set_game_data('fixed', False, 'cryo.pipe.left') self.set_game_data('fixed', False, 'cryo.pipe.right') diff -r 60a0757bee05 -r ca0c2875ad8f gamelib/tests/test_walkthrough.py --- a/gamelib/tests/test_walkthrough.py Fri Aug 27 17:32:05 2010 +0200 +++ b/gamelib/tests/test_walkthrough.py Fri Aug 27 17:35:15 2010 +0200 @@ -8,12 +8,15 @@ def close_detail(self): self.state.set_current_detail(None) - def move(self, source, target): - self.interact_thing(source+'.door') + def move_to(self, target): + self.interact_thing(self.state.current_scene.name + '.door') self.assert_current_scene('map') - self.interact_thing('map.to'+target) + self.interact_thing('map.to' + target) self.assert_current_scene(target) + def test_walkthrough_complete(self): + self.fail("Walkthrough incomplete.") + def test_walkthrough(self): """A complete game walkthrough. @@ -40,21 +43,8 @@ self.assert_game_data('door', 'open', 'cryo.door') self.assert_inventory_item('titanium_leg') - # Go to the machine room. - self.move('cryo', 'machine') - - # Sharpen leg into machete. - self.interact_thing('machine.grinder', 'titanium_leg') - self.assert_inventory_item('titanium_leg', False) - self.assert_inventory_item('machete') - # Go to the mess. - self.move('machine', 'mess') - - # Clear the broccoli. - self.assert_game_data('status', 'blocked', 'mess.tubes') - self.interact_thing('mess.tubes', 'machete') - self.assert_game_data('status', 'broken', 'mess.tubes') + self.move_to('mess') # Get the cans. self.assert_game_data('cans_available', 3, 'mess.cans') @@ -66,6 +56,39 @@ self.assert_inventory_item('full_can.2') self.assert_game_data('cans_available', 0, 'mess.cans') + # Bash one of the cans. + self.assert_item_exists('dented_can.0', False) + self.interact_item('full_can.1', 'titanium_leg') + self.assert_inventory_item('dented_can.0') + self.assert_inventory_item('full_can.1', False) - self.fail("Walkthrough incomplete.") + # Go to the machine room. + self.move_to('machine') + + # Sharpen leg into machete. + self.interact_thing('machine.grinder', 'titanium_leg') + self.assert_inventory_item('titanium_leg', False) + self.assert_inventory_item('machete') + + # Go to the cryo room. + self.move_to('cryo') + # Chop up some pipes. + self.assert_game_data('fixed', True, 'cryo.pipe.left') + self.interact_thing('cryo.pipe.left', 'machete') + self.assert_game_data('fixed', False, 'cryo.pipe.left') + self.assert_inventory_item('cryo_pipe.0') + + self.assert_game_data('fixed', True, 'cryo.pipe.right') + self.interact_thing('cryo.pipe.right', 'machete') + self.assert_game_data('fixed', False, 'cryo.pipe.right') + self.assert_inventory_item('cryo_pipe.1') + + # Go to the mess. + self.move_to('mess') + + # Clear the broccoli. + self.assert_game_data('status', 'blocked', 'mess.tubes') + self.interact_thing('mess.tubes', 'machete') + self.assert_game_data('status', 'broken', 'mess.tubes') +