lsmpp commited on
Commit
adca048
·
verified ·
1 Parent(s): 38612fb

Verify complete English and Chinese example presets are ready to refine

Browse files
Files changed (1) hide show
  1. tests/test_api.py +16 -5
tests/test_api.py CHANGED
@@ -21,15 +21,25 @@ def new_session(client, example="english"):
21
  return response.json()["id"]
22
 
23
 
24
- def test_real_example_and_saved_targets_are_consistent(client):
25
- sid = new_session(client)
26
- targets = client.get(f"/api/sessions/{sid}/targets").json()["regions"]
 
 
 
27
  image = Image.open(io.BytesIO(client.get(f"/api/sessions/{sid}/source.png").content))
28
- assert len(targets) == 4
 
 
29
  for row in targets:
30
  x0, y0, x1, y1 = row["bbox"]
31
  assert 0 <= x0 < x1 <= image.width and 0 <= y0 < y1 <= image.height
32
- assert row["origin"] == "example"
 
 
 
 
 
33
 
34
 
35
  def test_upload_rejects_invalid_data_and_normalizes_valid_images(client):
@@ -40,6 +50,7 @@ def test_upload_rejects_invalid_data_and_normalizes_valid_images(client):
40
  assert response.status_code == 200
41
  session = response.json()
42
  assert (session["width"], session["height"]) == (128, 80)
 
43
  assert client.get(session["image"]).headers["content-type"] == "image/webp"
44
  assert client.get(f"/api/sessions/{session['id']}/source.png").headers["content-type"] == "image/png"
45
  assert client.get(f"/api/sessions/{session['id']}/targets").status_code == 404
 
21
  return response.json()["id"]
22
 
23
 
24
+ @pytest.mark.parametrize(("example", "count"), [("english", 4), ("chinese", 13)])
25
+ def test_examples_load_complete_ready_to_run_presets(client, example, count):
26
+ session = client.post("/api/session", json={"example": example}).json()
27
+ sid = session["id"]
28
+ targets = session["regions"]
29
+ settings = session["settings"]
30
  image = Image.open(io.BytesIO(client.get(f"/api/sessions/{sid}/source.png").content))
31
+ assert len(targets) == count
32
+ assert settings == {"variant": "meanflow", "steps": 4, "seed": 42,
33
+ "guidance": 3.3, "text_threshold": 0.5}
34
  for row in targets:
35
  x0, y0, x1, y1 = row["bbox"]
36
  assert 0 <= x0 < x1 <= image.width and 0 <= y0 < y1 <= image.height
37
+ assert row["origin"] == "example" and row["enabled"] and row["text"].strip()
38
+ # The first response is already a valid inference request; no OCR/setup request is needed.
39
+ request = studio.RefineRequest.model_validate({**settings, "regions": targets})
40
+ assert studio.validate_refine(sid, request)["size"] == image.size
41
+ restored = client.get(f"/api/sessions/{sid}/targets").json()
42
+ assert restored == {"regions": targets, "settings": settings}
43
 
44
 
45
  def test_upload_rejects_invalid_data_and_normalizes_valid_images(client):
 
50
  assert response.status_code == 200
51
  session = response.json()
52
  assert (session["width"], session["height"]) == (128, 80)
53
+ assert not session.get("regions") and "settings" not in session
54
  assert client.get(session["image"]).headers["content-type"] == "image/webp"
55
  assert client.get(f"/api/sessions/{session['id']}/source.png").headers["content-type"] == "image/png"
56
  assert client.get(f"/api/sessions/{session['id']}/targets").status_code == 404