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
|
#!/usr/bin/env python
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
'''Test cases for type discovery'''
import os
import sys
import unittest
from pathlib import Path
sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from shiboken_paths import init_paths
init_paths()
from sample import (Abstract, Base1, Derived,
MDerived1, SonOfMDerived1, MDerived3)
from other import OtherMultipleDerived
class TypeDiscoveryTest(unittest.TestCase):
def testPureVirtualsOfImpossibleTypeDiscovery(self):
a = Derived.triggerImpossibleTypeDiscovery()
self.assertEqual(type(a), Abstract)
# call some pure virtual method
a.pureVirtual()
def testAnotherImpossibleTypeDiscovery(self):
a = Derived.triggerAnotherImpossibleTypeDiscovery()
self.assertEqual(type(a), Derived)
def testMultipleInheritance(self):
obj = OtherMultipleDerived.createObject("Base1")
self.assertEqual(type(obj), Base1)
# PYSIDE-868: In case of single line direct inheritance,
# a factory function will return the class wrapper
# of the derived class.
obj = OtherMultipleDerived.createObject("MDerived1")
self.assertEqual(type(obj), MDerived1)
obj = OtherMultipleDerived.createObject("SonOfMDerived1")
self.assertEqual(type(obj), SonOfMDerived1)
obj = OtherMultipleDerived.createObject("MDerived3")
self.assertEqual(type(obj), MDerived3)
# PYSIDE-868: OtherMultipleDerived inherits
# OtherBase, Base1. In this case, a factory
# function will return the base class wrapper.
obj = OtherMultipleDerived.createObject("OtherMultipleDerived")
self.assertEqual(type(obj), Base1)
if __name__ == '__main__':
unittest.main()
|