Belle II Software  release-08-01-10
test_folder_creation.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import os
12 import shutil
13 import tempfile
14 import validation
15 import validationpath
16 import validationserver
17 
18 from validationtestutil import check_execute, check_path_exists
19 
20 
21 def main():
22  """
23  Runs two test validations, starts the web server and queries data
24  """
25 
26  rev_to_gen = "test_folder_creation"
27  all_tags = ["reference", rev_to_gen]
28 
29  # will create a temporary folder and delete it once this block is left
30  with tempfile.TemporaryDirectory() as tmpdir:
31  print(f"Created temporary test folder {tmpdir}")
32 
33  expect_html_plots_comparison_json = validationpath.get_html_plots_tag_comparison_json(
34  str(tmpdir), all_tags
35  )
36  expect_html_plots_comparison_folder = validationpath.get_html_plots_tag_comparison_folder(
37  str(tmpdir), all_tags
38  )
39 
40  # switch to this folder
41  os.chdir(str(tmpdir))
42 
43  validation.execute(tag=rev_to_gen, is_test=True)
44 
45  # todo: check if results folder has been created and is filled
46  path_to_check = [
47  validationpath.get_results_tag_folder(str(tmpdir), rev_to_gen),
49  str(tmpdir), rev_to_gen
50  ),
51  os.path.join(
52  validationpath.get_results_tag_folder(str(tmpdir), rev_to_gen),
53  "validation-test",
54  "validationTestPlots.py.log",
55  ),
56  os.path.join(
57  validationpath.get_results_tag_folder(str(tmpdir), rev_to_gen),
58  "validation-test",
59  "validationTestPlots.root",
60  ),
61  expect_html_plots_comparison_json,
62  expect_html_plots_comparison_folder,
63  ]
64 
65  check_path_exists(path_to_check)
66 
67  # run validation server
68  # must setup all content in the html folder required
69  validationserver.run_server(dry_run=True)
70 
71  # check if all files have been copied and the symbolic links properly
72  # set
73  path_to_check = [
74  os.path.join(str(tmpdir), validationpath.folder_name_html),
75  os.path.join(
76  str(tmpdir),
77  validationpath.folder_name_html,
78  validationpath.folder_name_plots,
79  ),
80  ]
81  check_path_exists(path_to_check)
82 
83  # remove generated plots and use create_validation_plots script to
84  # regenerate
85  shutil.rmtree(expect_html_plots_comparison_folder)
86 
87  # recreate
88  # switch to this folder
89  os.chdir(str(tmpdir))
90  check_execute("create_validation_plots.py")
91  check_path_exists(path_to_check)
92 
93 
94 if __name__ == "__main__":
95  main()
Definition: main.py:1
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91
def execute(tag=None, is_test=None)
Definition: validation.py:1382
def get_results_tag_folder(output_base_dir, tag)
def get_html_plots_tag_comparison_json(output_base_dir, tags)
def get_html_plots_tag_comparison_folder(output_base_dir, tags)
def get_results_tag_revision_file(output_base_dir, tag)
def run_server(ip="127.0.0.1", port=8000, parse_command_line=False, open_site=False, dry_run=False)