Spaces:
Running
Running
File size: 1,962 Bytes
d66ab65 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
"""
pytest configuration file
"""
import pytest
import os
import tempfile
from unittest.mock import Mock, patch
from flask import Flask
# Add the parent directory to Python path so we can import the app
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from app import create_app
from config import TestingConfig
@pytest.fixture
def app():
"""Create a test Flask application."""
app = create_app(TestingConfig())
# Create a temporary directory for file uploads during testing
with tempfile.TemporaryDirectory() as temp_dir:
app.config['UPLOAD_FOLDER'] = temp_dir
app.config['TESTING'] = True
yield app
@pytest.fixture
def client(app):
"""Create a test client."""
return app.test_client()
@pytest.fixture
def mock_tokenizer():
"""Create a mock tokenizer for testing."""
tokenizer = Mock()
tokenizer.tokenize.return_value = ['Hello', 'world', '!']
tokenizer.vocab_size = 50257
tokenizer.model_max_length = 1024
tokenizer.__class__.__name__ = 'MockTokenizer'
# Mock special tokens
tokenizer.pad_token = '<pad>'
tokenizer.eos_token = '</s>'
tokenizer.unk_token = '<unk>'
tokenizer.bos_token = '<s>'
return tokenizer
@pytest.fixture
def sample_text():
"""Sample text for testing."""
return "Hello world! This is a test."
@pytest.fixture
def sample_tokens():
"""Sample tokens for testing."""
return ['Hello', ' world', '!', ' This', ' is', ' a', ' test', '.']
@pytest.fixture
def temp_file():
"""Create a temporary file for testing."""
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
f.write("Hello world! This is a test file.")
temp_path = f.name
yield temp_path
# Cleanup
if os.path.exists(temp_path):
os.unlink(temp_path) |