5 from pathlib
import Path
8 class TestHeaderGenIntegration(unittest
.TestCase
):
10 self
.output_dir
= TestHeaderGenIntegration
.output_dir
11 self
.source_dir
= Path(__file__
).parent
12 self
.main_script
= self
.source_dir
.parent
/ "main.py"
14 def run_script(self
, yaml_file
, output_file
, entry_points
):
17 str(self
.main_script
),
23 for entry_point
in entry_points
:
24 command
.extend(["--entry-point", entry_point
])
26 result
= subprocess
.run(
32 print("STDOUT:", result
.stdout
)
33 print("STDERR:", result
.stderr
)
34 result
.check_returncode()
36 def compare_files(self
, generated_file
, expected_file
):
37 with generated_file
.open("r") as gen_file
:
38 gen_content
= gen_file
.read()
39 with expected_file
.open("r") as exp_file
:
40 exp_content
= exp_file
.read()
42 self
.assertEqual(gen_content
, exp_content
)
44 def test_generate_header(self
):
45 yaml_file
= self
.source_dir
/ "input/test_small.yaml"
46 expected_output_file
= self
.source_dir
/ "expected_output/test_header.h"
47 output_file
= self
.output_dir
/ "test_small.h"
48 entry_points
= {"func_b", "func_a", "func_c", "func_d", "func_e"}
50 self
.run_script(yaml_file
, output_file
, entry_points
)
52 self
.compare_files(output_file
, expected_output_file
)
56 parser
= argparse
.ArgumentParser(description
="TestHeaderGenIntegration arguments")
60 help="Output directory for generated headers",
63 args
, remaining_argv
= parser
.parse_known_args()
65 TestHeaderGenIntegration
.output_dir
= args
.output_dir
67 sys
.argv
[1:] = remaining_argv
72 if __name__
== "__main__":