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
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ downloads
.vscode
pyrightconfig.json

# Testing
.pytest_cache/
.coverage
htmlcov/
coverage.xml
.tox/
.nox/

# Claude Code
.claude/

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

# Custom
data
outputs
Expand Down
136 changes: 136 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
[tool.poetry]
name = "opus"
version = "1.0.0"
description = "OPUS: Occupancy Prediction Using a Sparse Set"
authors = ["Jiabao Wang <jbwang1997@gmail.com>", "Zhaojiang Liu <agito555@gmail.com>"]
readme = "README.md"
packages = [{include = "loaders"}, {include = "models"}]

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

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
pytest-mock = "^3.11.1"
pytest-xdist = "^3.3.1"
black = "^23.0.0"
isort = "^5.12.0"
flake8 = "^6.0.0"
mypy = "^1.5.0"
torch = ">=1.13.1"
numpy = "*"


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

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

[tool.pytest.ini_options]
minversion = "6.0"
addopts = [
"--strict-markers",
"--strict-config",
"--verbose",
"--tb=short",
"--cov=loaders",
"--cov=models",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=80",
]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
markers = [
"unit: Unit tests",
"integration: Integration tests",
"slow: Slow running tests",
"gpu: Tests requiring GPU",
]
filterwarnings = [
"error",
"ignore::UserWarning",
"ignore::DeprecationWarning",
]

[tool.coverage.run]
source = ["loaders", "models"]
omit = [
"*/tests/*",
"*/test_*.py",
"*/*_test.py",
"*/conftest.py",
"*/setup.py",
"*/models/csrc/*",
"*/lib/*",
]
branch = true

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

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

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

[tool.black]
line-length = 88
target-version = ["py38"]
include = '\.pyi?$'
extend-exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| models/csrc
| lib
)/
'''

[tool.isort]
profile = "black"
multi_line_output = 3
line_length = 88
known_first_party = ["loaders", "models"]
skip_glob = ["models/csrc/*", "lib/*"]

[tool.mypy]
python_version = "3.8"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
exclude = [
"models/csrc/",
"lib/",
"tests/",
]
100 changes: 100 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# OPUS Testing Infrastructure

This directory contains the testing infrastructure for the OPUS project.

## Structure

```
tests/
├── README.md # This file
├── __init__.py # Test package initialization
├── conftest.py # Shared pytest fixtures
├── test_basic_infrastructure.py # Basic tests (no external deps)
├── test_infrastructure.py # Full infrastructure tests (requires deps)
├── unit/ # Unit tests
│ └── __init__.py
└── integration/ # Integration tests
└── __init__.py
```

## Running Tests

### Option 1: With Poetry (Recommended for full setup)
```bash
# Install dependencies
poetry install

# Run all tests
poetry run test
# or
poetry run tests

# Run with coverage
poetry run pytest --cov

# Run specific test categories
poetry run pytest -m unit # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m "not slow" # Skip slow tests
```

### Option 2: With pip (if Poetry unavailable)
```bash
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate

# Install testing dependencies
pip install pytest pytest-cov pytest-mock torch numpy

# Run tests
pytest
```

### Option 3: Basic validation (no dependencies)
```bash
# Run basic infrastructure tests
python3 tests/test_basic_infrastructure.py
```

## Test Categories

Tests are organized with markers:
- `@pytest.mark.unit` - Fast unit tests
- `@pytest.mark.integration` - Integration tests
- `@pytest.mark.slow` - Slow-running tests
- `@pytest.mark.gpu` - Tests requiring GPU

## Coverage

Coverage is configured to:
- Measure coverage of `loaders/` and `models/` packages
- Generate HTML reports in `htmlcov/`
- Generate XML reports as `coverage.xml`
- Require minimum 80% coverage
- Exclude test files and CUDA extensions

## Fixtures

Common fixtures are available in `conftest.py`:
- `temp_dir` - Temporary directory for test files
- `mock_config` - Mock configuration dictionary
- `sample_tensor` - Sample PyTorch tensor
- `sample_batch_dict` - Sample batch data
- `mock_model` - Mock OPUS model
- And many more...

## Configuration

Test configuration is in `pyproject.toml` under:
- `[tool.pytest.ini_options]` - pytest settings
- `[tool.coverage.run]` - Coverage measurement
- `[tool.coverage.report]` - Coverage reporting

## Adding New Tests

1. Create test files with `test_*.py` naming
2. Use appropriate markers for categorization
3. Place unit tests in `tests/unit/`
4. Place integration tests in `tests/integration/`
5. Use fixtures from `conftest.py` for common test data
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Test package initialization
Loading