-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Open
Changes from all commits
Commits
File filter
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
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
pyproject.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
Empty file.
135 changes: 135 additions & 0 deletions
tests/conftest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.