././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1773262506.2808523 pytest_cython-0.4.0/0000755000175100017510000000000015154353252014102 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/CHANGELOG.md0000644000175100017510000000313415154353244015715 0ustar00runnerrunner# Changelog ## 0.2.2 Onwards Please see the [GitHub releases](https://github.com/lgpage/pytest-cython/releases) for what has changed ## 0.2.1 The full list of merged changes is: - #26: fix: pytest_collect_file to take into account pytest fspath deprecation in Node constructors - #29: chore: use GitHub workflows in place of Travis - #30: chore: use markdown project files - #31: chore: add renovate bot Special thanks to the following contributors that made this release possible: - @AlenkaF - @shvenkat ## 0.2.0 The full list of merged changes is: - #11: Update tests - #15, #17: Dropped support for Python 2, added support for Python 3.6+ - #18: New patched pyimport implementation, maintaining better compatibility with the installed pytest version - #19: Rework how test collection works, making it possible to directly specify .pyx files to run, and reporting tests as being from the .pyx files as opposed to the compiled extension modules - #20: Fix handling of cython generated autotestdicts; prevents running the same tests repeatedly, and adds better reporting of test line numbers - #21: Add CI job with Windows - #22: Various documentation improvements Special thanks to the following contributors that made this release possible: - @embray ## 0.1.1 The full list of merged changes is: - #5: Fix DoctestModule deprecated error - #6: Fix typo from #5 - #7: Fix support for relative imports - #9: Maintain backwards compatibility for pytest 4.x Special thanks to the following contributors that made this release possible: - @embray - @thrasibule ## 0.1.0 First release on PyPI (2016-04-17) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/CODE_OF_CONDUCT.md0000644000175100017510000001215515154353244016706 0ustar00runnerrunner# Contributor Covenant Code of Conduct ## Our Pledge We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socioeconomic status, nationality, personal appearance, race, religion, or sexual identity and orientation. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. ## Our Standards Examples of behavior that contributes to a positive environment for our community include: * Demonstrating empathy and kindness toward other people * Being respectful of differing opinions, viewpoints, and experiences * Giving and gracefully accepting constructive feedback * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience * Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: * The use of sexualized language or imagery, and sexual attention or advances of any kind * Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or email address, without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. ## Scope This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at pytestcython@gmail.com. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. ## Enforcement Guidelines Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. ### 2. Warning **Community Impact**: A violation through a single incident or series of actions. **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. ### 3. Temporary Ban **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at . Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see the FAQ at . Translations are available at . ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/CONTRIBUTING.md0000644000175100017510000000450315154353244016336 0ustar00runnerrunner# Contributing Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given. ## Bug reports When [reporting a bug](https://github.com/lgpage/pytest-cython/issues) please include: - Your operating system name and version. - The `cython` and `pytest` versions you are using - Detailed steps to reproduce the bug. - Any other details about your local setup that might be helpful in troubleshooting. ## Documentation improvements `pytest-cython` could always use more documentation, whether as part of the official `pytest-cython` docs, in docstrings, or even on the web in blog posts, articles, and such. ## Feature requests and feedback The best way to send feedback is to [file an issue](https://github.com/lgpage/pytest-cython/issues). If you are proposing a new feature: - Explain in detail how it would work. - Keep the scope as narrow as possible, to make it easier to implement. - Remember that this is a volunteer-driven project, and that code contributions are welcome :) ## Development To set up `pytest-cython` for local development: 1. Fork [pytest-cython](https://github.com/lgpage/pytest-cython) (look for the \"fork\" button). 2. Clone your fork locally: ```shell git clone git@github.com:your_name_here/pytest-cython.git ``` 3. Create a branch for local development: ```shell git checkout -b name-of-your-bugfix-or-feature ``` 4. When you're done making changes, run all the checks and tests with the [nox](https://tox.wiki/en/latest) command: ```shell nox ``` 5. Commit your changes and push your branch to GitHub: ```shell git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature ``` 6. Submit a pull request through the GitHub website. ## Pull Request Guidelines If you need some code review or feedback while you're developing the code just make the pull request. Before merging, you should: 1. Update the documentation when there's new API, functionality etc. 2. Add a note to `CHANGELOG.rst` about the changes. ## Tips To list all [nox](https://tox.wiki/en/latest) tasks: ```shell nox --list ``` To run a subset of tests use one of the task from the above list, for example: ```shell nox --session "test(cython='0.29', python='3.9', pytest='7')" ``` ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/LICENSE.md0000644000175100017510000000211315154353244015504 0ustar00runnerrunnerThe MIT License (MIT) ===================== Copyright (c) 2016 Logan Page Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/MANIFEST.in0000644000175100017510000000057615154353244015651 0ustar00runnerrunnergraft tests include CHANGELOG.md include CODE_OF_CONDUCT.md include CONTRIBUTING.md include LICENSE.md include README.md global-exclude *.py[cod] __pycache__ *.so *.pyd *.dylib exclude renovate.json exclude .github/**/* exclude .vscode/* exclude tests/example-project/build/**/* exclude tests/example-project/src/pypackage/*.c exclude tests/example-project/src/pypackage/*.cpp ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1773262506.2808182 pytest_cython-0.4.0/PKG-INFO0000644000175100017510000001024115154353252015175 0ustar00runnerrunnerMetadata-Version: 2.4 Name: pytest-cython Version: 0.4.0 Summary: A plugin for testing Cython extension modules. Author-email: Logan Page , Richard Shadrach Project-URL: Documentation, https://github.com/lgpage/pytest-cython/tree/main#readme Project-URL: Source, https://github.com/lgpage/pytest-cython Project-URL: Tracker, https://github.com/lgpage/pytest-cython/issues Keywords: pytest,py.test,cython,doctest Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=3.8 Description-Content-Type: text/markdown License-File: LICENSE.md Requires-Dist: pytest>=8 Provides-Extra: lint Requires-Dist: pre-commit; extra == "lint" Requires-Dist: mypy; extra == "lint" Requires-Dist: codespell; extra == "lint" Provides-Extra: test Requires-Dist: pytest; extra == "test" Provides-Extra: dev Requires-Dist: pytest-cython[lint,test]; extra == "dev" Dynamic: license-file # Overview [![PyPI Package latest release](https://img.shields.io/pypi/v/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![PyPI Package monthly downloads](https://img.shields.io/pypi/dm/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![PyPI Wheel](https://img.shields.io/pypi/wheel/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![Supported versions](https://img.shields.io/pypi/pyversions/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![Supported implementations](https://img.shields.io/pypi/implementation/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![Conda Version](https://img.shields.io/conda/vn/conda-forge/pytest-cython.svg)](https://anaconda.org/conda-forge/pytest-cython) [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/pytest-cython.svg)](https://anaconda.org/conda-forge/pytest-cython) [![CI Lint Status](https://github.com/lgpage/pytest-cython/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/lgpage/pytest-cython/actions/workflows/lint.yml?query=branch%3Amain) [![CI Test Status](https://github.com/lgpage/pytest-cython/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/lgpage/pytest-cython/actions/workflows/test.yml?query=branch%3Amain) This [pytest](https://github.com/pytest-dev/pytest) plugin allows for the doctesting of C/C++ extension modules for Python created through [cython](https://cython.org/). ## Installation You can install `pytest-cython` via [pip](https://pypi.org/project/pip/) from [PyPI](https://pypi.org): ``` shell pip install pytest-cython ``` ## Usage Basic usage: ``` shell pytest --doctest-cython ``` You can also run the doctests for a single `.pyx` file as such: ``` shell pytest --doctest-cython path/to/module.pyx ``` ### Notes - The pytest option `--import-mode=importlib` is not supported, though we would like it to be. - When using the pytest option `--import-mode=prepend` with packages that are installed in a non-editable fashion, you must set the environment variable `PY_IGNORE_IMPORTMISMATCH=1`. ## Compatibility The following table describes the versions of Pytest and Cython the each version of the pytest-cython plugin is compatible with. | Version | Pytest | Cython | | ------- | ------ | ------- | | 0.4.x | 9 | 3 | | 0.3.x | 8 | 0.29, 3 | | 0.2.x | 6, 7 | 0.29, 3 | ## Issues If you encounter any problems, please [file an issue](https://github.com/lgpage/pytest-cython/issues) along with a detailed description. ## Acknowledgements This [pytest](https://github.com/pytest-dev/pytest) plugin was generated with [cookiecutter](https://github.com/cookiecutter/cookiecutter) along with [\@hackebrot](https://github.com/hackebrot)'s [cookiecutter-pytest-plugin](https://github.com/pytest-dev/cookiecutter-pytest-plugin) and [\@ionelmc](https://github.com/ionelmc)'s [cookiecutter-pylibrary](https://github.com/ionelmc/cookiecutter-pylibrary) templates. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/README.md0000644000175100017510000000574115154353244015371 0ustar00runnerrunner# Overview [![PyPI Package latest release](https://img.shields.io/pypi/v/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![PyPI Package monthly downloads](https://img.shields.io/pypi/dm/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![PyPI Wheel](https://img.shields.io/pypi/wheel/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![Supported versions](https://img.shields.io/pypi/pyversions/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![Supported implementations](https://img.shields.io/pypi/implementation/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![Conda Version](https://img.shields.io/conda/vn/conda-forge/pytest-cython.svg)](https://anaconda.org/conda-forge/pytest-cython) [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/pytest-cython.svg)](https://anaconda.org/conda-forge/pytest-cython) [![CI Lint Status](https://github.com/lgpage/pytest-cython/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/lgpage/pytest-cython/actions/workflows/lint.yml?query=branch%3Amain) [![CI Test Status](https://github.com/lgpage/pytest-cython/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/lgpage/pytest-cython/actions/workflows/test.yml?query=branch%3Amain) This [pytest](https://github.com/pytest-dev/pytest) plugin allows for the doctesting of C/C++ extension modules for Python created through [cython](https://cython.org/). ## Installation You can install `pytest-cython` via [pip](https://pypi.org/project/pip/) from [PyPI](https://pypi.org): ``` shell pip install pytest-cython ``` ## Usage Basic usage: ``` shell pytest --doctest-cython ``` You can also run the doctests for a single `.pyx` file as such: ``` shell pytest --doctest-cython path/to/module.pyx ``` ### Notes - The pytest option `--import-mode=importlib` is not supported, though we would like it to be. - When using the pytest option `--import-mode=prepend` with packages that are installed in a non-editable fashion, you must set the environment variable `PY_IGNORE_IMPORTMISMATCH=1`. ## Compatibility The following table describes the versions of Pytest and Cython the each version of the pytest-cython plugin is compatible with. | Version | Pytest | Cython | | ------- | ------ | ------- | | 0.4.x | 9 | 3 | | 0.3.x | 8 | 0.29, 3 | | 0.2.x | 6, 7 | 0.29, 3 | ## Issues If you encounter any problems, please [file an issue](https://github.com/lgpage/pytest-cython/issues) along with a detailed description. ## Acknowledgements This [pytest](https://github.com/pytest-dev/pytest) plugin was generated with [cookiecutter](https://github.com/cookiecutter/cookiecutter) along with [\@hackebrot](https://github.com/hackebrot)'s [cookiecutter-pytest-plugin](https://github.com/pytest-dev/cookiecutter-pytest-plugin) and [\@ionelmc](https://github.com/ionelmc)'s [cookiecutter-pylibrary](https://github.com/ionelmc/cookiecutter-pylibrary) templates. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/pyproject.toml0000644000175100017510000000410315154353244017015 0ustar00runnerrunner[project] name = "pytest-cython" description = "A plugin for testing Cython extension modules." authors = [ { name = "Logan Page", email = "page.lg@gmail.com" }, { name = "Richard Shadrach", email = "rhshadrach@gmail.com" }, ] keywords = ['pytest', 'py.test', 'cython', 'doctest'] readme = "README.md" license-files = ["LICENSE.md"] requires-python = ">= 3.8" dynamic = ["version"] dependencies = ["pytest>=8"] classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: Implementation :: CPython', 'Topic :: Software Development :: Testing', 'Topic :: Utilities', ] [tool.setuptools.dynamic] version = {file = "src/pytest_cython/VERSION"} [project.entry-points."pytest11"] pytest_cython = "pytest_cython.plugin" [project.urls] Documentation = "https://github.com/lgpage/pytest-cython/tree/main#readme" Source = "https://github.com/lgpage/pytest-cython" Tracker = "https://github.com/lgpage/pytest-cython/issues" [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [project.optional-dependencies] lint = ["pre-commit", "mypy", "codespell"] test = ["pytest"] dev = ["pytest-cython[lint, test]"] [tool.ruff.lint] unfixable = ["F401"] select = [ "A", # flake8-builtins # "ANN", # flake8-annotations "B", # flake8-bugbear "C4", # flake8-comprehensions # "D", # pydocstyle "DOC", # pydoclint "E", # pycodestyle - error "F", # Pyflakes "FA", # flake8-future-annotations # "FBT", # flake8-boolean-trap "G", # flake8-logging-format "I", # isort "INP", # flake8-no-pep420 "ISC", # flake8-implicit-str-concat "LOG", # flake8-logging "N", # pep8-naming "PERF", # Perflint "PIE", # flake8-pie "PL", # Pylint "Q", # flake8-quotes "RUF", # Ruff-specific rules "SIM", # flake8-simplify "T20", # flake8-print "UP", # pyupgrade "W", # pycodestyle - warning "YTT", # flake8-2020 ] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1773262506.2811568 pytest_cython-0.4.0/setup.cfg0000644000175100017510000000004615154353252015723 0ustar00runnerrunner[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1773262506.2723336 pytest_cython-0.4.0/src/0000755000175100017510000000000015154353252014671 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1773262506.2758434 pytest_cython-0.4.0/src/pytest_cython/0000755000175100017510000000000015154353252017605 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/src/pytest_cython/VERSION0000644000175100017510000000000615154353244020652 0ustar00runnerrunner0.4.0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/src/pytest_cython/__init__.py0000644000175100017510000000013415154353244021715 0ustar00runnerrunnerfrom importlib.metadata import version __version__ = version("pytest-cython") del version ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/src/pytest_cython/plugin.py0000644000175100017510000001034415154353244021460 0ustar00runnerrunner"""Discover and run doctests in Cython extension modules.""" from __future__ import annotations import os import pathlib import re from typing import Any, Iterable import pytest from _pytest.doctest import DoctestItem, DoctestModule from _pytest.pathlib import ImportMode, resolve_package_path CYTHON_SUFFIXES = [".pyx"] IGNORE_IMPORTMISMATCH_KEY = "PY_IGNORE_IMPORTMISMATCH" IGNORE_IMPORTMISMATCH = os.environ.get(IGNORE_IMPORTMISMATCH_KEY, "") def pytest_addoption(parser: pytest.Parser): group = parser.getgroup("cython") group.addoption( "--doctest-cython", action="store_true", default=False, help="run doctests in all .so and .pyd modules", dest="doctest_cython", ) def pytest_collect_file( file_path: pathlib.Path, parent: pytest.Collector ) -> pytest.Module: config = parent.config if file_path.suffix not in CYTHON_SUFFIXES or not config.getoption( "--doctest-cython" ): return # only run test if matching .so and .pyx files exist return _PatchedDoctestModule.from_parent(parent, path=file_path) class _PatchedDoctestModule(DoctestModule): def collect(self) -> Iterable[DoctestItem]: mode = ImportMode(self.config.getoption("importmode")) if mode is not ImportMode.importlib and IGNORE_IMPORTMISMATCH != "1": # we know we will get an import file mismatch error so ignore it for now, # we will double check the import paths after import. os.environ[IGNORE_IMPORTMISMATCH_KEY] = "1" try: items = list(super().collect()) # import the module and collect tests finally: # set ignore variable back to its original value os.environ[IGNORE_IMPORTMISMATCH_KEY] = IGNORE_IMPORTMISMATCH module = self.obj # module already imported return _add_line_numbers(module, items) def _without_suffixes(path: str | pathlib.Path) -> pathlib.Path: path = pathlib.Path(path) return path.with_name(path.name.split(".")[0]).with_suffix("") def _get_module_name(path: pathlib.Path) -> str: pkg_path = resolve_package_path(path) if pkg_path is not None: pkg_root = pkg_path.parent names = list(path.with_suffix("").relative_to(pkg_root).parts) if names[-1] == "__init__": names.pop() module_name = ".".join(names) else: pkg_root = path.parent module_name = path.stem return module_name def _add_line_numbers( module: Any, items: Iterable[DoctestItem] ) -> Iterable[DoctestItem]: # handle tests from Cython's internal __test__ dict generated by # the autotestdict directive; we exclude the tests from __test__, # though they do give us a little bonus if they exist: we can extract # the line number of the test lineno_re = re.compile(r"\(line (\d+)\)") test_dict = module.__name__ + ".__test__" test_items = {x.name: x for x in items} for test_name in list(test_items.keys()): if not test_name.startswith(test_dict + "."): continue match = lineno_re.search(test_name) lineno = int(match.group(1)) if match else None # If somehow the equivalent test does not already exist, we # keep the __test__ test (maybe it is something else not # generated by autotestdict) equiv_test_name = test_name.split()[0].replace(test_dict, module.__name__) if ( equiv_test_name not in test_items or not test_items[equiv_test_name].dtest.examples ): # for some reason the equivalent test was not found (e.g. # the module was compiled with docstrings stripped) so keep # the __test__ test but hide the fact that it came from the # __test__ dict test_items[test_name].name = equiv_test_name # set lineno on the __test__ test as well, since normally # it is not set by doctest test_items[test_name].dtest.lineno = lineno continue # Delete the __test__ test, but try to update the lineno of the # equivalent test del test_items[test_name] test_items[equiv_test_name].dtest.lineno = lineno yield from sorted(test_items.values(), key=lambda x: x.name) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1773262506.2800448 pytest_cython-0.4.0/src/pytest_cython.egg-info/0000755000175100017510000000000015154353252021277 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262506.0 pytest_cython-0.4.0/src/pytest_cython.egg-info/PKG-INFO0000644000175100017510000001024115154353252022372 0ustar00runnerrunnerMetadata-Version: 2.4 Name: pytest-cython Version: 0.4.0 Summary: A plugin for testing Cython extension modules. Author-email: Logan Page , Richard Shadrach Project-URL: Documentation, https://github.com/lgpage/pytest-cython/tree/main#readme Project-URL: Source, https://github.com/lgpage/pytest-cython Project-URL: Tracker, https://github.com/lgpage/pytest-cython/issues Keywords: pytest,py.test,cython,doctest Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=3.8 Description-Content-Type: text/markdown License-File: LICENSE.md Requires-Dist: pytest>=8 Provides-Extra: lint Requires-Dist: pre-commit; extra == "lint" Requires-Dist: mypy; extra == "lint" Requires-Dist: codespell; extra == "lint" Provides-Extra: test Requires-Dist: pytest; extra == "test" Provides-Extra: dev Requires-Dist: pytest-cython[lint,test]; extra == "dev" Dynamic: license-file # Overview [![PyPI Package latest release](https://img.shields.io/pypi/v/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![PyPI Package monthly downloads](https://img.shields.io/pypi/dm/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![PyPI Wheel](https://img.shields.io/pypi/wheel/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![Supported versions](https://img.shields.io/pypi/pyversions/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![Supported implementations](https://img.shields.io/pypi/implementation/pytest-cython.svg?style=flat)](https://pypi.org/project/pytest-cython) [![Conda Version](https://img.shields.io/conda/vn/conda-forge/pytest-cython.svg)](https://anaconda.org/conda-forge/pytest-cython) [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/pytest-cython.svg)](https://anaconda.org/conda-forge/pytest-cython) [![CI Lint Status](https://github.com/lgpage/pytest-cython/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/lgpage/pytest-cython/actions/workflows/lint.yml?query=branch%3Amain) [![CI Test Status](https://github.com/lgpage/pytest-cython/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/lgpage/pytest-cython/actions/workflows/test.yml?query=branch%3Amain) This [pytest](https://github.com/pytest-dev/pytest) plugin allows for the doctesting of C/C++ extension modules for Python created through [cython](https://cython.org/). ## Installation You can install `pytest-cython` via [pip](https://pypi.org/project/pip/) from [PyPI](https://pypi.org): ``` shell pip install pytest-cython ``` ## Usage Basic usage: ``` shell pytest --doctest-cython ``` You can also run the doctests for a single `.pyx` file as such: ``` shell pytest --doctest-cython path/to/module.pyx ``` ### Notes - The pytest option `--import-mode=importlib` is not supported, though we would like it to be. - When using the pytest option `--import-mode=prepend` with packages that are installed in a non-editable fashion, you must set the environment variable `PY_IGNORE_IMPORTMISMATCH=1`. ## Compatibility The following table describes the versions of Pytest and Cython the each version of the pytest-cython plugin is compatible with. | Version | Pytest | Cython | | ------- | ------ | ------- | | 0.4.x | 9 | 3 | | 0.3.x | 8 | 0.29, 3 | | 0.2.x | 6, 7 | 0.29, 3 | ## Issues If you encounter any problems, please [file an issue](https://github.com/lgpage/pytest-cython/issues) along with a detailed description. ## Acknowledgements This [pytest](https://github.com/pytest-dev/pytest) plugin was generated with [cookiecutter](https://github.com/cookiecutter/cookiecutter) along with [\@hackebrot](https://github.com/hackebrot)'s [cookiecutter-pytest-plugin](https://github.com/pytest-dev/cookiecutter-pytest-plugin) and [\@ionelmc](https://github.com/ionelmc)'s [cookiecutter-pylibrary](https://github.com/ionelmc/cookiecutter-pylibrary) templates. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262506.0 pytest_cython-0.4.0/src/pytest_cython.egg-info/SOURCES.txt0000644000175100017510000000203615154353252023164 0ustar00runnerrunnerCHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md LICENSE.md MANIFEST.in README.md pyproject.toml src/pytest_cython/VERSION src/pytest_cython/__init__.py src/pytest_cython/plugin.py src/pytest_cython.egg-info/PKG-INFO src/pytest_cython.egg-info/SOURCES.txt src/pytest_cython.egg-info/dependency_links.txt src/pytest_cython.egg-info/entry_points.txt src/pytest_cython.egg-info/requires.txt src/pytest_cython.egg-info/top_level.txt tests/__init__.py tests/conftest.py tests/test_pytest_cython.py tests/example-project/.gitignore tests/example-project/pyproject.toml tests/example-project/setup.py tests/example-project/src/clib/CMakeLists.txt tests/example-project/src/clib/sqrc.c tests/example-project/src/clib/sqrcpp.cpp tests/example-project/src/pypackage/__init__.py tests/example-project/src/pypackage/cython_ext_module.pxd tests/example-project/src/pypackage/cython_ext_module.pyx tests/example-project/src/pypackage/pure_py_module.py tests/example-project/src/pypackage/wrap_c_ext_module.pyx tests/example-project/src/pypackage/wrap_cpp_ext_module.pyx././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262506.0 pytest_cython-0.4.0/src/pytest_cython.egg-info/dependency_links.txt0000644000175100017510000000000115154353252025345 0ustar00runnerrunner ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262506.0 pytest_cython-0.4.0/src/pytest_cython.egg-info/entry_points.txt0000644000175100017510000000006015154353252024571 0ustar00runnerrunner[pytest11] pytest_cython = pytest_cython.plugin ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262506.0 pytest_cython-0.4.0/src/pytest_cython.egg-info/requires.txt0000644000175100017510000000013315154353252023674 0ustar00runnerrunnerpytest>=8 [dev] pytest-cython[lint,test] [lint] pre-commit mypy codespell [test] pytest ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262506.0 pytest_cython-0.4.0/src/pytest_cython.egg-info/top_level.txt0000644000175100017510000000001615154353252024026 0ustar00runnerrunnerpytest_cython ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1773262506.2775846 pytest_cython-0.4.0/tests/0000755000175100017510000000000015154353252015244 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/__init__.py0000644000175100017510000000000015154353244017344 0ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/conftest.py0000644000175100017510000000003415154353244017441 0ustar00runnerrunnerpytest_plugins = "pytester" ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1773262506.278163 pytest_cython-0.4.0/tests/example-project/0000755000175100017510000000000015154353252020343 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/.gitignore0000644000175100017510000000010315154353244022326 0ustar00runnerrunner # Ignore Cython build files src/pypackage/*.c src/pypackage/*.cpp ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/pyproject.toml0000644000175100017510000000010215154353244023251 0ustar00runnerrunner[build-system] requires = ["setuptools>=74.1", "Cython", "wheel"] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/setup.py0000644000175100017510000000131315154353244022054 0ustar00runnerrunner#!/usr/bin/env python if __name__ == "__main__": import sys from Cython.Build import cythonize from setuptools import Extension, setup directives = { "autotestdict": True, "embedsignature": False, "language_level": sys.version_info[0], "linetrace": False, "profile": False, } extensions = [Extension("*", ["src/pypackage/*.pyx"])] setup( name="pytest-cython-example", version="0.0.1", description="Example Cython project for pytest-cython tests", package_dir={"": "src"}, packages=["pypackage"], zip_safe=False, ext_modules=cythonize(extensions, compiler_directives=directives), ) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1773262506.2723336 pytest_cython-0.4.0/tests/example-project/src/0000755000175100017510000000000015154353252021132 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1773262506.2787247 pytest_cython-0.4.0/tests/example-project/src/clib/0000755000175100017510000000000015154353252022043 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/src/clib/CMakeLists.txt0000644000175100017510000000021215154353244024577 0ustar00runnerrunner cmake_minimum_required(VERSION 2.8) project (cython_example_clib) add_library(sqrc SHARED sqrc.c) add_library(sqrcpp SHARED sqrcpp.cpp) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/src/clib/sqrc.c0000644000175100017510000000012615154353244023157 0ustar00runnerrunner int isqr(int a){ return (a * a); } double dsqr(double a){ return (a * a); } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/src/clib/sqrcpp.cpp0000644000175100017510000000016015154353244024055 0ustar00runnerrunner template T vsqr(T a){ return (a * a); } template int vsqr(int); template double vsqr(double); ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1773262506.279846 pytest_cython-0.4.0/tests/example-project/src/pypackage/0000755000175100017510000000000015154353252023076 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/src/pypackage/__init__.py0000644000175100017510000000000015154353244025176 0ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/src/pypackage/cython_ext_module.pxd0000644000175100017510000000056715154353244027355 0ustar00runnerrunner cdef int cfoo(int a, int b) except? -1 cdef int cbar(int a, int b) except? -1 nogil cdef inline int cspam(int a, int b) except? -1 nogil cdef class Eggs: cdef: readonly int a readonly int b cdef int foo(Eggs self) except? -1 cdef int bar(Eggs self) except? -1 nogil cdef int spam(Eggs self) except? -1 nogil cpdef int fubar(Eggs self) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/src/pypackage/cython_ext_module.pyx0000644000175100017510000000266515154353244027403 0ustar00runnerrunner cdef int cfoo(int a, int b) except? -1: """ >>> cfoo(1, 1) 2 """ return a + b cdef int cbar(int a, int b) except? -1 nogil: """ >>> cbar(1, 1) 2 """ return a + b cdef inline int cspam(int a, int b) except? -1 nogil: """ >>> cspam(1, 1) 2 """ return (a + b) cdef class Eggs: def __init__(self, a, b): """ >>> eggs = Eggs(1, 1) >>> eggs.a 1 >>> eggs.b 1 """ self.a = a self.b = b cdef int foo(Eggs self) except? -1: """ >>> eggs = Eggs(1, 1) >>> eggs.foo() 2 """ return self.a + self.b cdef int bar(Eggs self) except? -1 nogil: """ >>> eggs = Eggs(1, 1) >>> eggs.bar() 2 """ return self.a + self.b cdef int spam(Eggs self) except? -1 nogil: """ >>> eggs = Eggs(1, 1) >>> eggs.spam() 2 """ return cspam(self.a, self.b) cpdef int fubar(Eggs self): """ >>> eggs = Eggs(1, 1) >>> eggs.fubar() 2 """ return self.a + self.b def blarg(self): """ >>> eggs = Eggs(1, 1) >>> eggs.blarg() 2 """ return self.a + self.b def failing_test(self): """ >>> eggs = Eggs(1, 1) >>> eggs.failing_test() False """ return True ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/src/pypackage/pure_py_module.py0000644000175100017510000000062415154353244026503 0ustar00runnerrunnerdef foo(a, b): """ >>> foo(1, 1) 2 """ return a + b class Eggs: def __init__(self, a, b): """ >>> eggs = Eggs(1, 1) >>> eggs.a 1 >>> eggs.b 1 """ self.a = a self.b = b def foo(self): """ >>> eggs = Eggs(1, 1) >>> eggs.foo() 2 """ return self.a + self.b ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/src/pypackage/wrap_c_ext_module.pyx0000644000175100017510000000074015154353244027342 0ustar00runnerrunner cdef extern from "../clib/sqrc.c": int isqr(int a) double dsqr(double a) def sqr(a): """ >>> sqr(2) 4 >>> '%.3g' % round(sqr(2.2), 2) '4.84' >>> sqr("asd") Traceback (most recent call last): ... TypeError: Expected int or float type input. """ if isinstance(a, (int, )): return isqr(a) elif isinstance(a, (float, )): return dsqr(a) else: raise TypeError("Expected int or float type input.") ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/example-project/src/pypackage/wrap_cpp_ext_module.pyx0000644000175100017510000000076215154353244027706 0ustar00runnerrunner# distutils: language = c++ cdef extern from "../clib/sqrcpp.cpp": T vsqr[T](T a) def sqr(a): """ >>> sqr(2) 4 >>> '%.3g' % round(sqr(2.2), 2) '4.84' >>> sqr("asd") Traceback (most recent call last): ... TypeError: Expected int or float type input. """ if isinstance(a, (int, )): return vsqr(a) elif isinstance(a, (float, )): return vsqr(a) else: raise TypeError("Expected int or float type input.") ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1773262500.0 pytest_cython-0.4.0/tests/test_pytest_cython.py0000644000175100017510000000521115154353244021571 0ustar00runnerrunnerimport pathlib # Check imports to ensure packages are installed before running tests import pypackage # noqa: F401 import pytest ROOT_PATH = pathlib.Path(__file__).parent PROJECT_PATH = ROOT_PATH.joinpath("example-project") PACKAGE_PATH = PROJECT_PATH.joinpath("src", "pypackage") # TODO: Figure out if importlib can be supported. IMPORT_MODES = ["append", "prepend"] def get_module(basename: str, suffix=".pyx") -> pathlib.Path: return PACKAGE_PATH.joinpath(basename + suffix) def run_pytest( pytester: pytest.Pytester, module: pathlib.Path, import_mode ) -> pytest.RunResult: return pytester.runpytest( "-vv", "--doctest-modules", "--doctest-cython", "--import-mode", import_mode, str(module), ) @pytest.mark.parametrize("import_mode", IMPORT_MODES) def test_cython_ext_module(pytester, import_mode): module = get_module("cython_ext_module") assert module.exists() result = run_pytest(pytester, module, import_mode) result.stdout.fnmatch_lines( [ "*Eggs.__init__*PASSED*", "*Eggs.blarg*PASSED*", "*Eggs.failing_test*FAILED*", "*Eggs.fubar*PASSED*", "*", "*FAILURES*", "*pypackage.cython_ext_module.Eggs.failing_test*", "078*", "079 >>> eggs = Eggs(1, 1)*", "080 >>> eggs.failing_test()*", "Expected:*", " False*", "Got:*", " True*", ] ) assert result.ret == 1 @pytest.mark.parametrize("import_mode", IMPORT_MODES) def test_wrap_c_ext_module(pytester, import_mode): module = get_module("wrap_c_ext_module") assert module.exists() result = run_pytest(pytester, module, import_mode) result.stdout.fnmatch_lines( [ "*sqr*PASSED*", ] ) assert result.ret == 0 @pytest.mark.parametrize("import_mode", IMPORT_MODES) def test_wrap_cpp_ext_module(pytester, import_mode): module = get_module("wrap_cpp_ext_module") assert module.exists() result = run_pytest(pytester, module, import_mode) result.stdout.fnmatch_lines( [ "*sqr*PASSED*", ] ) assert result.ret == 0 @pytest.mark.parametrize("import_mode", IMPORT_MODES) def test_pure_py_module(pytester, import_mode): module = get_module("pure_py_module", suffix=".py") assert module.exists() result = run_pytest(pytester, module, import_mode) result.stdout.fnmatch_lines( [ "*Eggs.__init__*PASSED*", "*Eggs.foo*PASSED*", "*foo*PASSED*", ] ) assert result.ret == 0