Mercurial > parpg-core
comparison tests/test_equip.py @ 102:334f7aea6386
Added unit test for the equip and equipable components.
author | KarstenBock@gmx.net |
---|---|
date | Wed, 21 Sep 2011 19:52:35 +0200 |
parents | |
children | 7829eb185d6f |
comparison
equal
deleted
inserted
replaced
101:3d9b6405bd86 | 102:334f7aea6386 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 # This file is part of PARPG. | |
4 # | |
5 # PARPG is free software: you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation, either version 3 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # PARPG is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. | |
17 | |
18 from parpg.bGrease.world import BaseWorld | |
19 from parpg.bGrease.entity import Entity | |
20 from parpg.components import Equipable | |
21 from parpg.components import Equip | |
22 from parpg.components import equip | |
23 | |
24 import unittest | |
25 | |
26 class TestEquip(unittest.TestCase): | |
27 | |
28 class GameWorld(BaseWorld): | |
29 """GameWorld""" | |
30 | |
31 def configure(self): | |
32 """Set up the world""" | |
33 self.components.equipable = Equipable() | |
34 self.components.equip = Equip() | |
35 | |
36 def setUp(self): | |
37 unittest.TestCase.setUp(self) | |
38 self.world = self.GameWorld() | |
39 self.wearer = Entity(self.world) | |
40 self.wearer.equip.head = None | |
41 self.wearer.equip.body = None | |
42 self.wearer.equip.leg = None | |
43 self.wearer.equip.feet = None | |
44 self.wearer.equip.l_arm = None | |
45 self.wearer.equip.r_arm = None | |
46 self.arms_item = Entity(self.world) | |
47 self.arms_item.equipable.possible_slots = ["l_arm", "r_arm"] | |
48 self.l_arm_item = Entity(self.world) | |
49 self.l_arm_item.equipable.possible_slots = ["l_arm"] | |
50 self.r_arm_item = Entity(self.world) | |
51 self.r_arm_item.equipable.possible_slots = ["r_arm"] | |
52 self.t_arm_item = Entity(self.world) | |
53 self.t_arm_item.equipable.possible_slots = ["t_arm"] | |
54 | |
55 def test_equip_and_take(self): | |
56 print "Raise SlotInvalidError" | |
57 self.assertRaises(equip.SlotInvalidError, equip.equip, self.wearer.equip, self.t_arm_item.equipable, "t_arm") | |
58 print "Raise CannotBeEquippedInSlot" | |
59 self.assertRaises(equip.CannotBeEquippedInSlot, equip.equip, self.wearer.equip, self.l_arm_item.equipable, "r_arm") | |
60 print "Equip l_arm" | |
61 equip.equip(self.wearer.equip, self.l_arm_item.equipable, "l_arm") | |
62 print "Equip r_arm" | |
63 equip.equip(self.wearer.equip, self.r_arm_item.equipable, "r_arm") | |
64 self.assertIsNotNone(self.l_arm_item.equipable.wearer) | |
65 print "Raise AlreadyEquipped" | |
66 self.assertRaises(equip.AlreadyEquippedError, equip.equip, self.wearer.equip, self.l_arm_item.equipable, "r_arm") | |
67 print "Switch r_arm with arms" | |
68 equip.equip(self.wearer.equip, self.arms_item.equipable, "r_arm") | |
69 self.assertIsNone(self.r_arm_item.equipable.wearer) | |
70 self.assertIsNotNone(self.arms_item.equipable.wearer) | |
71 print "Take l_arm" | |
72 equip.take_equipable( self.wearer.equip, self.l_arm_item.equipable.in_slot) | |
73 self.assertIsNone(self.l_arm_item.equipable.wearer) | |
74 | |
75 def tearDown(self): | |
76 self.world = None | |
77 self.wearer = None | |
78 self.arms_item = None | |
79 self.l_arm_item = None | |
80 self.r_arm_item = None | |
81 self.t_arm_item = None | |
82 | |
83 |