Skip to content

feat: add comprehensive Python testing infrastructure with Poetry #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Testing
.pytest_cache/
.coverage
.coverage.*
htmlcov/
coverage.xml
*.cover
*.py,cover
.hypothesis/
.tox/
.nox/
coverage.json
coverage.lcov

# Virtual environments
env/
venv/
ENV/
env.bak/
venv.bak/
.python-version

# IDEs
.vscode/
.idea/
*.swp
*.swo
*~
.project
.pydevproject
.settings/
.DS_Store

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Claude
.claude/*

# Poetry (DO NOT ignore poetry.lock)
dist/

# UV (DO NOT ignore uv.lock)
1,470 changes: 1,470 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
[tool.poetry]
name = "pysift"
version = "0.1.0"
description = "A pure Python implementation of SIFT (Scale-Invariant Feature Transform)"
authors = ["Your Name <[email protected]>"]
readme = "README.md"
license = "MIT"
homepage = "https://github.com/duerrp/pysift"
repository = "https://github.com/duerrp/pysift"
keywords = ["sift", "computer-vision", "feature-detection", "image-processing"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Image Recognition",
"Topic :: Software Development :: Libraries :: Python Modules",
]

[tool.poetry.dependencies]
python = "^3.8"
numpy = "^1.19.4"
opencv-python-headless = "^4.3.0"
matplotlib = "^3.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
pytest-mock = "^3.11.1"

[tool.poetry.scripts]
test = "pytest:main"
tests = "pytest:main"

[tool.pytest.ini_options]
minversion = "7.0"
addopts = [
"-ra",
"--strict-markers",
"--strict-config",
"--cov=pysift",
"--cov-branch",
"--cov-report=term-missing:skip-covered",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=0", # Set to 80 when actual tests are added
"-vv",
]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
markers = [
"unit: marks tests as unit tests (fast, isolated)",
"integration: marks tests as integration tests (may involve external dependencies)",
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
]
filterwarnings = [
"error",
"ignore::UserWarning",
"ignore::DeprecationWarning",
]

[tool.coverage.run]
source = ["pysift"]
branch = true
parallel = true
omit = [
"*/tests/*",
"*/test_*.py",
"*/__pycache__/*",
"*/site-packages/*",
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
]
precision = 2
show_missing = true
skip_covered = false
skip_empty = true

[tool.coverage.html]
directory = "htmlcov"

[tool.coverage.xml]
output = "coverage.xml"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Empty file added tests/__init__.py
Empty file.
115 changes: 115 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import os
import tempfile
from pathlib import Path
from typing import Generator

import cv2
import numpy as np
import pytest


@pytest.fixture
def temp_dir() -> Generator[Path, None, None]:
"""Create a temporary directory for test files."""
with tempfile.TemporaryDirectory() as tmpdir:
yield Path(tmpdir)


@pytest.fixture
def sample_image() -> np.ndarray:
"""Create a simple test image."""
image = np.zeros((100, 100, 3), dtype=np.uint8)
cv2.rectangle(image, (20, 20), (80, 80), (255, 255, 255), -1)
cv2.circle(image, (50, 50), 20, (0, 0, 0), -1)
return image


@pytest.fixture
def grayscale_image() -> np.ndarray:
"""Create a simple grayscale test image."""
image = np.zeros((100, 100), dtype=np.uint8)
cv2.rectangle(image, (20, 20), (80, 80), 255, -1)
cv2.circle(image, (50, 50), 20, 0, -1)
return image


@pytest.fixture
def sample_keypoints():
"""Create sample keypoints for testing."""
keypoints = [
cv2.KeyPoint(x=10.0, y=10.0, size=5.0, angle=0.0),
cv2.KeyPoint(x=50.0, y=50.0, size=10.0, angle=45.0),
cv2.KeyPoint(x=90.0, y=90.0, size=15.0, angle=90.0),
]
return keypoints


@pytest.fixture
def sample_descriptors():
"""Create sample descriptors for testing."""
np.random.seed(42)
descriptors = np.random.randint(0, 256, (3, 128), dtype=np.uint8)
return descriptors


@pytest.fixture
def mock_config():
"""Provide a mock configuration for testing."""
return {
'sigma': 1.6,
'num_intervals': 3,
'assumed_blur': 0.5,
'image_border_width': 5,
'contrast_threshold': 0.04,
'edge_threshold': 10,
'gaussian_kernel_size': 16,
}


@pytest.fixture(autouse=True)
def reset_cv2_modules():
"""Reset cv2 modules state before each test."""
yield


@pytest.fixture
def capture_stdout(monkeypatch):
"""Capture stdout for testing print statements."""
import io
import sys

captured_output = io.StringIO()
monkeypatch.setattr(sys, 'stdout', captured_output)
return captured_output


@pytest.fixture
def test_image_path(temp_dir: Path, sample_image: np.ndarray) -> Path:
"""Save a test image to a temporary file and return its path."""
image_path = temp_dir / "test_image.png"
cv2.imwrite(str(image_path), sample_image)
return image_path


@pytest.fixture(scope="session")
def test_data_dir() -> Path:
"""Return the path to the test data directory."""
return Path(__file__).parent / "data"


@pytest.fixture
def mock_sift_detector(mocker):
"""Mock SIFT detector for testing."""
mock_detector = mocker.Mock()
mock_detector.detectAndCompute.return_value = ([], None)
return mock_detector


def pytest_configure(config):
"""Configure pytest with custom settings."""
config.addinivalue_line(
"markers", "performance: mark test as a performance test"
)
config.addinivalue_line(
"markers", "requires_display: mark test as requiring a display"
)
Empty file added tests/integration/__init__.py
Empty file.
Loading