You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.6 KiB

  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import sys
  4. sys.path.append('.')
  5. from example.issues import print_cchar, print_char
  6. from example.issues import DispatchIssue, dispatch_issue_go
  7. from example.issues import Placeholder, return_vec_of_reference_wrapper
  8. from example.issues import iterator_passthrough
  9. from example.issues import ElementList, ElementA, print_element
  10. from example.issues import expect_float, expect_int
  11. from example.issues import A, call_f
  12. import gc
  13. print_cchar("const char *")
  14. print_char('c')
  15. class PyClass1(DispatchIssue):
  16. def dispatch(self):
  17. print("Yay..")
  18. class PyClass2(DispatchIssue):
  19. def dispatch(self):
  20. try:
  21. super(PyClass2, self).dispatch()
  22. except Exception as e:
  23. print("Failed as expected: " + str(e))
  24. p = PyClass1()
  25. dispatch_issue_go(p)
  26. b = PyClass2()
  27. dispatch_issue_go(b)
  28. print(return_vec_of_reference_wrapper(Placeholder(4)))
  29. print(list(iterator_passthrough(iter([3, 5, 7, 9, 11, 13, 15]))))
  30. el = ElementList()
  31. for i in range(10):
  32. el.add(ElementA(i))
  33. gc.collect()
  34. for i, v in enumerate(el.get()):
  35. print("%i==%i, " % (i, v.value()), end='')
  36. print()
  37. try:
  38. print_element(None)
  39. except Exception as e:
  40. print("Failed as expected: " + str(e))
  41. try:
  42. print(expect_int(5.2))
  43. except Exception as e:
  44. print("Failed as expected: " + str(e))
  45. print(expect_float(12))
  46. class B(A):
  47. def __init__(self):
  48. super(B, self).__init__()
  49. def f(self):
  50. print("In python f()")
  51. print("C++ version")
  52. a = A()
  53. call_f(a)
  54. print("Python version")
  55. b = B()
  56. call_f(b)