test_constants_and_functions.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from pybind11_tests import constants_and_functions as m
  2. def test_constants():
  3. assert m.some_constant == 14
  4. def test_function_overloading():
  5. assert m.test_function() == "test_function()"
  6. assert m.test_function(7) == "test_function(7)"
  7. assert m.test_function(m.MyEnum.EFirstEntry) == "test_function(enum=1)"
  8. assert m.test_function(m.MyEnum.ESecondEntry) == "test_function(enum=2)"
  9. assert m.test_function() == "test_function()"
  10. assert m.test_function("abcd") == "test_function(char *)"
  11. assert m.test_function(1, 1.0) == "test_function(int, float)"
  12. assert m.test_function(1, 1.0) == "test_function(int, float)"
  13. assert m.test_function(2.0, 2) == "test_function(float, int)"
  14. def test_bytes():
  15. assert m.print_bytes(m.return_bytes()) == "bytes[1 0 2 0]"
  16. def test_exception_specifiers():
  17. c = m.C()
  18. assert c.m1(2) == 1
  19. assert c.m2(3) == 1
  20. assert c.m3(5) == 2
  21. assert c.m4(7) == 3
  22. assert c.m5(10) == 5
  23. assert c.m6(14) == 8
  24. assert c.m7(20) == 13
  25. assert c.m8(29) == 21
  26. assert m.f1(33) == 34
  27. assert m.f2(53) == 55
  28. assert m.f3(86) == 89
  29. assert m.f4(140) == 144