annotate tests/test_lockable.py @ 147:3aff9dee1b4f

Added belt and neck as equipment slots.
author KarstenBock@gmx.net
date Wed, 05 Oct 2011 10:54:56 +0200
parents 0a2cc748d16b
children 7fc3acada7e0
rev   line source
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
2
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
3 # This file is part of PARPG.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
4 #
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
5 # PARPG is free software: you can redistribute it and/or modify
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
7 # the Free Software Foundation, either version 3 of the License, or
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
8 # (at your option) any later version.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
9 #
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
10 # PARPG is distributed in the hope that it will be useful,
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
13 # GNU General Public License for more details.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
14 #
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
16 # along with PARPG. If not, see <http://www.gnu.org/licenses/>.
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
17
94
0a2cc748d16b Fixed container and lockable test. They where using the old name of the parpg grease module.
KarstenBock@gmx.net
parents: 50
diff changeset
18 from parpg.bGrease.world import BaseWorld
0a2cc748d16b Fixed container and lockable test. They where using the old name of the parpg grease module.
KarstenBock@gmx.net
parents: 50
diff changeset
19 from parpg.bGrease.entity import Entity
50
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
20 from parpg.components import lockable
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
21
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
22 import unittest
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
23
50
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
24 class TestLockable(unittest.TestCase):
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
25 class Lock(Entity):
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
26 """Enity representing an Lock"""
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
27
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
28 def __init__(self, world, locked, closed):
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
29 """Constructor"""
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
30 self.lockable.locked = locked
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
31 self.lockable.closed = closed
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
32
50
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
33 class GameWorld(BaseWorld):
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
34 """GameWorld"""
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
35
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
36 def configure(self):
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
37 """Set up the world"""
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
38 self.components.lockable = lockable.Lockable()
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
39
50
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
40 def setUp(self):
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
41 unittest.TestCase.setUp(self)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
42 self.world = self.GameWorld()
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
43 self.lock = self.Lock(self.world, False, True)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
44
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
45 def tearDown(self):
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
46 self.lock = None
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
47 self.world = None
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
48
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
49 def testOpenClose(self):
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
50 lockable.open(self.lock.lockable)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
51 self.assertFalse(self.lock.lockable.closed)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
52 lockable.close(self.lock.lockable)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
53 self.assertTrue(self.lock.lockable.closed)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
54
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
55 def testLockUnlock(self):
50
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
56 lockable.lock(self.lock.lockable)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
57 self.assertTrue(self.lock.lockable.locked)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
58 self.assertRaises(lockable.LockedError, lockable.open, self.lock.lockable)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
59 lockable.unlock(self.lock.lockable)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
60 self.assertFalse(self.lock.lockable.locked)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
61 lockable.open(self.lock.lockable)
79cb7a659414 Added unit tests for the Lockable functions
KarstenBock@gmx.net
parents: 0
diff changeset
62 self.assertRaises(lockable.OpenError, lockable.lock, self.lock.lockable)
0
1fd2201f5c36 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
63