2023-03-11 06:42:31 +00:00
|
|
|
import os
|
2022-10-29 18:50:06 +00:00
|
|
|
import unittest
|
2023-01-09 18:01:28 +00:00
|
|
|
import requests
|
|
|
|
from gradio.processing_utils import encode_pil_to_base64
|
|
|
|
from PIL import Image
|
2023-03-11 06:42:31 +00:00
|
|
|
from modules.paths import script_path
|
2022-10-29 18:50:06 +00:00
|
|
|
|
|
|
|
class TestExtrasWorking(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2023-01-09 18:01:28 +00:00
|
|
|
self.url_extras_single = "http://localhost:7860/sdapi/v1/extra-single-image"
|
|
|
|
self.extras_single = {
|
2022-10-29 18:50:06 +00:00
|
|
|
"resize_mode": 0,
|
|
|
|
"show_extras_results": True,
|
|
|
|
"gfpgan_visibility": 0,
|
|
|
|
"codeformer_visibility": 0,
|
|
|
|
"codeformer_weight": 0,
|
|
|
|
"upscaling_resize": 2,
|
2022-11-14 10:39:22 +00:00
|
|
|
"upscaling_resize_w": 128,
|
|
|
|
"upscaling_resize_h": 128,
|
2022-10-29 18:50:06 +00:00
|
|
|
"upscaling_crop": True,
|
|
|
|
"upscaler_1": "None",
|
|
|
|
"upscaler_2": "None",
|
|
|
|
"extras_upscaler_2_visibility": 0,
|
2023-03-11 06:42:31 +00:00
|
|
|
"image": encode_pil_to_base64(Image.open(os.path.join(script_path, r"test/test_files/img2img_basic.png")))
|
2022-10-29 18:50:06 +00:00
|
|
|
}
|
|
|
|
|
2023-01-09 18:01:28 +00:00
|
|
|
def test_simple_upscaling_performed(self):
|
|
|
|
self.extras_single["upscaler_1"] = "Lanczos"
|
|
|
|
self.assertEqual(requests.post(self.url_extras_single, json=self.extras_single).status_code, 200)
|
|
|
|
|
|
|
|
|
|
|
|
class TestPngInfoWorking(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.url_png_info = "http://localhost:7860/sdapi/v1/extra-single-image"
|
|
|
|
self.png_info = {
|
2023-03-11 06:42:31 +00:00
|
|
|
"image": encode_pil_to_base64(Image.open(os.path.join(script_path, r"test/test_files/img2img_basic.png")))
|
2023-01-09 18:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def test_png_info_performed(self):
|
|
|
|
self.assertEqual(requests.post(self.url_png_info, json=self.png_info).status_code, 200)
|
|
|
|
|
|
|
|
|
|
|
|
class TestInterrogateWorking(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.url_interrogate = "http://localhost:7860/sdapi/v1/extra-single-image"
|
|
|
|
self.interrogate = {
|
2023-03-11 06:42:31 +00:00
|
|
|
"image": encode_pil_to_base64(Image.open(os.path.join(script_path, r"test/test_files/img2img_basic.png"))),
|
2023-01-09 18:01:28 +00:00
|
|
|
"model": "clip"
|
|
|
|
}
|
2022-10-30 05:22:44 +00:00
|
|
|
|
2023-01-09 18:01:28 +00:00
|
|
|
def test_interrogate_performed(self):
|
|
|
|
self.assertEqual(requests.post(self.url_interrogate, json=self.interrogate).status_code, 200)
|
2022-10-29 18:50:06 +00:00
|
|
|
|
2022-10-30 05:22:44 +00:00
|
|
|
|
2022-10-29 18:50:06 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|