Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Set up comprehensive Python testing infrastructure #3

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
llbbl wants to merge 1 commit into ahmedfgad:main
base: main
Choose a base branch
Loading
from UnitSeeker:add-testing-infrastructure
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
feat: Set up comprehensive Python testing infrastructure
- Configure Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as test dependencies
- Create tests/ directory structure with unit/integration subdirectories
- Set up shared pytest fixtures in conftest.py for common test utilities
- Configure pytest with custom markers (unit, integration, slow)
- Add comprehensive .gitignore for Python development
- Include validation tests to verify testing infrastructure setup
  • Loading branch information
llbbl committed Sep 3, 2025
commit 4802399c2086f3e112281902fe8ef96332afeb6a
76 changes: 76 additions & 0 deletions .gitignore
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Testing
.pytest_cache/
.coverage
htmlcov/
coverage.xml
.tox/
.nox/

# Claude settings
.claude/*

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Jupyter
.ipynb_checkpoints

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

# Pyre
.pyre/

# pytype
.pytype/

# Cython debug symbols
cython_debug/
282 changes: 282 additions & 0 deletions poetry.lock
View file Open in desktop

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions pyproject.toml
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
[tool.poetry]
name = "ArithmeticEncodingPython"
version = "1.0.0"
description = "Data Compression using Arithmetic Encoding in Python"
authors = ["Ahmed Fawzy Gad <ahmed.f.gad@gmail.com>"]
readme = "README.md"
homepage = "https://github.com/ahmedfgad/ArithmeticEncodingPython"
repository = "https://github.com/ahmedfgad/ArithmeticEncodingPython"
keywords = ["arithmetic-encoding", "data-compression", "python"]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
packages = [{include = "pyae.py"}]

[tool.poetry.dependencies]
python = "^3.8"

[tool.poetry.group.test.dependencies]
pytest = "^8.0.0"
pytest-cov = "^4.0.0"
pytest-mock = "^3.12.0"

[tool.poetry.scripts]

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"--strict-markers",
"--strict-config",
"--verbose",
"--cov=pyae",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=80",
]
markers = [
"unit: Unit tests",
"integration: Integration tests",
"slow: Slow tests that take more time to run",
]
filterwarnings = [
"error",
"ignore::UserWarning",
"ignore::DeprecationWarning",
]

[tool.coverage.run]
source = ["."]
omit = [
"tests/*",
"setup.py",
"*/venv/*",
"*/.venv/*",
"*/site-packages/*",
"*/__pycache__/*",
]

[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__.:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
]
show_missing = true
precision = 2

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

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file added tests/__init__.py
View file Open in desktop
Empty file.
135 changes: 135 additions & 0 deletions tests/conftest.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
"""Shared pytest fixtures for the ArithmeticEncodingPython project."""

import tempfile
import shutil
from pathlib import Path
from typing import Generator, Any

import pytest


@pytest.fixture
def temp_dir() -> Generator[Path, None, None]:
"""Create a temporary directory that gets cleaned up after the test."""
temp_path = Path(tempfile.mkdtemp())
try:
yield temp_path
finally:
shutil.rmtree(temp_path, ignore_errors=True)


@pytest.fixture
def temp_file(temp_dir: Path) -> Path:
"""Create a temporary file in the temp directory."""
temp_file_path = temp_dir / "test_file.txt"
temp_file_path.touch()
return temp_file_path


@pytest.fixture
def sample_data() -> bytes:
"""Provide sample binary data for testing."""
return b"Hello, World! This is sample data for arithmetic encoding tests."


@pytest.fixture
def sample_text() -> str:
"""Provide sample text data for testing."""
return "Hello, World! This is sample text for arithmetic encoding tests."


@pytest.fixture
def sample_frequencies() -> dict[str, int]:
"""Provide sample character frequencies for testing."""
return {
'a': 5,
'b': 3,
'c': 2,
'd': 1,
'e': 8,
'f': 1,
'g': 2,
'h': 4,
'i': 6,
'j': 1,
'k': 1,
'l': 3,
'm': 2,
'n': 6,
'o': 7,
'p': 2,
'q': 1,
'r': 6,
's': 6,
't': 9,
'u': 3,
'v': 2,
'w': 2,
'x': 1,
'y': 2,
'z': 1,
' ': 10
}


@pytest.fixture
def mock_file_operations(mocker):
"""Mock file operations for testing."""
mock_open = mocker.mock_open()
mocker.patch('builtins.open', mock_open)
return mock_open


@pytest.fixture(autouse=True)
def reset_module_state():
"""Reset any global module state before each test."""
# This fixture runs automatically before each test
# Add any module-specific state reset logic here if needed
yield


@pytest.fixture
def capture_output(capsys):
"""Fixture to capture stdout/stderr output."""
def _capture():
return capsys.readouterr()
return _capture


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


@pytest.fixture
def mock_random_seed(mocker):
"""Mock random seed for reproducible tests."""
mocker.patch('random.seed')
return mocker


# Parametrized fixtures for common test scenarios
@pytest.fixture(params=[
b"a",
b"abc",
b"hello world",
b"The quick brown fox jumps over the lazy dog",
bytes(range(256)), # All possible byte values
])
def various_binary_inputs(request) -> bytes:
"""Provide various binary inputs for comprehensive testing."""
return request.param


@pytest.fixture(params=[
"",
"a",
"abc",
"hello world",
"The quick brown fox jumps over the lazy dog",
"Special chars: !@#$%^&*()_+-={}[]|\\:;\"'<>?,./"
])
def various_text_inputs(request) -> str:
"""Provide various text inputs for comprehensive testing."""
return request.param
Empty file added tests/integration/__init__.py
View file Open in desktop
Empty file.
Loading

AltStyle によって変換されたページ (->オリジナル) /