Skip to content

Commit e7ea0b3

Browse files
committed
Add lightweight test mode tests for IntelligentContentAnalyzer and ModelRegistry
1 parent 35f8b7d commit e7ea0b3

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

.github/workflows/tests.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@ jobs:
1616
- uses: actions/setup-python@v5
1717
with:
1818
python-version: '3.11'
19+
- name: Cache pip
20+
uses: actions/cache@v4
21+
with:
22+
path: ~/.cache/pip
23+
key: ${{ runner.os }}-pip-fast-${{ hashFiles('requirements-test.txt') }}
24+
restore-keys: |
25+
${{ runner.os }}-pip-fast-
1926
- name: Install minimal deps
2027
run: |
2128
python -m pip install --upgrade pip
2229
pip install -r requirements-test.txt
23-
- name: Run lightweight tests
30+
- name: Run lightweight tests with coverage
2431
env:
2532
LIGHT_TEST_MODE: '1'
26-
run: pytest -q
33+
run: pytest -q --cov=src --cov-report=term-missing:skip-covered --maxfail=1 -m "not heavy"
2734

2835
full-tests:
2936
if: github.event_name == 'schedule'
@@ -33,11 +40,18 @@ jobs:
3340
- uses: actions/setup-python@v5
3441
with:
3542
python-version: '3.11'
43+
- name: Cache pip
44+
uses: actions/cache@v4
45+
with:
46+
path: ~/.cache/pip
47+
key: ${{ runner.os }}-pip-full-${{ hashFiles('requirements.txt') }}
48+
restore-keys: |
49+
${{ runner.os }}-pip-full-
3650
- name: Install full deps
3751
run: |
3852
python -m pip install --upgrade pip
3953
pip install -r requirements.txt
4054
- name: Run integration tests
4155
env:
4256
LIGHT_TEST_MODE: '0'
43-
run: pytest -q || true # tolerate failures initially
57+
run: pytest -q -m "integration or heavy" || true # tolerate failures initially

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Minimal dependencies for running lightweight tests
22
pytest>=8.0.0
33
pytest-asyncio>=0.21.0
4+
pytest-cov>=5.0.0
45
PyYAML>=6.0.0
56
streamlit>=1.32.0
67
opencv-python-headless>=4.8.0

tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,25 @@
66
"""
77
import os
88
import pytest
9+
import pytest
910

1011
def pytest_configure(): # pragma: no cover
1112
os.environ.setdefault('LIGHT_TEST_MODE', '1')
13+
# Register custom markers to avoid warnings on CI output
14+
for marker in [
15+
'heavy: marks tests that load large ML models (deselected in fast CI)',
16+
'integration: multi-component integration tests',
17+
'slow: longer-running tests',
18+
]:
19+
try: # pytest <8 compatibility
20+
pytest.config.addinivalue_line('markers', marker) # type: ignore[attr-defined]
21+
except Exception: # pragma: no cover
22+
pass
23+
24+
25+
def pytest_runtest_setup(item): # pragma: no cover
26+
if os.getenv('LIGHT_TEST_MODE') == '1' and 'heavy' in item.keywords:
27+
pytest.skip('Skipping heavy test in LIGHT_TEST_MODE=1')
1228
# Register custom markers to avoid warnings
1329
for marker in [
1430
'heavy: marks tests that load large ML models (deselected in fast CI)',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from src.ai_models.intelligent_content_analyzer import IntelligentContentAnalyzer
2+
3+
4+
def test_content_analyzer_light_mode(monkeypatch):
5+
monkeypatch.setenv('LIGHT_TEST_MODE', '1')
6+
analyzer = IntelligentContentAnalyzer({'ai_models': {'cache_dir': './cache'}})
7+
assert analyzer.content_classifier is None
8+
assert analyzer.object_detector is None
9+
assert analyzer.text_analyzer is None
10+
11+
12+
def test_content_analyzer_basic_analysis(monkeypatch, tmp_path):
13+
monkeypatch.setenv('LIGHT_TEST_MODE', '1')
14+
analyzer = IntelligentContentAnalyzer({'ai_models': {'cache_dir': './cache'}})
15+
dummy_video = tmp_path / 'dummy.mp4'
16+
dummy_video.write_bytes(b'')
17+
result = analyzer.analyze_content(str(dummy_video))
18+
assert 'content_type' in result
19+
assert 'editing_recommendations' in result

tests/test_model_registry.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from src.ai_models import ModelRegistry
4+
5+
6+
def test_registry_light_mode(monkeypatch):
7+
monkeypatch.setenv('LIGHT_TEST_MODE', '1')
8+
pipe = ModelRegistry.get_pipeline('text-classification', 'distilbert-base-uncased')
9+
assert pipe is None
10+
11+
12+
@pytest.mark.heavy
13+
def test_registry_attempt_load(monkeypatch):
14+
monkeypatch.setenv('LIGHT_TEST_MODE', '0')
15+
pipe = ModelRegistry.get_pipeline('text-classification', 'distilbert-base-uncased')
16+
assert pipe is None or hasattr(pipe, '__call__')

0 commit comments

Comments
 (0)