junaid-simamdigital commited on
Commit
2d0ecef
·
verified ·
1 Parent(s): bceef84

Test hosted smoke-test orchestration

Browse files
Files changed (1) hide show
  1. tests/test_hosted_smoke_test.py +36 -0
tests/test_hosted_smoke_test.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ from unittest.mock import patch
3
+
4
+ from hosted_smoke_test import run
5
+
6
+
7
+ def test_hosted_smoke_orchestrates_upload_event_and_output_contract(tmp_path):
8
+ image = tmp_path / "input.png"
9
+ image.write_bytes(b"test image")
10
+ result = [None] * 11 + ["manifest.json", "### analysis single_view_baseline", "Processed 1 view(s) on CUDA"]
11
+ with patch("hosted_smoke_test.upload_image", return_value="/tmp/gradio/input.png") as upload:
12
+ with patch("hosted_smoke_test.request_json", return_value={"event_id": "event-1"}) as request:
13
+ with patch("hosted_smoke_test.poll_event", return_value=result) as poll:
14
+ summary = run("https://example.test/", image, timeout=10)
15
+ upload.assert_called_once_with("https://example.test", image)
16
+ request.assert_called_once_with(
17
+ "https://example.test/gradio_api/call/generate",
18
+ {"data": [{"path": "/tmp/gradio/input.png"}, [], "Depth Anything V2 (stable baseline)", "hosted smoke test", True]},
19
+ )
20
+ poll.assert_called_once_with("https://example.test", "generate", "event-1", 10)
21
+ assert summary["output_count"] == 14
22
+ assert summary["manifest"] == "manifest.json"
23
+
24
+
25
+ def test_hosted_smoke_rejects_incomplete_output_contract(tmp_path):
26
+ image = tmp_path / "input.png"
27
+ image.write_bytes(b"test image")
28
+ with patch("hosted_smoke_test.upload_image", return_value="/tmp/gradio/input.png"):
29
+ with patch("hosted_smoke_test.request_json", return_value={"event_id": "event-1"}):
30
+ with patch("hosted_smoke_test.poll_event", return_value=[None] * 13):
31
+ try:
32
+ run("https://example.test", image, timeout=10)
33
+ except RuntimeError as exc:
34
+ assert "Expected 14 generated outputs" in str(exc)
35
+ else:
36
+ raise AssertionError("incomplete hosted output should fail")