view tests/test_lockable.py @ 54:5e27c24acaef

Fixed bug that the game crashes in the main menu after a few seconds.
author KarstenBock@gmx.net
date Sun, 04 Sep 2011 16:37:37 +0200
parents 79cb7a659414
children 0a2cc748d16b
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.grease.world import BaseWorld
from parpg.grease.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)