/
himozaa
/
SE_FastAPI_Example
Обзор
Документация
Войти
/
himozaa
/
SE_FastAPI_Example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
tests/test_app.py
54 строки
1 KB
Shankly8642
style(ci): add flake8 configuration and fix lint issues
12 май 2026, 16:09
12 май 2026, 16:09
5d32ea7
Код
Авторство
О чём код?
import sys import types from pathlib import Path import pytest from fastapi import HTTPException from fastapi.testclient import TestClient sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) fake_transformers = types.ModuleType("transformers") def fake_pipeline(model_name): return lambda text: [{"label": "MOCK", "text": text}] fake_transformers.pipeline = fake_pipeline sys.modules["transformers"] = fake_transformers import main # noqa: E402 client = TestClient(main.app) def test_root(): response = client.get("/") assert response.status_code == 200 assert response.json() == { "message": "FastAPI service started!" } def test_predict_success(): response = client.post( "/predict/", json={"text": "hello"} ) assert response.status_code == 200 assert response.json() == [ {"label": "MOCK", "text": "hello"} ] def test_validate_text_empty(): with pytest.raises(HTTPException) as exc: main.validate_text(" ") assert exc.value.status_code == 400 assert exc.value.detail == "Text must not be empty"