Skip to main content

CPYTEST

Pipeline Status Test Coverage PyPI - Python Version PyPI - License

CPYTEST is a python package that allows you to write unit tests for your C code. It uses cffi to generate python bindings for C code, so that you can use the full pytest framework for testing your C code.

Installation

t.b.d.

Runing the Example

Dependencies

pip install poetry pytest
sudo apt install gcovr
sudo apt install lcov

Build and Run Example Test

Using Poetry

poetry install
poetry run pip install pycparser==2.21
poetry run python3 -m cpytest example/test/cpytest.yaml
poetry run pytest example/test/test_example.py

Using virtualenv

virtualenv .venv
source .venv/bin/activate
poetry install
poetry run pip install pycparser==2.21
python3 -m cpytest example/test/cpytest.yaml
pytest example/test/test_example.py

Generate Coverage

lcov --capture --directory example/src --base-directory example/test/build --output-file coverage.info --rc lcov_branch_coverage=1 --no-external
genhtml coverage.info --output-directory coverage_report --rc genhtml_branch_coverage=1
ls coverage_report/index.html

Limitations

pycparser / pycparserext version conflict

pycparserext requires pycparser==2.20, but we need pycparser==2.21 (for #pragma support). poetry doesn't solve this conflict for us, but we can manually install pycparser=2.21 using poetry: poetry run pip install pycparser==2.21. The corresponding pip install error that is shown can be ignored.

#pragma vs. __attribute__((packed)) support

pycparser doesn't support __attribute__((packed)) on structs, but it supports #pragma pack. We need to use #pragma pack in order to the correct python code for packed structs.

__attribute__ limitations of pycparserext

pycparserext has only limited support for GCC __attribute__ extensions. To avoid problems, we run a postprocessor after the preprocessor, which filters out all __attribute__ extensions.

Development

Run QA

tox is used to run all QA tools at once.

tox

Docker

Run the Example

cd docker
docker-compose up --build test-example-project
docker-compose down

Run the interactive docker shell

docker-compose up --build -d shell
docker-compose exec shell bash
docker-compose down

Metadata

Release files for cpytest 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cpytest 0.1.2
File Size Uploaded Provenance Actions
cpytest-0.1.2.tar.gz 20.6 kB Without provenance Details for cpytest-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cpytest 0.1.2
File Interpreter ABI Platform Actions
cpytest-0.1.2-py3-none-any.whl Python 3 none any Details for cpytest-0.1.2-py3-none-any.whl

Total release size: 44.1 kB

Release files / cpytest-0.1.2.tar.gz

Download URL cpytest-0.1.2.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b3c65f887c34c9f023a74d8697c1209c41c0873dcbe1a7d6ff53d44eb78e17ef
BLAKE2b-256 checksum
How to use checksums
788adddf3537aaeadb397291803439300089c68850ac4ca07fd4388215ced1dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / cpytest-0.1.2-py3-none-any.whl

Download URL cpytest-0.1.2-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3d86952c8fd3ec56ea42ec18392e2d48c9fd3f242dc60ff2e4ff83028613149
BLAKE2b-256 checksum
How to use checksums
0260ae58edf5cd05df323c862bed340218ca9802ae046c259fb0ce013e41a797
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Security for cpytest 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page