Belle II Software  release-05-01-25
test_folder_creation.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import os
5 import shutil
6 import tempfile
7 import validation
8 import validationpath
9 import validationserver
10 
11 from validationtestutil import check_execute, check_path_exists
12 
13 
14 def main():
15  """
16  Runs two test validations, starts the web server and queries data
17  """
18 
19  rev_to_gen = "test_folder_creation"
20  all_tags = ["reference", rev_to_gen]
21 
22  # will create a temporary folder and delete it once this block is left
23  with tempfile.TemporaryDirectory() as tmpdir:
24  print("Created temporary test folder {}".format(tmpdir))
25 
26  expect_html_plots_comparison_json = \
28  all_tags)
29  expect_html_plots_comparison_folder = \
31  all_tags)
32 
33  # switch to this folder
34  os.chdir(str(tmpdir))
35 
36  validation.execute(tag=rev_to_gen, is_test=True)
37 
38  # todo: check if results folder has been created and is filled
39  path_to_check = [
40  validationpath.get_results_tag_folder(str(tmpdir), rev_to_gen),
42  rev_to_gen),
43  os.path.join(
44  validationpath.get_results_tag_folder(str(tmpdir), rev_to_gen),
45  "validation-test",
46  "validationTestPlots.py.log"
47  ),
48  os.path.join(
49  validationpath.get_results_tag_folder(str(tmpdir), rev_to_gen),
50  "validation-test",
51  "validationTestPlots.root"
52  ),
53  expect_html_plots_comparison_json,
54  expect_html_plots_comparison_folder
55  ]
56 
57  check_path_exists(path_to_check)
58 
59  # run validation server
60  # must setup all content in the html folder required
61  validationserver.run_server(dry_run=True)
62 
63  # check if all files have been copied and the symbolic links properly
64  # set
65  path_to_check = [
66  os.path.join(str(tmpdir), validationpath.folder_name_html),
67  os.path.join(
68  str(tmpdir),
69  validationpath.folder_name_html,
70  validationpath.folder_name_plots
71  )
72  ]
73  check_path_exists(path_to_check)
74 
75  # remove generated plots and use create_validation_plots script to
76  # regenerate
77  shutil.rmtree(expect_html_plots_comparison_folder)
78 
79  # recreate
80  # switch to this folder
81  os.chdir(str(tmpdir))
82  check_execute("create_validation_plots.py")
83  check_path_exists(path_to_check)
84 
85 
86 if __name__ == "__main__":
87  main()
validationpath.get_results_tag_revision_file
def get_results_tag_revision_file(output_base_dir, tag)
Return the absolute path to the revision.json file for one tag folder.
Definition: validationpath.py:136
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
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
validationpath.get_html_plots_tag_comparison_json
def get_html_plots_tag_comparison_json(output_base_dir, tags)
Return the absolute path json file with the comparison file.
Definition: validationpath.py:108
validationpath.get_html_plots_tag_comparison_folder
def get_html_plots_tag_comparison_folder(output_base_dir, tags)
Return the absolute path to the results folder.
Definition: validationpath.py:91
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
validation.execute
def execute(tag=None, is_test=None)
Parses the command line and executes the full validation suite :param tag The name that will be used ...
Definition: validation.py:1311