Skip to content

Commit

Permalink
Add NULL singleton tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ionite34 committed Feb 8, 2023
1 parent a694936 commit a685ed0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/structs/test_null.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Test behavior of the `types.NULL` singleton."""
from __future__ import annotations

from einspect import NULL
from einspect.structs import PyTupleObject, PyTypeObject


def test_func_ptr():
"""Test that NULL can be used as a function pointer."""

t = PyTypeObject(int)
n = t.tp_as_number.contents
assert n.nb_add != NULL
# Null FuncPtr should equal NULL
assert n.nb_matrix_multiply == NULL
# We can set this to NULL, and it'll invoke type(FuncPtr)()
n.nb_matrix_multiply = NULL
assert n.nb_matrix_multiply == NULL


def test_py_object():
"""Test usage as a NULL PyObject pointer."""

s = PyTupleObject(
ob_refcnt=1,
ob_type=PyTypeObject(tuple).as_ref(),
ob_size=2,
ob_item=[NULL] * 2,
)
assert not s.ob_item[0]
assert not s.ob_item[1]
assert s.ob_item[0] == NULL
assert s.ob_item[1] == NULL

0 comments on commit a685ed0

Please sign in to comment.