Belle II Software development
test_server_detect_no_results.py
1#!/usr/bin/env python3
2
3
10
11import sys
12import os
13import tempfile
14import validationpath
15import validationserver
16
17
18def main():
19 """
20 Test if the validationserver is able to detect if there is no
21 results folder available
22 """
23
24 # will create a temporary folder and delete it once this block is left
25 with tempfile.TemporaryDirectory() as tmpdir:
26 print(f"Created temporary test folder {tmpdir}")
27 os.chdir(str(tmpdir))
28
29 # run validation server
30 fail = False
31 try:
32 validationserver.run_server(dry_run=True)
33 fail = True
34 except SystemExit:
35 # we expect it to exit
36 pass
37
38 if fail:
39 sys.exit("did not exit, even though there is no results folder")
40
41 # will create a temporary folder and delete it once this block is left
42 with tempfile.TemporaryDirectory() as tmpdir:
43 print(f"Created temporary test folder {tmpdir}")
44 os.chdir(str(tmpdir))
45
46 # create validation results folders, but still no folders inside
47 os.mkdir(validationpath.get_results_folder(os.getcwd()))
48
49 # run validation server
50 fail = False
51 try:
52 validationserver.run_server(dry_run=True)
53 fail = True
54 except SystemExit:
55 # we expect it to exit
56 pass
57
58 if fail:
59 sys.exit(
60 "did not exit, even though there is no folders in "
61 "results folder"
62 )
63
64 # will create a temporary folder and delete it once this block is left
65 with tempfile.TemporaryDirectory() as tmpdir:
66 # should work when the folders are present
67 print(f"Created temporary test folder {tmpdir}")
68 os.chdir(str(tmpdir))
69
70 # create validation results folders, but still no folders inside
71 os.mkdir(validationpath.get_results_folder(os.getcwd()))
72 os.mkdir(validationpath.get_results_tag_folder(os.getcwd(), "some"))
73
74 # run validation server
75 # should not raise any exit exceptions
76 validationserver.run_server(dry_run=True)
77
78
79if __name__ == "__main__":
80 main()
Definition: main.py:1
def get_results_folder(output_base_dir)
def get_results_tag_folder(output_base_dir, tag)
def run_server(ip="127.0.0.1", port=8000, parse_command_line=False, open_site=False, dry_run=False)