mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 16:13:53 +00:00
6493f496e3
* `#error BYE_BYE_GOLDEN_SNAKE` * Removing everything related to 2.7 from ci.yml * Commenting-out Centos7 * Removing `PYTHON: 27` from .appveyor.yml * "PY2" removal, mainly from tests. C++ code is not touched. * Systematic removal of `u` prefix from `u"..."` and `u'...'` literals. Collateral cleanup of a couple minor other things. * Cleaning up around case-insensitive hits for `[^a-z]py.*2` in tests/. * Removing obsolete Python 2 mention in compiling.rst * Proper `#error` for Python 2. * Using PY_VERSION_HEX to guard `#error "PYTHON 2 IS NO LONGER SUPPORTED.` * chore: bump pre-commit * style: run pre-commit for pyupgrade 3+ * tests: use sys.version_info, not PY * chore: more Python 2 removal * Uncommenting Centos7 block (PR #3691 showed that it is working again). * Update pre-commit hooks * Fix pre-commit hook * refactor: remove Python 2 from CMake * refactor: remove Python 2 from setup code * refactor: simplify, better static typing * feat: fail with nice messages * refactor: drop Python 2 C++ code * docs: cleanup for Python 3 * revert: intree revert: intree * docs: minor touchup to py2 statement Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
import pytest
|
|
|
|
m = pytest.importorskip("pybind11_tests.constants_and_functions")
|
|
|
|
|
|
def test_constants():
|
|
assert m.some_constant == 14
|
|
|
|
|
|
def test_function_overloading():
|
|
assert m.test_function() == "test_function()"
|
|
assert m.test_function(7) == "test_function(7)"
|
|
assert m.test_function(m.MyEnum.EFirstEntry) == "test_function(enum=1)"
|
|
assert m.test_function(m.MyEnum.ESecondEntry) == "test_function(enum=2)"
|
|
|
|
assert m.test_function() == "test_function()"
|
|
assert m.test_function("abcd") == "test_function(char *)"
|
|
assert m.test_function(1, 1.0) == "test_function(int, float)"
|
|
assert m.test_function(1, 1.0) == "test_function(int, float)"
|
|
assert m.test_function(2.0, 2) == "test_function(float, int)"
|
|
|
|
|
|
def test_bytes():
|
|
assert m.print_bytes(m.return_bytes()) == "bytes[1 0 2 0]"
|
|
|
|
|
|
def test_exception_specifiers():
|
|
c = m.C()
|
|
assert c.m1(2) == 1
|
|
assert c.m2(3) == 1
|
|
assert c.m3(5) == 2
|
|
assert c.m4(7) == 3
|
|
assert c.m5(10) == 5
|
|
assert c.m6(14) == 8
|
|
assert c.m7(20) == 13
|
|
assert c.m8(29) == 21
|
|
|
|
assert m.f1(33) == 34
|
|
assert m.f2(53) == 55
|
|
assert m.f3(86) == 89
|
|
assert m.f4(140) == 144
|
|
|
|
|
|
def test_function_record_leaks():
|
|
class RaisingRepr:
|
|
def __repr__(self):
|
|
raise RuntimeError("Surprise!")
|
|
|
|
with pytest.raises(RuntimeError):
|
|
m.register_large_capture_with_invalid_arguments(m)
|
|
with pytest.raises(RuntimeError):
|
|
m.register_with_raising_repr(m, RaisingRepr())
|