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