Spaces:
Runtime error
Runtime error
Download test_api.py from abdoolamunir/very-basic-sentiment-analysis: direct link, hf CLI and curl.
- Browser
- Download file 757 Bytes
-
https://huggingface.co/spaces/abdoolamunir/very-basic-sentiment-analysis/resolve/main/test_api.py
- Command line
-
hf download hf://spaces/abdoolamunir/very-basic-sentiment-analysis/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/abdoolamunir/very-basic-sentiment-analysis/resolve/main/test_api.py
757 Bytes
| from fastapi.testclient import TestClient | |
| from main import app | |
| client = TestClient(app) | |
| def test_positive_sentiment(): | |
| response = client.post("/analyze", json={"text": "I love this new product, it's amazing!"}) | |
| assert response.status_code == 200 | |
| assert "positive" in response.json()['result'][0]['label'].lower() | |
| def test_negative_sentiment(): | |
| response = client.post("/analyze", json={"text": "I hate this new product, it's terrible!"}) | |
| assert response.status_code == 200 | |
| assert "negative" in response.json()['result'][0]['label'].lower() | |
| def test_empty_text(): | |
| response = client.post("/analyze", json={"text": " "}) | |
| assert response.status_code == 400 | |
| assert "must not be empty" in response.json()['detail'].lower() | |