"""Pytest configuration and fixtures for i18n-guardian tests.""" import tempfile from pathlib import Path import pytest @pytest.fixture def temp_dir(): """Create a temporary directory for tests.""" with tempfile.TemporaryDirectory() as tmpdir: yield Path(tmpdir) @pytest.fixture def sample_python_file(temp_dir): """Create a sample Python file with hardcoded strings.""" content = ''' def greet(name): return "Hello, " + name def farewell(): return "Goodbye, world!" message = "This is a test message" url = "https://example.com" email = "test@example.com" regex = r"^pattern$" ''' file_path = temp_dir / "test.py" file_path.write_text(content, encoding="utf-8") return file_path @pytest.fixture def sample_js_file(temp_dir): """Create a sample JavaScript file with hardcoded strings.""" content = ''' function greet(name) { return "Hello, " + name; } function farewell() { return "Goodbye, world!"; } const message = "This is a test message"; const url = "https://example.com"; const email = "test@example.com"; ''' file_path = temp_dir / "test.js" file_path.write_text(content, encoding="utf-8") return file_path @pytest.fixture def sample_tsx_file(temp_dir): """Create a sample TypeScript React file.""" content = ''' import React from 'react'; export function Welcome() { return (

Welcome to our app

This is a translated message

); } ''' file_path = temp_dir / "Welcome.tsx" file_path.write_text(content, encoding="utf-8") return file_path @pytest.fixture def sample_package_json(temp_dir): """Create a sample package.json with react-intl.""" content = ''' { "name": "test-app", "version": "1.0.0", "dependencies": { "react-intl": "^5.0.0" } } ''' file_path = temp_dir / "package.json" file_path.write_text(content, encoding="utf-8") return file_path @pytest.fixture def sample_locales(temp_dir): """Create sample locale files.""" locales_dir = temp_dir / "locales" locales_dir.mkdir() en_json = locales_dir / "en.json" en_json.write_text('{"greeting": "Hello"}', encoding="utf-8") de_json = locales_dir / "de.json" de_json.write_text('{"greeting": "Hallo"}', encoding="utf-8") return locales_dir @pytest.fixture def sample_config_file(temp_dir): """Create a sample configuration file.""" content = ''' i18n_library: react-intl min_string_length: 3 key_style: snake_case exclude_patterns: - "**/node_modules/**" - "**/.git/**" i18n_functions: - formatMessage - t ''' file_path = temp_dir / ".i18n-guardian.yaml" file_path.write_text(content, encoding="utf-8") return file_path