示例工程 25-c-extensions-ctypes-cffi
25-c-extensions-ctypes-cffi/01-ctypes-libc/test_ctypes_libc.py
"""test_ctypes_libc.py"""
from __future__ import annotations
import pytest
from ctypes_libc import c_strlen, main
def test_strlen_ascii() -> None:
assert c_strlen("hello") == 5
assert c_strlen("") == 0
def test_strlen_utf8_bytes() -> None:
assert c_strlen("你好") == 6
def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None:
main()
out = capsys.readouterr().out
assert "strlen('hello'): 5" in out
assert "strlen('你好'): 6" in out