|
1 | 1 | import unittest
|
2 | 2 | import requests
|
3 |
| -import time |
4 |
| - |
5 |
| -url_txt2img = "http://localhost:7860/sdapi/v1/txt2img" |
6 |
| -simple_txt2img = { |
7 |
| - "enable_hr": False, |
8 |
| - "denoising_strength": 0, |
9 |
| - "firstphase_width": 0, |
10 |
| - "firstphase_height": 0, |
11 |
| - "prompt": "example prompt", |
12 |
| - "styles": [ |
13 |
| - "" |
14 |
| - ], |
15 |
| - "seed": -1, |
16 |
| - "subseed": -1, |
17 |
| - "subseed_strength": 0, |
18 |
| - "seed_resize_from_h": -1, |
19 |
| - "seed_resize_from_w": -1, |
20 |
| - "batch_size": 1, |
21 |
| - "n_iter": 1, |
22 |
| - "steps": 5, |
23 |
| - "cfg_scale": 7, |
24 |
| - "width": 64, |
25 |
| - "height": 64, |
26 |
| - "restore_faces": False, |
27 |
| - "tiling": False, |
28 |
| - "negative_prompt": "", |
29 |
| - "eta": 0, |
30 |
| - "s_churn": 0, |
31 |
| - "s_tmax": 0, |
32 |
| - "s_tmin": 0, |
33 |
| - "s_noise": 1, |
34 |
| - "sampler_index": "Euler a" |
35 |
| -} |
36 | 3 |
|
37 | 4 | class TestTxt2ImgWorking(unittest.TestCase):
|
| 5 | + def setUp(self): |
| 6 | + self.url_txt2img = "http://localhost:7860/sdapi/v1/txt2img" |
| 7 | + self.simple_txt2img = { |
| 8 | + "enable_hr": False, |
| 9 | + "denoising_strength": 0, |
| 10 | + "firstphase_width": 0, |
| 11 | + "firstphase_height": 0, |
| 12 | + "prompt": "example prompt", |
| 13 | + "styles": [ |
| 14 | + "" |
| 15 | + ], |
| 16 | + "seed": -1, |
| 17 | + "subseed": -1, |
| 18 | + "subseed_strength": 0, |
| 19 | + "seed_resize_from_h": -1, |
| 20 | + "seed_resize_from_w": -1, |
| 21 | + "batch_size": 1, |
| 22 | + "n_iter": 1, |
| 23 | + "steps": 3, |
| 24 | + "cfg_scale": 7, |
| 25 | + "width": 64, |
| 26 | + "height": 64, |
| 27 | + "restore_faces": False, |
| 28 | + "tiling": False, |
| 29 | + "negative_prompt": "", |
| 30 | + "eta": 0, |
| 31 | + "s_churn": 0, |
| 32 | + "s_tmax": 0, |
| 33 | + "s_tmin": 0, |
| 34 | + "s_noise": 1, |
| 35 | + "sampler_index": "Euler a" |
| 36 | + } |
38 | 37 | def test_txt2img_simple_performed(self):
|
39 |
| - self.assertEqual(requests.post(url_txt2img, json=simple_txt2img).status_code, 200) |
| 38 | + self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200) |
40 | 39 |
|
41 | 40 | def test_txt2img_with_negative_prompt_performed(self):
|
42 |
| - params = simple_txt2img.copy() |
43 |
| - params["negative_prompt"] = "example negative prompt" |
44 |
| - self.assertEqual(requests.post(url_txt2img, json=params).status_code, 200) |
| 41 | + self.simple_txt2img["negative_prompt"] = "example negative prompt" |
| 42 | + self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200) |
45 | 43 |
|
46 | 44 | def test_txt2img_not_square_image_performed(self):
|
47 |
| - params = simple_txt2img.copy() |
48 |
| - params["height"] = 128 |
49 |
| - self.assertEqual(requests.post(url_txt2img, json=params).status_code, 200) |
| 45 | + self.simple_txt2img["height"] = 128 |
| 46 | + self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200) |
50 | 47 |
|
51 | 48 | def test_txt2img_with_hrfix_performed(self):
|
52 |
| - params = simple_txt2img.copy() |
53 |
| - params["enable_hr"] = True |
54 |
| - self.assertEqual(requests.post(url_txt2img, json=params).status_code, 200) |
| 49 | + self.simple_txt2img["enable_hr"] = True |
| 50 | + self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200) |
55 | 51 |
|
56 | 52 | def test_txt2img_with_restore_faces_performed(self):
|
57 |
| - params = simple_txt2img.copy() |
58 |
| - params["restore_faces"] = True |
59 |
| - self.assertEqual(requests.post(url_txt2img, json=params).status_code, 200) |
| 53 | + self.simple_txt2img["restore_faces"] = True |
| 54 | + self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200) |
60 | 55 |
|
61 | 56 | def test_txt2img_with_tiling_faces_performed(self):
|
62 |
| - params = simple_txt2img.copy() |
63 |
| - params["tiling"] = True |
64 |
| - self.assertEqual(requests.post(url_txt2img, json=params).status_code, 200) |
| 57 | + self.simple_txt2img["tiling"] = True |
| 58 | + self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200) |
65 | 59 |
|
66 | 60 | def test_txt2img_with_vanilla_sampler_performed(self):
|
67 |
| - params = simple_txt2img.copy() |
68 |
| - params["sampler_index"] = "PLMS" |
69 |
| - self.assertEqual(requests.post(url_txt2img, json=params).status_code, 200) |
| 61 | + self.simple_txt2img["sampler_index"] = "PLMS" |
| 62 | + self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200) |
70 | 63 |
|
71 | 64 | def test_txt2img_multiple_batches_performed(self):
|
72 |
| - params = simple_txt2img.copy() |
73 |
| - params["n_iter"] = 2 |
74 |
| - self.assertEqual(requests.post(url_txt2img, json=params).status_code, 200) |
| 65 | + self.simple_txt2img["n_iter"] = 2 |
| 66 | + self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200) |
75 | 67 |
|
76 | 68 | class TestTxt2ImgCorrectness(unittest.TestCase):
|
77 | 69 | pass
|
|
0 commit comments