view tests/test_lockable.py @ 149:eab3e1e52497

Modified EquipmentSlot to display an image instead of a text. Added EquipmentGui class, which handles the equipment slots of the player screen. An EquipmentGui instance will be created in the InventoryGUI constructor. The initializeInventory method of the Hud class supplies the players inventory and equipment to the InventoryGUI constructor.
author KarstenBock@gmx.net
date Wed, 05 Oct 2011 11:04:39 +0200
parents 0a2cc748d16b
children 7fc3acada7e0
line wrap: on
line source

#!/usr/bin/env python

# This file is part of PARPG.
# 
# PARPG is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# PARPG is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with PARPG.  If not, see <http://www.gnu.org/licenses/>.

from parpg.bGrease.world import BaseWorld
from parpg.bGrease.entity import Entity
from parpg.components import lockable

import unittest

class TestLockable(unittest.TestCase):
    class Lock(Entity):
        """Enity representing an Lock"""
        
        def __init__(self, world, locked, closed):
            """Constructor"""
            self.lockable.locked = locked
            self.lockable.closed = closed

    class GameWorld(BaseWorld):
        """GameWorld"""

        def configure(self):
            """Set up the world"""
            self.components.lockable = lockable.Lockable()

    def setUp(self):
        unittest.TestCase.setUp(self)
        self.world = self.GameWorld()
        self.lock = self.Lock(self.world, False, True)
        
    def tearDown(self):
        self.lock = None
        self.world = None
        
    def testOpenClose(self):
        lockable.open(self.lock.lockable)
        self.assertFalse(self.lock.lockable.closed)
        lockable.close(self.lock.lockable)
        self.assertTrue(self.lock.lockable.closed)
         
    def testLockUnlock(self):
        lockable.lock(self.lock.lockable)
        self.assertTrue(self.lock.lockable.locked)
        self.assertRaises(lockable.LockedError, lockable.open, self.lock.lockable)
        lockable.unlock(self.lock.lockable)
        self.assertFalse(self.lock.lockable.locked)
        lockable.open(self.lock.lockable)
        self.assertRaises(lockable.OpenError, lockable.lock, self.lock.lockable)