annotate tests/test_equip.py @ 150:3fc7cfa80771

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