Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test nb::int_(double). #793

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/test_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ NB_MODULE(test_functions_ext, m) {
m.def("test_19", [](nb::int_ i) { return i + nb::int_(123); });
m.def("test_20", [](nb::str s) { return nb::int_(s) + nb::int_(123); });
m.def("test_21", [](nb::int_ i) { return (int) i; });
m.def("test_21_f", [](nb::float_ f) { return nb::int_(f); });
m.def("test_21_g", []() { return nb::int_(1.5); });
m.def("test_21_h", []() { return nb::int_(1e50); });

// Test capsule wrapper
m.def("test_22", []() -> void * { return (void*) 1; });
Expand Down
7 changes: 7 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ def test25_int():
assert t.test_19(5) == 128
assert t.test_20("5") == 128
assert t.test_21(5) == 5
assert t.test_21_f(5.1) == int(5.1)
assert t.test_21_f(1e50) == int(1e50)
assert type(t.test_21_f(0.5)) is int
assert t.test_21_g() == int(1.5)
assert type(t.test_21_g()) is int
assert t.test_21_h() == int(1e50)
assert type(t.test_21_h()) is int
assert t.test_19.__doc__ == "test_19(arg: int, /) -> object"


Expand Down
6 changes: 6 additions & 0 deletions tests/test_functions_ext.pyi.ref
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ def test_20(arg: str, /) -> object: ...

def test_21(arg: int, /) -> int: ...

def test_21_f(arg: float, /) -> int: ...

def test_21_g() -> int: ...

def test_21_h() -> int: ...

def test_22() -> types.CapsuleType: ...

def test_23() -> types.CapsuleType: ...
Expand Down
Loading