comparison tests/test_scriptable.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 GameObject, Scriptable
20
21 class TestScriptable(unittest.TestCase):
22 def setUp(self):
23 self.script_ran1=False
24 self.script_ran2=False
25
26 def tearDown(self):
27 self.scriptable = None
28
29 def script1(self,param1,param2):
30 self.script_ran1=True
31 self.assertEqual(param1, 'param1')
32 self.assertEqual(param2, 'param2')
33
34 def script2(self,param3,param4):
35 self.script_ran2=True
36 self.assertEqual(param3, 'param3')
37 self.assertEqual(param4, 'param4')
38
39 def testScripting(self):
40 """Test Scriptable mixin scripting abilities"""
41 scriptable = Scriptable()
42 scriptable.runScript('script1')
43 self.assertFalse(self.script_ran1)
44 self.assertFalse(self.script_ran2)
45 scriptable = Scriptable({'script1':(self.script1,('param1',),{'param2':'param2'})})
46 scriptable.runScript('script1')
47 self.assertTrue(self.script_ran1)
48 self.assertFalse(self.script_ran2)
49 self.script_ran1=False
50 scriptable.setScript('script2', self.script2, ('param3',), {'param4':'param4'})
51 scriptable.runScript('script2')
52 self.assertTrue(self.script_ran2)
53 self.assertFalse(self.script_ran1)
54
55 if __name__ == '__main__':
56 unittest.main()
57