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
156 changes: 156 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# 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
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

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

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

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

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

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

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

# Pyre type checker
.pyre/

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

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

# Project specific
results/
datasets/
*.pth
*.pkl
*.h5
*.hdf5

# Claude Code settings
.claude/*
283 changes: 283 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 = "person-reid-research"
version = "0.1.0"
description = "Person Re-identification Research Project"
authors = ["Your Name <[email protected]>"]
packages = [{include = "core"}, {include = "tools"}]

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

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.0"
pytest-cov = "^4.0.0"
pytest-mock = "^3.10.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[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=core",
"--cov=tools",
"--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",
]

[tool.coverage.run]
source = ["core", "tools"]
omit = [
"*/tests/*",
"*/test_*",
"*/__pycache__/*",
"*/migrations/*",
"*/venv/*",
"*/virtualenv/*",
"*/.venv/*",
"*/.tox/*",
"*/build/*",
"*/dist/*",
]

[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"

[tool.coverage.xml]
output = "coverage.xml"
Empty file added tests/__init__.py
Empty file.
160 changes: 160 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
"""
Shared pytest fixtures for the Person ReID testing suite.
"""
import os
import tempfile
import shutil
from pathlib import Path
import pytest
from unittest.mock import Mock, MagicMock


@pytest.fixture
def temp_dir():
"""Create a temporary directory for testing."""
temp_path = tempfile.mkdtemp()
yield temp_path
shutil.rmtree(temp_path, ignore_errors=True)


@pytest.fixture
def temp_file():
"""Create a temporary file for testing."""
with tempfile.NamedTemporaryFile(delete=False) as tmp:
temp_path = tmp.name
yield temp_path
try:
os.unlink(temp_path)
except FileNotFoundError:
pass


@pytest.fixture
def mock_config():
"""Mock configuration object for testing."""
config = Mock()
config.cuda = 'cuda'
config.mode = 'train'
config.output_path = '/tmp/test_output'
config.market_path = '/tmp/market'
config.duke_path = '/tmp/duke'
config.train_dataset = 'market'
config.test_dataset = 'market'
config.image_size = [384, 192]
config.mis_align_ratio = 0.05
config.use_rea = True
config.p = 18
config.k = 4
config.part_num = 6
config.pid_num = 751
config.margin = 0.3
config.milestones = [50, 80, 100]
config.base_learning_rate = 0.5
config.total_train_epochs = 120
config.auto_resume_training_from_lastest_steps = True
config.max_save_model_num = 1
config.resume_test_model = '/path/to/model.pth'
config.test_mode = 'inter-camera'
config.resume_visualize_model = '/path/to/model.pkl'
config.visualize_dataset = 'market'
config.visualize_mode = 'inter-camera'
config.visualize_output_path = '/tmp/visualization'
return config


@pytest.fixture
def mock_dataset_paths(temp_dir):
"""Create mock dataset directory structure."""
market_path = Path(temp_dir) / "market"
duke_path = Path(temp_dir) / "duke"

# Create basic directory structure
for dataset_path in [market_path, duke_path]:
dataset_path.mkdir(exist_ok=True)
(dataset_path / "bounding_box_train").mkdir(exist_ok=True)
(dataset_path / "bounding_box_test").mkdir(exist_ok=True)
(dataset_path / "query").mkdir(exist_ok=True)

return {
'market': str(market_path),
'duke': str(duke_path)
}


@pytest.fixture
def mock_model():
"""Mock neural network model for testing."""
model = MagicMock()
model.eval.return_value = model
model.train.return_value = model
model.cuda.return_value = model
model.parameters.return_value = []
return model


@pytest.fixture
def mock_dataloader():
"""Mock dataloader for testing."""
loader = MagicMock()
loader.__iter__ = MagicMock(return_value=iter([]))
loader.__len__ = MagicMock(return_value=0)
return loader


@pytest.fixture
def mock_optimizer():
"""Mock optimizer for testing."""
optimizer = MagicMock()
optimizer.zero_grad = MagicMock()
optimizer.step = MagicMock()
optimizer.state_dict = MagicMock(return_value={})
optimizer.load_state_dict = MagicMock()
return optimizer


@pytest.fixture
def mock_logger():
"""Mock logger for testing."""
logger = MagicMock()
logger.info = MagicMock()
logger.error = MagicMock()
logger.warning = MagicMock()
return logger


@pytest.fixture(autouse=True)
def reset_environment():
"""Reset environment variables before each test."""
original_env = os.environ.copy()
yield
os.environ.clear()
os.environ.update(original_env)


@pytest.fixture
def sample_image_tensor():
"""Create a sample image tensor for testing."""
try:
import torch
return torch.randn(3, 384, 192)
except ImportError:
# If torch is not available, return None
return None


@pytest.fixture
def sample_batch():
"""Create a sample batch of data for testing."""
try:
import torch
return {
'images': torch.randn(32, 3, 384, 192),
'pids': torch.randint(0, 751, (32,)),
'camids': torch.randint(0, 6, (32,))
}
except ImportError:
return {
'images': None,
'pids': list(range(32)),
'camids': list(range(32))
}
Empty file added tests/integration/__init__.py
Empty file.
Loading