stable-diffusion-webui
89 строк · 3.1 Кб
1
2import pytest
3import requests
4
5
6@pytest.fixture()
7def url_txt2img(base_url):
8return f"{base_url}/sdapi/v1/txt2img"
9
10
11@pytest.fixture()
12def simple_txt2img_request():
13return {
14"batch_size": 1,
15"cfg_scale": 7,
16"denoising_strength": 0,
17"enable_hr": False,
18"eta": 0,
19"firstphase_height": 0,
20"firstphase_width": 0,
21"height": 64,
22"n_iter": 1,
23"negative_prompt": "",
24"prompt": "example prompt",
25"restore_faces": False,
26"s_churn": 0,
27"s_noise": 1,
28"s_tmax": 0,
29"s_tmin": 0,
30"sampler_index": "Euler a",
31"seed": -1,
32"seed_resize_from_h": -1,
33"seed_resize_from_w": -1,
34"steps": 3,
35"styles": [],
36"subseed": -1,
37"subseed_strength": 0,
38"tiling": False,
39"width": 64,
40}
41
42
43def test_txt2img_simple_performed(url_txt2img, simple_txt2img_request):
44assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
45
46
47def test_txt2img_with_negative_prompt_performed(url_txt2img, simple_txt2img_request):
48simple_txt2img_request["negative_prompt"] = "example negative prompt"
49assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
50
51
52def test_txt2img_with_complex_prompt_performed(url_txt2img, simple_txt2img_request):
53simple_txt2img_request["prompt"] = "((emphasis)), (emphasis1:1.1), [to:1], [from::2], [from:to:0.3], [alt|alt1]"
54assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
55
56
57def test_txt2img_not_square_image_performed(url_txt2img, simple_txt2img_request):
58simple_txt2img_request["height"] = 128
59assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
60
61
62def test_txt2img_with_hrfix_performed(url_txt2img, simple_txt2img_request):
63simple_txt2img_request["enable_hr"] = True
64assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
65
66
67def test_txt2img_with_tiling_performed(url_txt2img, simple_txt2img_request):
68simple_txt2img_request["tiling"] = True
69assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
70
71
72def test_txt2img_with_restore_faces_performed(url_txt2img, simple_txt2img_request):
73simple_txt2img_request["restore_faces"] = True
74assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
75
76
77@pytest.mark.parametrize("sampler", ["PLMS", "DDIM", "UniPC"])
78def test_txt2img_with_vanilla_sampler_performed(url_txt2img, simple_txt2img_request, sampler):
79simple_txt2img_request["sampler_index"] = sampler
80assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
81
82
83def test_txt2img_multiple_batches_performed(url_txt2img, simple_txt2img_request):
84simple_txt2img_request["n_iter"] = 2
85assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
86
87
88def test_txt2img_batch_performed(url_txt2img, simple_txt2img_request):
89simple_txt2img_request["batch_size"] = 2
90assert requests.post(url_txt2img, json=simple_txt2img_request).status_code == 200
91