Skip to content

Commit

Permalink
PythonBind ABI: testing aggregate type conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipul-Cariappa committed Aug 18, 2024
1 parent b6cbaa0 commit 4f6714f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ RUN(NAME bindpy_02 LABELS cpython c_py EXTRA_ARGS --link-numpy COPY_TO
RUN(NAME bindpy_03 LABELS cpython c_py EXTRA_ARGS --link-numpy NOFAST COPY_TO_BIN bindpy_03_module.py)
RUN(NAME bindpy_04 LABELS cpython c_py EXTRA_ARGS --link-numpy NOFAST COPY_TO_BIN bindpy_04_module.py)
RUN(NAME bindpy_05 LABELS llvm_py c_py EXTRA_ARGS --enable-cpython COPY_TO_BIN bindpy_05_module.py REQ_PY_VER 3.10)
RUN(NAME bindpy_06 LABELS llvm_py EXTRA_ARGS --enable-cpython COPY_TO_BIN bindpy_06_module.py REQ_PY_VER 3.10)
RUN(NAME test_generics_01 LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME test_cmath LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME test_complex_01 LABELS cpython llvm llvm_jit c wasm wasm_x64)
Expand Down
72 changes: 72 additions & 0 deletions integration_tests/bindpy_06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from lpython import i32, f64, pythoncall, Const
from numpy import empty, int32, float64


@pythoncall(module = "bindpy_06_module")
def get_cpython_version() -> str:
pass


@pythoncall(module = "bindpy_06_module")
def get_modified_dict(d: dict[str, i32]) -> dict[str, i32]:
pass


@pythoncall(module = "bindpy_06_module")
def get_modified_list(d: list[str]) -> list[str]:
pass

@pythoncall(module = "bindpy_06_module")
def get_modified_tuple(t: tuple[i32, i32]) -> tuple[i32, i32, i32]:
pass


@pythoncall(module = "bindpy_06_module")
def get_modified_set(s: set[i32]) -> set[i32]:
pass


def test_list():
l: list[str] = ["LPython"]
lr: list[str] = get_modified_list(l)
assert len(lr) == 2
assert lr[0] == "LPython"
assert lr[1] == "LFortran"


def test_tuple():
t: tuple[i32, i32] = (2, 4)
tr: tuple[i32, i32, i32] = get_modified_tuple(t)
assert tr[0] == t[0]
assert tr[1] == t[1]
assert tr[2] == t[0] + t[1]


def test_set():
s: set[i32] = {1, 2, 3}
sr: set[i32] = get_modified_set(s)
assert len(sr) == 4
assert 1 in sr
assert 2 in sr
assert 3 in sr
assert 100 in sr


def test_dict():
d: dict[str, i32] = {
"LPython": 50
}
dr: dict[str, i32] = get_modified_dict(d)
assert len(dr) == 2
assert dr["LPython"] == 50
assert dr["LFortran"] == 100


def main0():
test_list()
test_tuple()
test_set()
test_dict()


main0()
24 changes: 24 additions & 0 deletions integration_tests/bindpy_06_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import platform


def get_cpython_version():
return platform.python_version()


def get_modified_dict(d):
d["LFortran"] = 100
return d


def get_modified_list(l):
l.append("LFortran")
return l


def get_modified_tuple(t):
return (t[0], t[1], t[0] + t[1])


def get_modified_set(s):
s.add(100)
return s

0 comments on commit 4f6714f

Please sign in to comment.