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
151 changes: 151 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# 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/

# 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
Pipfile.lock

# PEP 582
__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
.idea/
.vscode/
*.swp
*.swo
*~

# Claude settings
.claude/*

# OS
.DS_Store
Thumbs.db

# Testing artifacts
.pytest_cache/
.coverage
htmlcov/
coverage.xml
*.cover
.hypothesis/

# Virtual environments
venv/
env/
ENV/

# Package manager files
# Note: Do NOT ignore poetry.lock or uv.lock
pip-log.txt
pip-delete-this-directory.txt
282 changes: 282 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[tool.poetry]
name = "moe-plus-plus"
version = "0.1.0"
description = "MoE++ - Mixture of Experts Plus Plus implementation"
authors = ["Your Name <you@example.com>"]
readme = "README.md"
license = "MIT"
packages = [{include = "MoE++"}]

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

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

[tool.pytest.ini_options]
minversion = "7.0"
addopts = [
"-v",
"--strict-markers",
"--strict-config",
"--cov=MoE++",
"--cov-branch",
"--cov-report=term-missing:skip-covered",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=80",
]
testpaths = ["tests"]
python_files = "test_*.py"
python_classes = "Test*"
python_functions = "test_*"
markers = [
"unit: Unit tests",
"integration: Integration tests",
"slow: Slow tests",
]

[tool.coverage.run]
source = ["MoE++"]
branch = true
omit = [
"*/tests/*",
"*/__pycache__/*",
"*/conftest.py",
"*/setup.py",
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if __name__ == .__main__.:",
"raise NotImplementedError",
"pass",
"except ImportError:",
]
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.
95 changes: 95 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import os
import tempfile
from pathlib import Path
from typing import Generator, Dict, Any

import pytest


@pytest.fixture
def temp_dir() -> Generator[Path, None, None]:
"""Provide a temporary directory that gets cleaned up after the test."""
with tempfile.TemporaryDirectory() as tmpdir:
yield Path(tmpdir)


@pytest.fixture
def mock_config() -> Dict[str, Any]:
"""Provide a mock configuration dictionary for testing."""
return {
"model_name": "test_model",
"num_experts": 8,
"num_selected_experts": 2,
"hidden_size": 768,
"intermediate_size": 3072,
"num_attention_heads": 12,
"num_hidden_layers": 12,
"max_position_embeddings": 512,
"vocab_size": 50000,
"dropout_prob": 0.1,
"activation": "gelu",
}


@pytest.fixture
def sample_data() -> Dict[str, Any]:
"""Provide sample data for testing."""
return {
"inputs": [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]],
"labels": [0, 1],
"attention_mask": [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1]],
}


@pytest.fixture
def env_vars() -> Generator[None, None, None]:
"""Temporarily set environment variables for testing."""
original_env = os.environ.copy()

# Set test environment variables
os.environ["TEST_MODE"] = "true"
os.environ["LOG_LEVEL"] = "DEBUG"

yield

# Restore original environment
os.environ.clear()
os.environ.update(original_env)


@pytest.fixture(autouse=True)
def reset_modules():
"""Reset module state between tests."""
import sys
modules_to_reset = [m for m in sys.modules if m.startswith("MoE++")]
for module in modules_to_reset:
sys.modules.pop(module, None)
yield


@pytest.fixture
def mock_file_system(tmp_path: Path) -> Dict[str, Path]:
"""Create a mock file system structure for testing."""
structure = {
"config": tmp_path / "config",
"models": tmp_path / "models",
"data": tmp_path / "data",
"logs": tmp_path / "logs",
}

for directory in structure.values():
directory.mkdir(parents=True, exist_ok=True)

# Create some test files
(structure["config"] / "test_config.json").write_text('{"test": true}')
(structure["data"] / "test_data.txt").write_text("test data content")

return structure


@pytest.fixture
def capture_logs(caplog):
"""Fixture to capture log messages during tests."""
import logging
caplog.set_level(logging.DEBUG)
yield caplog
Empty file added tests/integration/__init__.py
Empty file.
Loading