"""Pytest configuration and fixtures.""" import pytest import tempfile import os from pathlib import Path @pytest.fixture def sample_python_file(): """Sample Python file content.""" return ''' """This is a sample module for testing.""" def add(a: int, b: int) -> int: """Add two numbers together. Args: a: First number b: Second number Returns: The sum of a and b Raises: ValueError: If either a or b is negative """ if a < 0 or b < 0: raise ValueError("Numbers must be positive") return a + b class Calculator: """A simple calculator class. Attributes: memory: Current stored value in memory """ def __init__(self, initial: int = 0): """Initialize calculator with optional starting value. Args: initial: Starting value for the calculator """ self.memory = initial def multiply(self, x: int, y: int) -> int: """Multiply two numbers. Args: x: First number y: Second number Returns: The product of x and y """ return x * y ''' @pytest.fixture def sample_typescript_file(): """Sample TypeScript file content.""" return ''' /** * This is a sample TypeScript module for testing. */ export function add(a: number, b: number): number { /** * Add two numbers together. * @param a - First number * @param b - Second number * @returns The sum of a and b */ return a + b; } export interface User { id: number; name: string; email?: string; } export class Calculator { private memory: number; constructor(initial: number = 0) { /** * Initialize calculator with optional starting value. * @param initial - Starting value */ this.memory = initial; } /** * Multiply two numbers. * @param x - First number * @param y - Second number * @returns The product of x and y */ public multiply(x: number, y: number): number { return x * y; } } ''' @pytest.fixture def sample_go_file(): """Sample Go file content.""" return ''' // Package calculator provides basic arithmetic operations. // // This package contains functions for addition, subtraction, // multiplication, and division. package calculator import "errors" // Add two numbers together. // // Parameters: // a: First number // b: Second number // // Returns the sum of a and b func Add(a, b int) int { return a + b } // Calculator performs arithmetic operations. type Calculator struct { memory int } // NewCalculator creates a new Calculator instance. // // Parameters: // initial: Starting value for the calculator // // Returns a new Calculator func NewCalculator(initial int) *Calculator { return &Calculator{memory: initial} } // Multiply two numbers. // // Parameters: // x: First number // y: Second number // // Returns the product of x and y func (c *Calculator) Multiply(x, y int) int { return x * y } ''' @pytest.fixture def temp_python_file(sample_python_file): """Create a temporary Python file.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f: f.write(sample_python_file) f.flush() yield f.name os.unlink(f.name) @pytest.fixture def temp_typescript_file(sample_typescript_file): """Create a temporary TypeScript file.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".ts", delete=False) as f: f.write(sample_typescript_file) f.flush() yield f.name os.unlink(f.name) @pytest.fixture def temp_go_file(sample_go_file): """Create a temporary Go file.""" with tempfile.NamedTemporaryFile(mode="w", suffix=".go", delete=False) as f: f.write(sample_go_file) f.flush() yield f.name os.unlink(f.name) @pytest.fixture def temp_directory(): """Create a temporary directory with sample files.""" with tempfile.TemporaryDirectory() as tmpdir: yield tmpdir