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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
import sys
from PyQt5 import QtCore
sys.path.append(sys.argv[1])
import PyTest.CppLib
mo = PyTest.CppLib.MyObject()
assert(mo.addThree(39) == 42)
assert(mo.addThree([38, 39, 40]) == [41, 42, 43])
assert(mo.addThree("SomeString") == "DefaultSomeStringThree")
assert(mo.findNeedle(["One", "Two", "Three"], "Two") == 1)
assert(mo.findNeedle(["One", "Two", "Three"], "Four") == -1)
assert(mo.findNeedle(["One", "Two", "Three"], "Th") == 2)
assert(mo.findNeedle(["One", "Two", "Three"], "Th", QtCore.Qt.MatchExactly) == -1)
assert(mo.const_parameters(30) == 15)
assert(mo.const_parameters(30, mo) == 10)
assert(mo.qtEnumTest(QtCore.Qt.MatchContains | QtCore.Qt.MatchStartsWith) == 3)
assert(mo.localEnumTest(PyTest.CppLib.MyObject.Val2) == 2)
lfd = PyTest.CppLib.LocalFwdDecl(18)
assert(mo.localFwdDecl(lfd) == 18)
import PyTest.ExternalLib
efd = PyTest.ExternalLib.ExternalFwdDecl(18)
assert(mo.externalFwdDecl(efd) == 18)
assert(mo.localListDecl([1, 5, 7]) == 13)
lfdl = [PyTest.CppLib.LocalFwdDecl(3), PyTest.CppLib.LocalFwdDecl(6)]
assert(mo.localDeclListDecl(lfdl) == 9)
#
# Verify that an enum with attributes can be read.
#
assert(PyTest.CppLib.Foo == 0)
assert(PyTest.CppLib.Bar == 2)
class Reactor(QtCore.QObject):
def __init__(self, obj):
QtCore.QObject.__init__(self)
self.gotPrivateSlotCalledSignal = False
self.gotProtectedSlotCalledSignal = False
self.gotPublicSlotCalledSignal = False
obj.privateSlotCalled.connect(self.react_to_privateSlotCalled)
obj.protectedSlotCalled.connect(self.react_to_protectedSlotCalled)
obj.publicSlotCalled.connect(self.react_to_publicSlotCalled)
def react_to_privateSlotCalled(self):
self.gotPrivateSlotCalledSignal = True
def react_to_protectedSlotCalled(self):
self.gotProtectedSlotCalledSignal = True
def react_to_publicSlotCalled(self):
self.gotPublicSlotCalledSignal = True
class Emitter(QtCore.QObject):
privateTrigger = QtCore.pyqtSignal()
protectedTrigger = QtCore.pyqtSignal()
publicTrigger = QtCore.pyqtSignal()
def __init__(self, obj):
QtCore.QObject.__init__(self)
self.privateTrigger.connect(obj.privateSlot1)
self.protectedTrigger.connect(obj.protectedSlot1)
self.publicTrigger.connect(obj.publicSlot1)
def emitSignalForPublic(self):
self.publicTrigger.emit()
def emitSignalForPrivate(self):
self.privateTrigger.emit()
def emitSignalForProtected(self):
self.protectedTrigger.emit()
e = Emitter(mo)
r = Reactor(mo)
assert(not r.gotPrivateSlotCalledSignal)
assert(not r.gotProtectedSlotCalledSignal)
assert(not r.gotPublicSlotCalledSignal)
e.emitSignalForPrivate()
assert(r.gotPrivateSlotCalledSignal)
e.emitSignalForProtected()
assert(r.gotProtectedSlotCalledSignal)
e.emitSignalForPublic()
assert(r.gotPublicSlotCalledSignal)
assert(PyTest.CppLib.SomeNS.EnumValueOne == 1)
assert(PyTest.CppLib.SomeNS.EnumValueTwo == 2)
assert(PyTest.CppLib.SomeNS.useEnum() == 1.0)
assert(PyTest.CppLib.SomeNS.useEnum(PyTest.CppLib.SomeNS.EnumValueOne) == 1.0)
assert(PyTest.CppLib.SomeNS.useEnum(PyTest.CppLib.SomeNS.EnumValueTwo) == 2.0)
assert(PyTest.CppLib.SomeNS.customMethod([2, 3, 5]) == 10)
assert(PyTest.CppLib.anotherCustomMethod([2, 3, 5]) == 52)
sdo = PyTest.CppLib.SubdirObject()
assert(sdo.mul(5, 6) == 30)
visible = PyTest.CppLib.Visible()
assert visible.visible_fn()
try:
assert visible.invisible_fn()
assert False
except AttributeError as e:
assert str(e) == "'Visible' object has no attribute 'invisible_fn'"
try:
invisible = PyTest.CppLib.Invisible()
assert False
except AttributeError as e:
assert str(e) == "module 'PyTest.CppLib' has no attribute 'Invisible'"
concrete = PyTest.CppLib.Concrete()
assert(concrete.callableMultiply(2, 3) == 6)
assert(concrete.callableAdd(2, 3) == 5)
|