Skip to content

Commit 93d6c02

Browse files
committed
Tests separated for github-actions CI
1 parent 007f4f7 commit 93d6c02

File tree

10 files changed

+108
-25
lines changed

10 files changed

+108
-25
lines changed

.github/workflows/run_tests.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Run tests on CPU with empty model
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout Code
12+
uses: actions/checkout@v3
13+
- name: Set up Python 3.10
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: 3.10.6
17+
- uses: actions/cache@v2
18+
with:
19+
path: ~/.cache/pip
20+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
21+
restore-keys: |
22+
${{ runner.os }}-pip-
23+
- name: Run tests
24+
run: |
25+
export COMMANDLINE_ARGS="--tests basic_features --no-half --disable-opt-split-attention --use-cpu all"
26+
python launch.py

launch.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ def extract_arg(args, name):
1717
return [x for x in args if x != name], name in args
1818

1919

20+
def extract_opt(args, name):
21+
opt = None
22+
is_present = False
23+
if name in args:
24+
is_present = True
25+
idx = args.index(name)
26+
del args[idx]
27+
if idx < len(args) and args[idx][0] != "-":
28+
opt = args[idx]
29+
del args[idx]
30+
return args, is_present, opt
31+
32+
2033
def run(command, desc=None, errdesc=None, custom_env=None):
2134
if desc is not None:
2235
print(desc)
@@ -151,12 +164,11 @@ def prepare_enviroment():
151164
blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9")
152165

153166
sys.argv += shlex.split(commandline_args)
154-
test_argv = [x for x in sys.argv if x != '--tests']
155167

156168
sys.argv, skip_torch_cuda_test = extract_arg(sys.argv, '--skip-torch-cuda-test')
157169
sys.argv, reinstall_xformers = extract_arg(sys.argv, '--reinstall-xformers')
158170
sys.argv, update_check = extract_arg(sys.argv, '--update-check')
159-
sys.argv, run_tests = extract_arg(sys.argv, '--tests')
171+
sys.argv, run_tests, test_dir = extract_opt(sys.argv, '--tests')
160172
xformers = '--xformers' in sys.argv
161173
deepdanbooru = '--deepdanbooru' in sys.argv
162174
ngrok = '--ngrok' in sys.argv
@@ -222,24 +234,24 @@ def prepare_enviroment():
222234
exit(0)
223235

224236
if run_tests:
225-
tests(test_argv)
237+
tests(test_dir)
226238
exit(0)
227239

228240

229-
def tests(argv):
230-
if "--api" not in argv:
231-
argv.append("--api")
232-
if "--ckpt" not in argv:
233-
argv.append("--ckpt")
234-
argv.append("./test/test_files/empty.pt")
241+
def tests(test_dir):
242+
if "--api" not in sys.argv:
243+
sys.argv.append("--api")
244+
if "--ckpt" not in sys.argv:
245+
sys.argv.append("--ckpt")
246+
sys.argv.append("./test/test_files/empty.pt")
235247

236-
print(f"Launching Web UI in another process for testing with arguments: {' '.join(argv[1:])}")
248+
print(f"Launching Web UI in another process for testing with arguments: {' '.join(sys.argv[1:])}")
237249

238250
with open('test/stdout.txt', "w", encoding="utf8") as stdout, open('test/stderr.txt', "w", encoding="utf8") as stderr:
239-
proc = subprocess.Popen([sys.executable, *argv], stdout=stdout, stderr=stderr)
251+
proc = subprocess.Popen([sys.executable, *sys.argv], stdout=stdout, stderr=stderr)
240252

241253
import test.server_poll
242-
test.server_poll.run_tests(proc)
254+
test.server_poll.run_tests(proc, test_dir)
243255

244256
print(f"Stopping Web UI process with id {proc.pid}")
245257
proc.kill()

test/advanced_features/__init__.py

Whitespace-only changes.

test/extras_test.py renamed to test/advanced_features/extras_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def setUp(self):
1111
"codeformer_visibility": 0,
1212
"codeformer_weight": 0,
1313
"upscaling_resize": 2,
14-
"upscaling_resize_w": 512,
15-
"upscaling_resize_h": 512,
14+
"upscaling_resize_w": 128,
15+
"upscaling_resize_h": 128,
1616
"upscaling_crop": True,
1717
"upscaler_1": "None",
1818
"upscaler_2": "None",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import unittest
2+
import requests
3+
4+
5+
class TestTxt2ImgWorking(unittest.TestCase):
6+
def setUp(self):
7+
self.url_txt2img = "http://localhost:7860/sdapi/v1/txt2img"
8+
self.simple_txt2img = {
9+
"enable_hr": False,
10+
"denoising_strength": 0,
11+
"firstphase_width": 0,
12+
"firstphase_height": 0,
13+
"prompt": "example prompt",
14+
"styles": [],
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": 3,
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+
def test_txt2img_with_restore_faces_performed(self):
38+
self.simple_txt2img["restore_faces"] = True
39+
self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200)
40+
41+
42+
class TestTxt2ImgCorrectness(unittest.TestCase):
43+
pass
44+
45+
46+
if __name__ == "__main__":
47+
unittest.main()

test/basic_features/__init__.py

Whitespace-only changes.

test/img2img_test.py renamed to test/basic_features/img2img_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,5 @@ def test_inpainting_masked_performed(self):
5151
self.assertEqual(requests.post(self.url_img2img, json=self.simple_img2img).status_code, 200)
5252

5353

54-
class TestImg2ImgCorrectness(unittest.TestCase):
55-
pass
56-
57-
5854
if __name__ == "__main__":
5955
unittest.main()

test/txt2img_test.py renamed to test/basic_features/txt2img_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,5 @@ def test_txt2img_multiple_batches_performed(self):
6868
self.assertEqual(requests.post(self.url_txt2img, json=self.simple_txt2img).status_code, 200)
6969

7070

71-
class TestTxt2ImgCorrectness(unittest.TestCase):
72-
pass
73-
74-
7571
if __name__ == "__main__":
7672
unittest.main()

test/utils_test.py renamed to test/basic_features/utils_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ def test_artist_categories(self):
6060
self.assertEqual(requests.get(self.url_artist_categories).status_code, 200)
6161

6262
def test_artists(self):
63-
self.assertEqual(requests.get(self.url_artists).status_code, 200)
63+
self.assertEqual(requests.get(self.url_artists).status_code, 200)
64+
65+
66+
if __name__ == "__main__":
67+
unittest.main()

test/server_poll.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import time
44

55

6-
def run_tests(proc):
6+
def run_tests(proc, test_dir):
77
timeout_threshold = 240
88
start_time = time.time()
99
while time.time()-start_time < timeout_threshold:
@@ -14,7 +14,9 @@ def run_tests(proc):
1414
if proc.poll() is not None:
1515
break
1616
if proc.poll() is None:
17-
suite = unittest.TestLoader().discover('', pattern='*_test.py')
17+
if test_dir is None:
18+
test_dir = ""
19+
suite = unittest.TestLoader().discover(test_dir, pattern="*_test.py", top_level_dir="test")
1820
result = unittest.TextTestRunner(verbosity=2).run(suite)
1921
else:
2022
print("Launch unsuccessful")

0 commit comments

Comments
 (0)