Skip to content
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
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
ENV/
.venv/
virtualenv/
.virtualenv/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
dist/
build/
develop-eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.manifest
*.spec

# Testing
.pytest_cache/
.coverage
.coverage.*
htmlcov/
coverage.xml
*.cover
*.py,cover
.hypothesis/
.tox/
nosetests.xml
pytest_cache/
test-results/
junit/

# Claude
.claude/*

# IDE
.idea/
.vscode/
*.swp
*.swo
*~
.project
.pydevproject
.settings/
*.sublime-project
*.sublime-workspace

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

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
Pipfile.lock

# PEP 582
__pypackages__/

# Celery
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.env.local
.env.*.local

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

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# Local development
local_settings.py
*.log
*.pid
instance/
.webassets-cache

# Documentation
docs/_build/
docs/.doctrees/
site/

# Temporary files
tmp/
temp/
*.tmp
*.bak
.cache/
282 changes: 282 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[tool.poetry]
name = "python-project"
version = "0.1.0"
description = "A Python project with testing infrastructure"
authors = ["Your Name <you@example.com>"]
readme = "README.md"
packages = [{include = "code"}]

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

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

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

[tool.pytest.ini_options]
minversion = "7.0"
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"--verbose",
"--strict-markers",
"--cov=code",
"--cov-report=html",
"--cov-report=xml",
"--cov-report=term-missing",
]
markers = [
"unit: marks tests as unit tests (fast, isolated)",
"integration: marks tests as integration tests (may be slower)",
"slow: marks tests as slow running",
]

[tool.coverage.run]
source = ["code"]
omit = [
"*/tests/*",
"*/__pycache__/*",
"*/venv/*",
"*/virtualenv/*",
"*/.venv/*",
"*/migrations/*",
"*/__init__.py",
]

[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",
]
precision = 2
show_missing = true
skip_covered = false

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

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

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file added tests/__init__.py
Empty file.
110 changes: 110 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import pytest
import tempfile
import shutil
from pathlib import Path
from unittest.mock import Mock, patch
import json


@pytest.fixture
def temp_dir():
"""Create a temporary directory for test files."""
temp_path = tempfile.mkdtemp()
yield Path(temp_path)
shutil.rmtree(temp_path)


@pytest.fixture
def mock_config():
"""Provide a mock configuration object."""
config = Mock()
config.debug = False
config.output_dir = "/tmp/test_output"
config.batch_size = 32
config.learning_rate = 0.001
return config


@pytest.fixture
def sample_data():
"""Provide sample data for testing."""
return {
"images": ["image1.png", "image2.png", "image3.png"],
"labels": [0, 1, 2],
"metadata": {
"dataset": "test",
"version": "1.0"
}
}


@pytest.fixture
def mock_model():
"""Provide a mock model for testing."""
model = Mock()
model.predict = Mock(return_value=[0.1, 0.8, 0.1])
model.train = Mock()
model.evaluate = Mock(return_value={"accuracy": 0.95, "loss": 0.05})
return model


@pytest.fixture
def test_image_path(temp_dir):
"""Create a test image file."""
image_path = temp_dir / "test_image.png"
image_path.write_bytes(b"fake image data")
return image_path


@pytest.fixture
def json_file(temp_dir):
"""Create a temporary JSON file."""
json_path = temp_dir / "test_data.json"

def _create_json(data):
with open(json_path, 'w') as f:
json.dump(data, f)
return json_path

return _create_json


@pytest.fixture
def capture_logs():
"""Capture log messages during tests."""
logs = []

def log_capture(message, level="INFO"):
logs.append({"message": message, "level": level})

return log_capture, logs


@pytest.fixture(autouse=True)
def reset_environment(monkeypatch):
"""Reset environment variables for each test."""
monkeypatch.setenv("PYTHONPATH", str(Path.cwd()))
monkeypatch.setenv("TEST_ENV", "true")


@pytest.fixture
def mock_file_operations():
"""Mock common file operations."""
with patch('builtins.open', create=True) as mock_open:
with patch('os.path.exists') as mock_exists:
with patch('os.makedirs') as mock_makedirs:
yield {
'open': mock_open,
'exists': mock_exists,
'makedirs': mock_makedirs
}


def pytest_configure(config):
"""Configure pytest with custom settings."""
config.addinivalue_line(
"markers", "requires_gpu: mark test as requiring GPU"
)
config.addinivalue_line(
"markers", "requires_network: mark test as requiring network access"
)
Empty file added tests/integration/__init__.py
Empty file.
Loading