1"""
2Helper module for KeyValue tests
3"""
4from __future__ import unicode_literals, absolute_import
5from PyObjCTest.testbndl import PyObjCTest_KVBaseClass, PyObjCTest_KVPathClass
6import objc
7
8NSObject = objc.lookUpClass('NSObject')
9
10DirectString = 'Direct String'
11IndirectString = 'Indirect String'
12DirectNumber = 42
13IndirectNumber = 84
14
15class KVPyBase:
16    def __init__(self):
17        self.directString = DirectString
18        self._indirectString = IndirectString
19        self.directNumber = DirectNumber
20        self._indirectNumber = IndirectNumber
21
22    def get_indirectString(self):
23        return self._indirectString
24
25    def set_indirectString(self, aString):
26        self._indirectString = aString
27
28    def getIndirectNumber(self):
29        return self._indirectNumber
30
31    def setIndirectNumber(self, aNumber):
32        self._indirectNumber = aNumber
33
34class KVPyPath:
35    def __init__(self):
36        self.directHead = KVPyBase()
37        self._indirectHead = KVPyBase()
38
39    def indirectHead(self):
40        return self._indirectHead
41
42    def setIndirectHead(self, aHead):
43        self._indirectHead = aHead
44
45class KVPySubObjCBase (PyObjCTest_KVBaseClass):
46    pass
47
48class KVPySubObjCPath (PyObjCTest_KVPathClass):
49    pass
50
51class KVPySubOverObjCBase (PyObjCTest_KVBaseClass):
52    def init(self):
53        self = super(KVPySubOverObjCBase, self).init()
54        if not self:
55            return self
56
57        self.overDirectString = DirectString
58        self._overIndirectString = IndirectString
59        return self
60
61    def getOverIndirectString(self):
62        return self._overIndirectString
63
64    def setOverIndirectString_(self, aString):
65        self._overIndirectString = aString
66
67class KVPySubOverObjCPath(PyObjCTest_KVPathClass):
68    def init(self):
69        self = super(KVPySubOverObjCPath, self).init()
70        self.overDirectHead = KVPySubOverObjCBase.new()
71        self._overIndirectHead = KVPySubOverObjCBase.new()
72        return self
73
74    def overIndirectHead(self):
75        return self._overIndirectHead
76
77    def setOverIndirectHead_(self, aHead):
78        self._overIndirectHead = aHead
79
80class PyObjCTestObserver (NSObject):
81    def init(self):
82        self = super(PyObjCTestObserver, self).init()
83        if self is not None:
84            self.observed = []
85            self.willChange = []
86        return self
87
88    def observeValueForKeyPath_ofObject_change_context_(self, keyPath, obj, change, context):
89        self.observed.append( (keyPath, obj, change, context) )
90
91    def willChangeValueForKey_(self, key):
92        self.willChange.append(key)
93