source: branches/active/character_customization/game/tests/test_openable.py @ 736

Revision 736, 3.2 KB checked in by aspidites, 9 years ago (diff)

Patch by Aspidites:

  • renamed scripts package to parpg
  • renamed parpg module to application
  • removed packaging and other related files (kept locally for reference, will reintroduce similar scripts to resolve bug #275
  • updated all import statements to respect changes above
  • Property svn:eol-style set to native
Line 
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
18import unittest
19from parpg.objects.base import Scriptable, Openable, GameObject
20
21
22class 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
90if __name__ == '__main__':
91    unittest.main()
92
Note: See TracBrowser for help on using the repository browser.