Mercurial > parpg-core
annotate tests/test_container.py @ 65:765cb0c16f20
Made the component classes available in the __ini__.py file of the components package
author | KarstenBock@gmx.net |
---|---|
date | Mon, 05 Sep 2011 14:49:45 +0200 |
parents | c017773e8443 |
children | 0a2cc748d16b |
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 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
18 import unittest |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
19 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
20 from parpg.grease.world import BaseWorld |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
21 from parpg.grease.entity import Entity |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
22 from parpg.components import containable, container |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
23 |
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
24 class TestContainer(unittest.TestCase): |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
25 class GameWorld(BaseWorld): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
26 """GameWorld""" |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
27 |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
28 def configure(self): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
29 """Set up the world""" |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
30 self.components.containable = containable.Containable() |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
31 self.components.container = container.Container() |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
32 |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
33 class Inventory(Entity): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
34 """Enity representing an Iventory""" |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
35 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
36 def __init__(self, world, max_bulk, slots): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
37 """Constructor""" |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
38 self.container.children = slots |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
39 self.container.max_bulk = max_bulk |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
40 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
41 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
42 class Item(Entity): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
43 def __init__(self, world, bulk): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
44 """Constructor""" |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
45 self.containable.bulk = bulk |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
46 |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
47 def setUp(self): |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
48 unittest.TestCase.setUp(self) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
49 self.world = self.GameWorld() |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
50 slots_15 = list() |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
51 slots_25 = list() |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
52 for i in xrange(3): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
53 slots_15.append(None) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
54 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
55 for i in xrange(10): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
56 slots_25.append(None) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
57 |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
58 self.inv_15 = self.Inventory(self.world, 15, slots_15) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
59 self.inv_25 = self.Inventory(self.world, 25, slots_25) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
60 self.dagger_1 = self.Item(self.world, 2) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
61 self.sword_1 = self.Item(self.world, 4) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
62 self.axe_1 = self.Item(self.world, 4) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
63 self.mace_1 = self.Item(self.world, 5) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
64 self.spear_1 = self.Item(self.world, 8) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
65 self.dagger_2 = self.Item(self.world, 2) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
66 self.sword_2 = self.Item(self.world, 4) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
67 self.axe_2 = self.Item(self.world, 4) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
68 self.mace_2 = self.Item(self.world, 5) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
69 self.spear_2 = self.Item(self.world, 8) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
70 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
71 def tearDown(self): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
72 self.dagger_1 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
73 self.sword_1 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
74 self.axe_1 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
75 self.mace_1 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
76 self.spear_1 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
77 self.dagger_2 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
78 self.sword_2 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
79 self.axe_2 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
80 self.mace_2 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
81 self.spear_2 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
82 self.inv_15 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
83 self.inv_25 = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
84 self.world = None |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
85 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
86 def test_State(self): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
87 for child in self.inv_15.container.children: |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
88 self.assertIsNone(child) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
89 |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
90 for child in self.inv_25.container.children: |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
91 self.assertIsNone(child) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
92 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
93 def test_PutTake(self): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
94 self.assertIsNone(container.get_item(self.inv_15.container, 0)) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
95 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
96 container.put_item(self.inv_15.container, self.sword_1.containable, 0) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
97 self.assertIsNotNone(container.get_item(self.inv_15.container, 0)) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
98 self.assertListEqual(self.inv_15.container.children, self.sword_1.containable.container.children) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
99 self.assertEqual(self.inv_15.container.children[0].container, self.sword_1.containable.container) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
100 self.assertEqual(self.inv_15.container.children[0].slot, self.sword_1.containable.slot) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
101 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
102 container.take_item(self.inv_15.container, 0) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
103 self.assertIsNone(self.inv_15.container.children[0]) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
104 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
105 def test_Swap(self): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
106 self.assertIsNone(self.inv_15.container.children[0]) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
107 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
108 container.put_item(self.inv_15.container, self.sword_1.containable, 0) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
109 sword1 = container.get_item(self.inv_15.container, 0) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
110 self.assertEqual(sword1.container, self.sword_1.containable.container) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
111 self.assertEqual(sword1.slot, self.sword_1.containable.slot) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
112 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
113 sword2 = container.put_item(self.inv_15.container, self.dagger_1.containable, 0) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
114 self.assertEqual(sword2.container, sword1.container) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
115 self.assertEqual(sword2.slot, sword1.slot) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
116 |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
117 self.assertIsNotNone(container.get_item(self.inv_15.container, 0)) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
118 self.assertListEqual(self.inv_15.container.children, self.dagger_1.containable.container.children) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
119 self.assertEqual(self.inv_15.container.children[0].container, self.dagger_1.containable.container) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
120 self.assertEqual(self.inv_15.container.children[0].slot, self.dagger_1.containable.slot) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
121 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
122 def test_BulkSlots(self): |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
123 container.put_item(self.inv_15.container, self.sword_1.containable) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
124 container.put_item(self.inv_25.container, self.sword_2.containable) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
125 self.assertEqual(container.get_total_bulk(self.inv_15.container), self.sword_1.containable.bulk) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
126 self.assertEqual(container.get_total_bulk(self.inv_25.container), self.sword_2.containable.bulk) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
127 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
128 container.put_item(self.inv_15.container, self.axe_1.containable) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
129 container.put_item(self.inv_25.container, self.axe_2.containable) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
130 self.assertEqual(container.get_total_bulk(self.inv_15.container), container.get_total_bulk(self.inv_25.container)) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
131 |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
132 self.assertRaises(container.BulkLimitError, container.put_item, self.inv_15.container, self.spear_1.containable) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
133 container.put_item(self.inv_25.container, self.spear_2.containable) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
134 |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
135 container.put_item(self.inv_15.container, self.dagger_1.containable) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
136 container.put_item(self.inv_25.container, self.dagger_2.containable) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
137 self.assertNotEqual(container.get_total_bulk(self.inv_15.container), container.get_total_bulk(self.inv_25.container)) |
0
1fd2201f5c36
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
138 |
48
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
139 self.assertRaises(container.NoFreeSlotError, container.put_item, self.inv_15.container, self.mace_1.containable) |
c017773e8443
Added unit tests for the container functions.
KarstenBock@gmx.net
parents:
0
diff
changeset
|
140 container.put_item(self.inv_25.container, self.mace_2.containable) |