Mercurial > parpg-core
comparison tests/test_openable.py @ 0:1fd2201f5c36
Initial commit of parpg-core.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 14 May 2011 01:12:35 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1fd2201f5c36 |
---|---|
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 import unittest | |
19 from parpg.objects.base import Scriptable, Openable, GameObject | |
20 | |
21 | |
22 class TestOpenable(unittest.TestCase): | |
23 | |
24 class OpenableScriptable (GameObject, Openable, Scriptable): | |
25 def __init__ (self, ID, **kwargs): | |
26 GameObject.__init__(self, ID, **kwargs) | |
27 Openable.__init__(self, **kwargs) | |
28 Scriptable.__init__(self, **kwargs) | |
29 | |
30 class OpenableNonScriptable (GameObject, Openable): | |
31 def __init__ (self, ID, **kwargs): | |
32 GameObject.__init__(self, ID, **kwargs) | |
33 Openable.__init__(self, **kwargs) | |
34 | |
35 def onOpen(self): | |
36 self.ran_on_open=True | |
37 | |
38 def onClose(self): | |
39 self.ran_on_close=True | |
40 | |
41 def setUp(self): | |
42 self.ran_on_open=False | |
43 self.ran_on_close=False | |
44 | |
45 def testOpenClose(self): | |
46 """ Test Openable mixin open-close functionality""" | |
47 | |
48 self.openable = self.OpenableNonScriptable(3) | |
49 self.assertEqual(self.openable.is_open,True) | |
50 | |
51 self.openable.close() | |
52 self.assertEqual(self.openable.is_open,False) | |
53 | |
54 # Duplicate close() should not lead to any ill effects | |
55 self.openable.close() | |
56 self.assertEqual(self.openable.is_open,False) | |
57 | |
58 self.openable.open() | |
59 self.assertEqual(self.openable.is_open,True) | |
60 | |
61 # Duplicate open() should not lead to any ill effects | |
62 self.openable.open() | |
63 self.assertEqual(self.openable.is_open,True) | |
64 | |
65 def testScripting(self): | |
66 """ Test Openable mixin with scripting""" | |
67 | |
68 self.openable = self.OpenableScriptable(3, parpg={'onOpen':(self.onOpen,(),{}),'onClose':(self.onClose,(),{})}) | |
69 self.assertEqual(self.ran_on_close,False) | |
70 self.assertEqual(self.ran_on_open,False) | |
71 self.assertEqual(self.openable.is_open,True) | |
72 self.openable.close() | |
73 self.assertEqual(self.ran_on_close,True) | |
74 self.assertEqual(self.ran_on_open,False) | |
75 self.assertEqual(self.openable.is_open,False) | |
76 self.ran_on_close=False | |
77 self.openable.open() | |
78 self.assertEqual(self.ran_on_close,False) | |
79 self.assertEqual(self.ran_on_open,True) | |
80 self.assertEqual(self.openable.is_open,True) | |
81 | |
82 def testInitiallyClosed(self): | |
83 """ Test Openable mixin instantiation in closed state""" | |
84 | |
85 self.openable = self.OpenableNonScriptable(3, is_open=False) | |
86 self.assertEqual(self.openable.is_open,False) | |
87 self.openable.open() | |
88 self.assertEqual(self.openable.is_open,True) | |
89 | |
90 if __name__ == '__main__': | |
91 unittest.main() | |
92 |