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