The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

71 lines
2.2 KiB

2 months ago
  1. def test_nested_modules():
  2. import pybind11_tests
  3. from pybind11_tests.submodule import submodule_func
  4. assert pybind11_tests.__name__ == "pybind11_tests"
  5. assert pybind11_tests.submodule.__name__ == "pybind11_tests.submodule"
  6. assert submodule_func() == "submodule_func()"
  7. def test_reference_internal():
  8. from pybind11_tests import ConstructorStats
  9. from pybind11_tests.submodule import A, B
  10. b = B()
  11. assert str(b.get_a1()) == "A[1]"
  12. assert str(b.a1) == "A[1]"
  13. assert str(b.get_a2()) == "A[2]"
  14. assert str(b.a2) == "A[2]"
  15. b.a1 = A(42)
  16. b.a2 = A(43)
  17. assert str(b.get_a1()) == "A[42]"
  18. assert str(b.a1) == "A[42]"
  19. assert str(b.get_a2()) == "A[43]"
  20. assert str(b.a2) == "A[43]"
  21. astats, bstats = ConstructorStats.get(A), ConstructorStats.get(B)
  22. assert astats.alive() == 2
  23. assert bstats.alive() == 1
  24. del b
  25. assert astats.alive() == 0
  26. assert bstats.alive() == 0
  27. assert astats.values() == ['1', '2', '42', '43']
  28. assert bstats.values() == []
  29. assert astats.default_constructions == 0
  30. assert bstats.default_constructions == 1
  31. assert astats.copy_constructions == 0
  32. assert bstats.copy_constructions == 0
  33. # assert astats.move_constructions >= 0 # Don't invoke any
  34. # assert bstats.move_constructions >= 0 # Don't invoke any
  35. assert astats.copy_assignments == 2
  36. assert bstats.copy_assignments == 0
  37. assert astats.move_assignments == 0
  38. assert bstats.move_assignments == 0
  39. def test_importing():
  40. from pybind11_tests import OD
  41. from collections import OrderedDict
  42. assert OD is OrderedDict
  43. assert str(OD([(1, 'a'), (2, 'b')])) == "OrderedDict([(1, 'a'), (2, 'b')])"
  44. def test_pydoc():
  45. """Pydoc needs to be able to provide help() for everything inside a pybind11 module"""
  46. import pybind11_tests
  47. import pydoc
  48. assert pybind11_tests.__name__ == "pybind11_tests"
  49. assert pybind11_tests.__doc__ == "pybind11 test module"
  50. assert pydoc.text.docmodule(pybind11_tests)
  51. def test_duplicate_registration():
  52. """Registering two things with the same name"""
  53. from pybind11_tests import duplicate_registration
  54. assert duplicate_registration() == []