[libc-commits] [libc] [libc] created integration tests for newhdrgen (PR #97361)
via libc-commits
libc-commits at lists.llvm.org
Mon Jul 1 16:14:36 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r 03e46475f510d9d7fa813dcfa1fd91894af39862...f86c14bbf243b9d25daedbd0021ffa3b8058f7ea libc/newhdrgen/tests/test_integration.py libc/newhdrgen/yaml_to_classes.py
``````````
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- tests/test_integration.py 2024-07-01 22:55:42.000000 +0000
+++ tests/test_integration.py 2024-07-01 23:14:09.864606 +0000
@@ -1,42 +1,53 @@
import subprocess
import unittest
from pathlib import Path
+
class TestHeaderGenIntegration(unittest.TestCase):
def setUp(self):
- self.output_dir = Path('tests/output')
- self.maxDiff = None
+ self.output_dir = Path("tests/output")
+ self.maxDiff = None
def run_script(self, yaml_file, h_def_file, output_dir):
- result = subprocess.run([
- 'python3', 'yaml_to_classes.py', yaml_file, h_def_file, '--output_dir', str(output_dir)
- ], capture_output=True, text=True)
+ result = subprocess.run(
+ [
+ "python3",
+ "yaml_to_classes.py",
+ yaml_file,
+ h_def_file,
+ "--output_dir",
+ str(output_dir),
+ ],
+ capture_output=True,
+ text=True,
+ )
print("STDOUT:", result.stdout)
print("STDERR:", result.stderr)
- result.check_returncode()
+ result.check_returncode()
def compare_files(self, generated_file, expected_file):
- with generated_file.open('r') as gen_file:
+ with generated_file.open("r") as gen_file:
gen_content = gen_file.read()
- with expected_file.open('r') as exp_file:
+ with expected_file.open("r") as exp_file:
exp_content = exp_file.read()
-
+
self.assertEqual(gen_content, exp_content)
def test_generate_header(self):
# this is for example, will find a way to test everything at once
- yaml_file = Path('tests/input/test_string.yaml')
- h_def_file = Path('tests/input/string.h.def')
- expected_output_file = Path('tests/expected_output/string.h')
- output_file = self.output_dir / 'string.h'
+ yaml_file = Path("tests/input/test_string.yaml")
+ h_def_file = Path("tests/input/string.h.def")
+ expected_output_file = Path("tests/expected_output/string.h")
+ output_file = self.output_dir / "string.h"
if not self.output_dir.exists():
self.output_dir.mkdir(parents=True)
self.run_script(yaml_file, h_def_file, self.output_dir)
self.compare_files(output_file, expected_output_file)
-if __name__ == '__main__':
+
+if __name__ == "__main__":
unittest.main()
--- yaml_to_classes.py 2024-07-01 22:55:42.000000 +0000
+++ yaml_to_classes.py 2024-07-01 23:14:09.924416 +0000
@@ -45,11 +45,11 @@
header.add_enumeration(
Enumeration(enum_data["name"], enum_data.get("value", None))
)
functions = yaml_data.get("functions", [])
- sorted_functions = sorted(functions, key=lambda x: x['name'])
+ sorted_functions = sorted(functions, key=lambda x: x["name"])
for function_data in sorted_functions:
arguments = [arg["type"] for arg in function_data["arguments"]]
guard = function_data.get("guard", None)
attributes = function_data.get("attributes", None)
standards = function_data.get("standards", None)
``````````
</details>
https://github.com/llvm/llvm-project/pull/97361
More information about the libc-commits
mailing list