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
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,53 @@
node_modules
package-lock.json
gen

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

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

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

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

# Claude settings
.claude/*
282 changes: 282 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[tool.poetry]
name = "v8-tools"
version = "0.1.0"
description = "V8 tools and utilities"
authors = ["Your Name <your.email@example.com>"]
readme = "README.md"
package-mode = false

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

[tool.poetry.group.test.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
pytest-mock = "^3.11.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=.",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=80",
]
markers = [
"unit: marks tests as unit tests",
"integration: marks tests as integration tests",
"slow: marks tests as slow running",
]

[tool.coverage.run]
source = ["."]
omit = [
"*/tests/*",
"*/test_*.py",
"*/__pycache__/*",
"*/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",
]
precision = 2
show_missing = true

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

[tool.coverage.xml]
output = "coverage.xml"
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
157 changes: 157 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
"""Shared pytest fixtures for all tests."""
import tempfile
import pytest
from pathlib import Path
from unittest.mock import Mock, patch
import os
import shutil


@pytest.fixture
def temp_dir():
"""Create a temporary directory for test files."""
with tempfile.TemporaryDirectory() as tmp_dir:
yield Path(tmp_dir)


@pytest.fixture
def temp_file():
"""Create a temporary file for tests."""
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
yield Path(tmp_file.name)
# Clean up
try:
os.unlink(tmp_file.name)
except FileNotFoundError:
pass


@pytest.fixture
def mock_subprocess():
"""Mock subprocess.run for testing command execution."""
with patch('subprocess.run') as mock_run:
mock_run.return_value.returncode = 0
mock_run.return_value.stdout = b"mock output"
mock_run.return_value.stderr = b""
yield mock_run


@pytest.fixture
def mock_git():
"""Mock git commands for testing."""
with patch('subprocess.run') as mock_run:
mock_run.return_value.returncode = 0
mock_run.return_value.stdout = b"mock git output"
mock_run.return_value.check_returncode.return_value = None
yield mock_run


@pytest.fixture
def sample_config():
"""Provide sample configuration data for tests."""
return {
"destination": "/tmp/test",
"v8_git": "/tmp/v8",
"oldest_version": (8, 6),
"branches": ["main", "10.0-lkgr"]
}


@pytest.fixture
def mock_path_exists():
"""Mock Path.exists() method for testing file system operations."""
with patch.object(Path, 'exists') as mock_exists:
mock_exists.return_value = True
yield mock_exists


@pytest.fixture
def mock_file_operations():
"""Mock file read/write operations."""
mock_data = {}

def mock_read_text(self):
return mock_data.get(str(self), "")

def mock_write_text(self, content):
mock_data[str(self)] = content

with patch.object(Path, 'read_text', mock_read_text), \
patch.object(Path, 'write_text', mock_write_text):
yield mock_data


@pytest.fixture
def mock_environment():
"""Mock environment variables for testing."""
original_env = os.environ.copy()
test_env = {
"HOME": "/tmp/test_home",
"PATH": "/usr/bin:/bin",
"PYTHONPATH": "/tmp/test_python"
}
os.environ.update(test_env)
yield test_env
os.environ.clear()
os.environ.update(original_env)


@pytest.fixture
def capture_output():
"""Capture stdout/stderr for testing print statements."""
import sys
from io import StringIO

old_stdout = sys.stdout
old_stderr = sys.stderr
stdout_capture = StringIO()
stderr_capture = StringIO()

sys.stdout = stdout_capture
sys.stderr = stderr_capture

yield stdout_capture, stderr_capture

sys.stdout = old_stdout
sys.stderr = old_stderr


@pytest.fixture
def mock_network():
"""Mock network requests for testing."""
with patch('urllib.request.urlopen') as mock_urlopen:
mock_response = Mock()
mock_response.read.return_value = b'{"status": "ok"}'
mock_urlopen.return_value.__enter__.return_value = mock_response
yield mock_urlopen


@pytest.fixture(autouse=True)
def cleanup_test_files():
"""Automatically clean up any test files after each test."""
yield
# Clean up any test files that might have been created
test_patterns = [
"*.tmp",
"test_*.log"
]
for pattern in test_patterns:
for file_path in Path.cwd().glob(pattern):
try:
if file_path.is_file():
file_path.unlink()
elif file_path.is_dir():
shutil.rmtree(file_path)
except (OSError, PermissionError):
pass # Ignore cleanup failures


@pytest.fixture
def mock_logger():
"""Mock logger for testing logging functionality."""
logger = Mock()
logger.info = Mock()
logger.error = Mock()
logger.warning = Mock()
logger.debug = Mock()
return logger
1 change: 1 addition & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Integration test package initialization
Loading