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
126 changes: 126 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# 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/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
*.manifest
*.spec

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

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

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

# macOS
.DS_Store
.AppleDouble
.LSOverride

# Windows
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
*.stackdump
[Dd]esktop.ini

# Claude AI
.claude/*

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# pipenv
Pipfile.lock

# PEP 582
__pypackages__/

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

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

# Pyre type checker
.pyre/

# Local data
data/
*.pth
*.pt
checkpoint/
checkpoints/
logs/
runs/

# Temporary files
*.tmp
*.bak
*.swp
*~
.#*
1,733 changes: 1,733 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[tool.poetry]
name = "augmix"
version = "0.1.0"
description = "AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty"
authors = ["Your Name <you@example.com>"]
readme = "README.md"
packages = [{include = "*.py"}, {include = "models"}, {include = "third_party"}]

[tool.poetry.dependencies]
python = "^3.8"
numpy = ">=1.15.0"
Pillow = ">=6.1.0"
torch = ">=1.9.0"
torchvision = ">=0.10.0"

[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 = [
"--strict-markers",
"--strict-config",
"--verbose",
"--cov=.",
"--cov-branch",
"--cov-report=term-missing:skip-covered",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=0" # TODO: Set to 80 once tests are written
]
markers = [
"unit: Unit tests",
"integration: Integration tests",
"slow: Slow running tests"
]

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

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"if typing.TYPE_CHECKING:"
]
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.
131 changes: 131 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
"""Shared pytest fixtures and configuration."""
import os
import sys
import tempfile
from pathlib import Path
from typing import Generator

import pytest

# Add the project root to the Python path
sys.path.insert(0, str(Path(__file__).parent.parent))


@pytest.fixture
def temp_dir() -> Generator[Path, None, None]:
"""Create a temporary directory for testing.

Yields:
Path: Path to the temporary directory
"""
with tempfile.TemporaryDirectory() as temp_dir:
yield Path(temp_dir)


@pytest.fixture
def mock_config() -> dict:
"""Provide a mock configuration dictionary for testing.

Returns:
dict: Mock configuration with common settings
"""
return {
"batch_size": 32,
"num_workers": 2,
"learning_rate": 0.001,
"epochs": 10,
"augmentation": {
"severity": 3,
"width": 3,
"depth": -1,
"alpha": 1.0
}
}


@pytest.fixture
def sample_image_path(temp_dir: Path) -> Path:
"""Create a dummy image file for testing.

Args:
temp_dir: Temporary directory fixture

Returns:
Path: Path to the created dummy image file
"""
image_path = temp_dir / "test_image.jpg"
# Create a dummy file (actual image content not needed for most tests)
image_path.write_bytes(b"dummy image content")
return image_path


@pytest.fixture
def mock_dataset_config() -> dict:
"""Provide mock dataset configuration.

Returns:
dict: Mock dataset configuration
"""
return {
"name": "cifar10",
"data_dir": "./data",
"num_classes": 10,
"image_size": 32,
"mean": [0.4914, 0.4822, 0.4465],
"std": [0.2023, 0.1994, 0.2010]
}


@pytest.fixture(autouse=True)
def reset_random_seeds():
"""Reset random seeds before each test for reproducibility."""
import random
import numpy as np

random.seed(42)
np.random.seed(42)

# Only set torch seed if torch is available
try:
import torch
torch.manual_seed(42)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(42)
except ImportError:
pass


@pytest.fixture
def capture_output():
"""Capture stdout and stderr for testing print statements.

Yields:
tuple: (stdout, stderr) StringIO objects
"""
from io import StringIO
import sys

old_stdout = sys.stdout
old_stderr = sys.stderr

sys.stdout = StringIO()
sys.stderr = StringIO()

yield sys.stdout, sys.stderr

sys.stdout = old_stdout
sys.stderr = old_stderr


# Markers for different test types
def pytest_configure(config):
"""Configure pytest with custom markers."""
config.addinivalue_line(
"markers", "unit: Unit tests that test individual components"
)
config.addinivalue_line(
"markers", "integration: Integration tests that test component interactions"
)
config.addinivalue_line(
"markers", "slow: Tests that take a long time to run"
)
Empty file added tests/integration/__init__.py
Empty file.
Loading