Mercurial > parpg-core
annotate 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 |
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.wearer.equip.head = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
41 self.wearer.equip.body = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
42 self.wearer.equip.leg = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
43 self.wearer.equip.feet = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
44 self.wearer.equip.l_arm = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
45 self.wearer.equip.r_arm = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
46 self.arms_item = Entity(self.world) |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
47 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
|
48 self.l_arm_item = Entity(self.world) |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
49 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
|
50 self.r_arm_item = Entity(self.world) |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
51 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
|
52 self.t_arm_item = Entity(self.world) |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
53 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
|
54 |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
55 def test_equip_and_take(self): |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
56 print "Raise SlotInvalidError" |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
57 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
|
58 print "Raise CannotBeEquippedInSlot" |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
59 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
|
60 print "Equip l_arm" |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
61 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
|
62 print "Equip r_arm" |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
63 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
|
64 self.assertIsNotNone(self.l_arm_item.equipable.wearer) |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
65 print "Raise AlreadyEquipped" |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
66 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
|
67 print "Switch r_arm with arms" |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
68 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
|
69 self.assertIsNone(self.r_arm_item.equipable.wearer) |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
70 self.assertIsNotNone(self.arms_item.equipable.wearer) |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
71 print "Take l_arm" |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
72 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
|
73 self.assertIsNone(self.l_arm_item.equipable.wearer) |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
74 |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
75 def tearDown(self): |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
76 self.world = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
77 self.wearer = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
78 self.arms_item = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
79 self.l_arm_item = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
80 self.r_arm_item = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
81 self.t_arm_item = None |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
82 |
334f7aea6386
Added unit test for the equip and equipable components.
KarstenBock@gmx.net
parents:
diff
changeset
|
83 |