File: ScriptableTest.py

package info (click to toggle)
pythoncard 0.8.2-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 8,452 kB
  • sloc: python: 56,787; makefile: 56; sh: 22
file content (56 lines) | stat: -rw-r--r-- 1,622 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from PythonCard import event, log, component
import unittest


class TestHandler( component.Scriptable ) :

    def __init__( self, name, parent ) :
        component.Scriptable.__init__( self, parent )
        self._name = name
        
    def on_doIt( self, event ) :
        global handledIn
        handledIn = self._name

    def getName( self ) :
        return self._name
        
        
class HandlerWithMissingMethod( component.Scriptable ) :

    def __init__( self, name, parent ) :
        component.Scriptable.__init__( self, parent )
        self._name = name
        
    def getName( self ) :
        return self._name
        

class TestScriptable( unittest.TestCase, event.EventListener ) :
    
    def __init__( self, name ) :
        unittest.TestCase.__init__( self, name )
        event.EventLog.getInstance().addEventListener( self )
        
    def eventOccurred( self, event ) :
        print 'event=', event
        
    def setUp( self ) :
        pass

    def testScriptable( self ) :
        global handledIn
        parent = TestHandler( 'parent', None )
        parent.execute( 'on_doIt', ( 'howdy parent' ) )
        self.assertEqual( handledIn, 'parent' )
        child = TestHandler( 'child', parent )
        child.execute( 'on_doIt', ( 'howdy child' ) )
        self.assertEqual( handledIn, 'child' )
        missing = HandlerWithMissingMethod( 'missing', parent )
        missing.execute( 'on_doIt', ( 'howdy missing(parent)' ) )
        self.assertEqual( handledIn, 'parent' )
        missing.execute( 'on_wtf', ( 'no dice' ) )

if __name__ == '__main__':
    unittest.main()