chunker and ui
This commit is contained in:
76
tests/chunker/conftest.py
Normal file
76
tests/chunker/conftest.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""
|
||||
Shared fixtures for chunker tests.
|
||||
|
||||
Demonstrates: TDD and unit testing best practices (Interview Topic 8) — fixtures, temp files.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
|
||||
from core.chunker.models import Chunk, ChunkResult
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_file():
|
||||
"""Create a temporary file with known content, cleaned up after test."""
|
||||
files = []
|
||||
|
||||
def _create(content: bytes = b"x" * 4096):
|
||||
f = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
|
||||
f.write(content)
|
||||
f.close()
|
||||
files.append(f.name)
|
||||
return f.name
|
||||
|
||||
yield _create
|
||||
|
||||
for path in files:
|
||||
if os.path.exists(path):
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_chunk(temp_file):
|
||||
"""Create a sample time-based Chunk with valid time range."""
|
||||
path = temp_file(b"x" * 1024)
|
||||
return Chunk(
|
||||
sequence=0,
|
||||
start_time=0.0,
|
||||
end_time=10.0,
|
||||
source_path=path,
|
||||
duration=10.0,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_chunk(temp_file):
|
||||
"""Factory fixture for creating time-based chunks with specific sequence numbers."""
|
||||
path = temp_file(b"x" * 1024)
|
||||
|
||||
def _make(sequence: int, duration: float = 10.0) -> Chunk:
|
||||
start = sequence * duration
|
||||
return Chunk(
|
||||
sequence=sequence,
|
||||
start_time=start,
|
||||
end_time=start + duration,
|
||||
source_path=path,
|
||||
duration=duration,
|
||||
)
|
||||
|
||||
return _make
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_result():
|
||||
"""Factory fixture for creating ChunkResults."""
|
||||
|
||||
def _make(sequence: int, success: bool = True, processing_time: float = 0.01) -> ChunkResult:
|
||||
return ChunkResult(
|
||||
sequence=sequence,
|
||||
success=success,
|
||||
processing_time=processing_time,
|
||||
)
|
||||
|
||||
return _make
|
||||
Reference in New Issue
Block a user