Rename examples files, as per #288
This renames example files from `exampleN` to `example-description`.
Specifically, the following renaming is applied:
example1 -> example-methods-and-attributes
example2 -> example-python-types
example3 -> example-operator-overloading
example4 -> example-constants-and-functions
example5 -> example-callbacks (*)
example6 -> example-sequence-and-iterators
example7 -> example-buffers
example8 -> example-custom-ref-counting
example9 -> example-modules
example10 -> example-numpy-vectorize
example11 -> example-arg-keywords-and-defaults
example12 -> example-virtual-functions
example13 -> example-keep-alive
example14 -> example-opaque-types
example15 -> example-pickling
example16 -> example-inheritance
example17 -> example-stl-binders
example18 -> example-eval
example19 -> example-custom-exceptions
* the inheritance parts of example5 are moved into example-inheritance
(previously example16), and the remainder is left as example-callbacks.
This commit also renames the internal variables ("Example1",
"Example2", "Example4", etc.) into non-numeric names ("ExampleMandA",
"ExamplePythonTypes", "ExampleWithEnum", etc.) to correspond to the
file renaming.
The order of tests is preserved, but this can easily be changed if
there is some more natural ordering by updating the list in
examples/CMakeLists.txt.
2016-07-18 20:43:18 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
import sys
|
|
|
|
sys.path.append('.')
|
|
|
|
|
|
|
|
from example import ExampleVirt, runExampleVirt, runExampleVirtVirtual, runExampleVirtBool
|
2016-08-05 21:44:28 +00:00
|
|
|
from example import A_Repeat, B_Repeat, C_Repeat, D_Repeat, A_Tpl, B_Tpl, C_Tpl, D_Tpl
|
Rename examples files, as per #288
This renames example files from `exampleN` to `example-description`.
Specifically, the following renaming is applied:
example1 -> example-methods-and-attributes
example2 -> example-python-types
example3 -> example-operator-overloading
example4 -> example-constants-and-functions
example5 -> example-callbacks (*)
example6 -> example-sequence-and-iterators
example7 -> example-buffers
example8 -> example-custom-ref-counting
example9 -> example-modules
example10 -> example-numpy-vectorize
example11 -> example-arg-keywords-and-defaults
example12 -> example-virtual-functions
example13 -> example-keep-alive
example14 -> example-opaque-types
example15 -> example-pickling
example16 -> example-inheritance
example17 -> example-stl-binders
example18 -> example-eval
example19 -> example-custom-exceptions
* the inheritance parts of example5 are moved into example-inheritance
(previously example16), and the remainder is left as example-callbacks.
This commit also renames the internal variables ("Example1",
"Example2", "Example4", etc.) into non-numeric names ("ExampleMandA",
"ExamplePythonTypes", "ExampleWithEnum", etc.) to correspond to the
file renaming.
The order of tests is preserved, but this can easily be changed if
there is some more natural ordering by updating the list in
examples/CMakeLists.txt.
2016-07-18 20:43:18 +00:00
|
|
|
|
|
|
|
class ExtendedExampleVirt(ExampleVirt):
|
|
|
|
def __init__(self, state):
|
|
|
|
super(ExtendedExampleVirt, self).__init__(state + 1)
|
|
|
|
self.data = "Hello world"
|
|
|
|
|
|
|
|
def run(self, value):
|
|
|
|
print('ExtendedExampleVirt::run(%i), calling parent..' % value)
|
|
|
|
return super(ExtendedExampleVirt, self).run(value + 1)
|
|
|
|
|
|
|
|
def run_bool(self):
|
|
|
|
print('ExtendedExampleVirt::run_bool()')
|
|
|
|
return False
|
|
|
|
|
|
|
|
def pure_virtual(self):
|
|
|
|
print('ExtendedExampleVirt::pure_virtual(): %s' % self.data)
|
|
|
|
|
|
|
|
|
|
|
|
ex12 = ExampleVirt(10)
|
|
|
|
print(runExampleVirt(ex12, 20))
|
|
|
|
try:
|
|
|
|
runExampleVirtVirtual(ex12)
|
|
|
|
except Exception as e:
|
|
|
|
print("Caught expected exception: " + str(e))
|
|
|
|
|
|
|
|
ex12p = ExtendedExampleVirt(10)
|
|
|
|
print(runExampleVirt(ex12p, 20))
|
|
|
|
print(runExampleVirtBool(ex12p))
|
|
|
|
runExampleVirtVirtual(ex12p)
|
2016-08-05 21:02:33 +00:00
|
|
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
class VI_AR(A_Repeat):
|
|
|
|
def unlucky_number(self):
|
|
|
|
return 99
|
|
|
|
class VI_AT(A_Tpl):
|
|
|
|
def unlucky_number(self):
|
|
|
|
return 999
|
|
|
|
|
|
|
|
class VI_CR(C_Repeat):
|
|
|
|
def lucky_number(self):
|
|
|
|
return C_Repeat.lucky_number(self) + 1.25
|
|
|
|
class VI_CT(C_Tpl):
|
|
|
|
pass
|
|
|
|
class VI_CCR(VI_CR):
|
|
|
|
def lucky_number(self):
|
|
|
|
return VI_CR.lucky_number(self) * 10
|
|
|
|
class VI_CCT(VI_CT):
|
|
|
|
def lucky_number(self):
|
|
|
|
return VI_CT.lucky_number(self) * 1000
|
|
|
|
|
|
|
|
|
|
|
|
class VI_DR(D_Repeat):
|
|
|
|
def unlucky_number(self):
|
|
|
|
return 123
|
|
|
|
def lucky_number(self):
|
|
|
|
return 42.0
|
|
|
|
class VI_DT(D_Tpl):
|
|
|
|
def say_something(self, times):
|
|
|
|
print("VI_DT says:" + (' quack' * times))
|
|
|
|
def unlucky_number(self):
|
|
|
|
return 1234
|
|
|
|
def lucky_number(self):
|
|
|
|
return -4.25
|
|
|
|
|
|
|
|
classes = [
|
2016-08-05 21:44:28 +00:00
|
|
|
# A_Repeat, A_Tpl, # abstract (they have a pure virtual unlucky_number)
|
|
|
|
VI_AR, VI_AT,
|
|
|
|
B_Repeat, B_Tpl,
|
|
|
|
C_Repeat, C_Tpl,
|
|
|
|
VI_CR, VI_CT, VI_CCR, VI_CCT,
|
|
|
|
D_Repeat, D_Tpl, VI_DR, VI_DT
|
2016-08-05 21:02:33 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for cl in classes:
|
|
|
|
print("\n%s:" % cl.__name__)
|
|
|
|
obj = cl()
|
|
|
|
obj.say_something(3)
|
|
|
|
print("Unlucky = %d" % obj.unlucky_number())
|
|
|
|
if hasattr(obj, "lucky_number"):
|
|
|
|
print("Lucky = %.2f" % obj.lucky_number())
|
|
|
|
|