|
| 1 | +import unittest |
| 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 | + |
| 37 | +class TestTxt2ImgWorking(unittest.TestCase): |
| 38 | + def test_txt2img_simple_performed(self): |
| 39 | + self.assertEqual(requests.post(url_txt2img, json=simple_txt2img).status_code, 200) |
| 40 | + |
| 41 | + 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) |
| 45 | + |
| 46 | + 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) |
| 50 | + |
| 51 | + 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) |
| 55 | + |
| 56 | + 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) |
| 60 | + |
| 61 | + 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) |
| 65 | + |
| 66 | + 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) |
| 70 | + |
| 71 | + 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) |
| 75 | + |
| 76 | +class TestTxt2ImgCorrectness(unittest.TestCase): |
| 77 | + pass |
| 78 | + |
| 79 | +if __name__ == "__main__": |
| 80 | + unittest.main() |
0 commit comments