# HG changeset patch # User Jeremy Thurgood # Date 1282576565 -7200 # Node ID 90b32447b2399c0b00cad35b09d02b66012ccc47 # Parent 23d2c58369fcb722c22293c8e377b8c1ca4c3979 Some test refactorage. diff -r 23d2c58369fc -r 90b32447b239 gamelib/tests/game_logic_utils.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/tests/game_logic_utils.py Mon Aug 23 17:16:05 2010 +0200 @@ -0,0 +1,43 @@ +import unittest + +import pygame + +from gamelib import state + +from pygame.locals import SWSURFACE +from gamelib.constants import SCREEN + + +# We need this stuff set up so we can load images and whatnot. +pygame.display.init() +pygame.display.set_mode(SCREEN, SWSURFACE) + + +class GameLogicTestCase(unittest.TestCase): + CURRENT_SCENE = None + + def setUp(self): + self.state = state.initial_state() + self.state.set_current_scene(self.CURRENT_SCENE) + + def set_game_data(self, key, value, thing=None, scene=None): + if scene is None: + scene = self.CURRENT_SCENE + gizmo = self.state.scenes[scene] + if thing is not None: + gizmo = gizmo.things[thing] + gizmo.set_data(key, value) + + def assert_game_data(self, key, value, thing=None, scene=None): + if scene is None: + scene = self.CURRENT_SCENE + gizmo = self.state.scenes[scene] + if thing is not None: + gizmo = gizmo.things[thing] + self.assertEquals(value, gizmo.get_data(key)) + + def interact_thing(self, thing_name, item_name=None): + item = None + if item_name is not None: + item = self.state.items[item_name] + self.state.scenes[self.CURRENT_SCENE].things[thing_name].interact(item) diff -r 23d2c58369fc -r 90b32447b239 gamelib/tests/test_game_logic.py --- a/gamelib/tests/test_game_logic.py Mon Aug 23 16:47:27 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -import unittest - -import pygame - -from gamelib import state - -from pygame.locals import SWSURFACE -from gamelib.constants import SCREEN - - -# We need this stuff set up so we can load images and whatnot. -pygame.display.init() -pygame.display.set_mode(SCREEN, SWSURFACE) - - -class TestGameLogic(unittest.TestCase): - def setUp(self): - self.state = state.initial_state() - - def set_game_data(self, key, value, scene, thing=None): - gizmo = self.state.scenes[scene] - if thing is not None: - gizmo = gizmo.things[thing] - gizmo.set_data(key, value) - - def assert_game_data(self, key, value, scene, thing=None): - gizmo = self.state.scenes[scene] - if thing is not None: - gizmo = gizmo.things[thing] - self.assertEquals(value, gizmo.get_data(key)) - - def interact_thing(self, scene_name, thing_name, item_name=None): - item = None - if item_name is not None: - item = self.state.items[item_name] - self.state.scenes[scene_name].things[thing_name].interact(item) - - def test_cryo_door_closed_hand(self): - "The door is closed and we touch it with the hand. No change." - - self.assert_game_data('accessible', True, 'cryo') - self.assert_game_data('accessible', False, 'bridge') - self.assert_game_data('open', False, 'cryo', 'cryo.door') - - self.interact_thing('cryo', 'cryo.door') - - self.assert_game_data('accessible', True, 'cryo') - self.assert_game_data('accessible', False, 'bridge') - self.assert_game_data('open', False, 'cryo', 'cryo.door') - - def test_cryo_door_closed_titanium_leg(self): - "The door is closed and we touch it with the titanium leg. It opens." - - self.assert_game_data('accessible', True, 'cryo') - self.assert_game_data('accessible', False, 'bridge') - self.assert_game_data('open', False, 'cryo', 'cryo.door') - - self.interact_thing('cryo', 'cryo.door', 'titanium_leg') - - self.assert_game_data('accessible', True, 'cryo') - self.assert_game_data('accessible', True, 'bridge') - self.assert_game_data('open', True, 'cryo', 'cryo.door') - - def test_cryo_door_open_hand(self): - "The door is open and we touch it with the hand. No change." - - self.set_game_data('accessible', True, 'bridge') - self.set_game_data('open', True, 'cryo', 'cryo.door') - - self.interact_thing('cryo', 'cryo.door') - - self.assert_game_data('accessible', True, 'cryo') - self.assert_game_data('accessible', True, 'bridge') - self.assert_game_data('open', True, 'cryo', 'cryo.door') - - def test_cryo_door_open_titanium_leg(self): - "The door is open and we touch it with the titanium leg. No change." - - self.set_game_data('accessible', True, 'bridge') - self.set_game_data('open', True, 'cryo', 'cryo.door') - - self.interact_thing('cryo', 'cryo.door', 'titanium_leg') - - self.assert_game_data('accessible', True, 'cryo') - self.assert_game_data('accessible', True, 'bridge') - self.assert_game_data('open', True, 'cryo', 'cryo.door') diff -r 23d2c58369fc -r 90b32447b239 gamelib/tests/test_scene_interactions_cryo.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/tests/test_scene_interactions_cryo.py Mon Aug 23 17:16:05 2010 +0200 @@ -0,0 +1,56 @@ +import game_logic_utils + + +class TestGameLogic(game_logic_utils.GameLogicTestCase): + + CURRENT_SCENE = 'cryo' + + def test_cryo_door_closed_hand(self): + "The door is closed and we touch it with the hand. No change." + + self.assert_game_data('accessible', True) + self.assert_game_data('accessible', False, scene='bridge') + self.assert_game_data('open', False, 'cryo.door') + + self.interact_thing('cryo.door') + + self.assert_game_data('accessible', True) + self.assert_game_data('accessible', False, scene='bridge') + self.assert_game_data('open', False, 'cryo.door') + + def test_cryo_door_closed_titanium_leg(self): + "The door is closed and we touch it with the titanium leg. It opens." + + self.assert_game_data('accessible', True) + self.assert_game_data('accessible', False, scene='bridge') + self.assert_game_data('open', False, 'cryo.door') + + self.interact_thing('cryo.door', 'titanium_leg') + + self.assert_game_data('accessible', True) + self.assert_game_data('accessible', True, scene='bridge') + self.assert_game_data('open', True, 'cryo.door') + + def test_cryo_door_open_hand(self): + "The door is open and we touch it with the hand. No change." + + self.set_game_data('accessible', True, scene='bridge') + self.set_game_data('open', True, 'cryo.door') + + self.interact_thing('cryo.door') + + self.assert_game_data('accessible', True) + self.assert_game_data('accessible', True, scene='bridge') + self.assert_game_data('open', True, 'cryo.door') + + def test_cryo_door_open_titanium_leg(self): + "The door is open and we touch it with the titanium leg. No change." + + self.set_game_data('accessible', True, scene='bridge') + self.set_game_data('open', True, 'cryo.door') + + self.interact_thing('cryo.door', 'titanium_leg') + + self.assert_game_data('accessible', True) + self.assert_game_data('accessible', True, scene='bridge') + self.assert_game_data('open', True, 'cryo.door')