"""Pytest configuration and fixtures for regex humanizer tests.""" import pytest from regex_humanizer.parser import RegexParser, parse_regex from regex_humanizer.translator import RegexTranslator, translate_regex from regex_humanizer.test_generator import TestCaseGenerator, generate_test_cases @pytest.fixture def parser(): """Provide a RegexParser instance.""" return RegexParser @pytest.fixture def translator(): """Provide a RegexTranslator instance.""" return RegexTranslator("pcre") @pytest.fixture def test_generator(): """Provide a TestCaseGenerator instance.""" return TestCaseGenerator("pcre") @pytest.fixture def sample_patterns(): """Provide sample regex patterns for testing.""" return { "simple_literal": "hello", "character_class": "[a-z]", "quantifier_plus": "a+", "quantifier_star": "b*", "quantifier_question": "c?", "digit": "\\d{3}", "word": "\\w+", "email": "[a-z]+@[a-z]+\\.[a-z]+", "phone": "\\d{3}-\\d{4}", "ip_address": "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}", "url": "https?://[^\\s]+", "date": "\\d{4}-\\d{2}-\\d{2}", "group": "(hello)\\s+(world)", "named_group": "(?P[a-z]+)", "lookahead": "\\d+(?=px)", "negative_lookahead": "\\d+(?!px)", "lookbehind": "(?<=\\$)\\d+", "non_capturing": "(?:hello)\\s+(?:world)", "alternation": "cat|dog", "anchor_start": "^start", "anchor_end": "end$", "word_boundary": "\\bword\\b", "complex": "^(?:http|https)://[\\w.-]+\\.(?:com|org|net)$", } @pytest.fixture def flavor_manager(): """Provide the flavor manager.""" from regex_humanizer.flavors import get_flavor_manager return get_flavor_manager() SAMPLE_OPENAPI_SPEC = { "openapi": "3.0.0", "info": { "title": "Test Pet Store API", "version": "1.0.0", "description": "A sample API for testing purposes" }, "servers": [ {"url": "https://api.example.com/v1"} ], "paths": { "/pets": { "get": { "summary": "List all pets", "description": "Returns a list of pets", "operationId": "listPets", "parameters": [ { "name": "limit", "in": "query", "description": "Maximum number of pets to return", "required": False, "schema": {"type": "integer", "default": 10} }, { "name": "status", "in": "query", "description": "Filter by pet status", "required": False, "schema": {"type": "string", "enum": ["available", "pending", "sold"]} } ], "responses": { "200": { "description": "A list of pets", "content": { "application/json": { "schema": { "type": "array", "items": {"$ref": "#/components/schemas/Pet"} } } } } } }, "post": { "summary": "Create a new pet", "description": "Creates a new pet in the store", "operationId": "createPet", "requestBody": { "required": True, "content": { "application/json": { "schema": {"$ref": "#/components/schemas/Pet"} } } }, "responses": { "201": { "description": "Pet created successfully", "content": { "application/json": { "schema": {"$ref": "#/components/schemas/Pet"} } } } } } }, "/pets/{petId}": { "get": { "summary": "Get a pet by ID", "description": "Returns a single pet", "operationId": "getPetById", "parameters": [ { "name": "petId", "in": "path", "description": "ID of the pet to retrieve", "required": True, "schema": {"type": "string"} } ], "responses": { "200": { "description": "Successful operation", "content": { "application/json": { "schema": {"$ref": "#/components/schemas/Pet"} } } }, "404": { "description": "Pet not found" } } }, "delete": { "summary": "Delete a pet", "description": "Deletes a pet from the store", "operationId": "deletePet", "parameters": [ { "name": "petId", "in": "path", "description": "ID of the pet to delete", "required": True, "schema": {"type": "string"} } ], "responses": { "204": { "description": "Pet deleted successfully" } } } } }, "components": { "schemas": { "Pet": { "type": "object", "required": ["name", "status"], "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string", "example": "Fluffy" }, "status": { "type": "string", "enum": ["available", "pending", "sold"], "description": "Pet status in the store" }, "categoryId": { "type": "integer", "format": "int64" }, "categoryName": { "type": "string" } } } }, "securitySchemes": { "ApiKeyAuth": { "type": "apiKey", "in": "header", "name": "X-API-Key" }, "BearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT" } } } } @pytest.fixture def sample_openapi_spec(): """Provide a sample OpenAPI specification for testing.""" return SAMPLE_OPENAPI_SPEC @pytest.fixture def temp_spec_file(sample_openapi_spec, tmp_path): """Create a temporary YAML file with a sample OpenAPI spec.""" import yaml file_path = tmp_path / "test_spec.yaml" with open(file_path, 'w') as f: yaml.dump(sample_openapi_spec, f) return file_path @pytest.fixture def temp_json_spec_file(sample_openapi_spec, tmp_path): """Create a temporary JSON file with a sample OpenAPI spec.""" import json file_path = tmp_path / "test_spec.json" with open(file_path, 'w') as f: json.dump(sample_openapi_spec, f, indent=2) return file_path