Skip to content

Commit fc3888f

Browse files
author
maxime.c
committed
add bin/fix_acceptance_tests_yml.py
1 parent 9a075a1 commit fc3888f

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

bin/fix_acceptance_tests_yml.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script to transform YAML acceptance tests structure.
4+
5+
This script transforms YAML files from the old format:
6+
tests:
7+
spec: [...]
8+
connection: [...]
9+
10+
To the new format:
11+
acceptance_tests:
12+
spec:
13+
tests: [...]
14+
connection:
15+
tests: [...]
16+
"""
17+
18+
import yaml
19+
import sys
20+
from pathlib import Path
21+
from typing import Dict, Any
22+
23+
24+
class AlreadyUpdatedError(Exception):
25+
"""Exception raised when the YAML file has already been updated."""
26+
pass
27+
28+
29+
def transform(file_path: Path) -> None:
30+
with open(file_path, 'r') as f:
31+
data = yaml.safe_load(f)
32+
33+
if 'acceptance_tests' in data:
34+
raise AlreadyUpdatedError()
35+
36+
if 'tests' not in data:
37+
raise ValueError(f"No 'tests' key found in {file_path}, skipping transformation")
38+
39+
# Extract the tests data
40+
tests_data = data.pop('tests')
41+
42+
if not isinstance(tests_data, dict):
43+
raise ValueError(f"Error: 'tests' key in {file_path} is not a dictionary")
44+
45+
# Create the new acceptance_tests structure
46+
data['acceptance_tests'] = {}
47+
48+
# Transform each test type
49+
for test_type, test_content in tests_data.items():
50+
data['acceptance_tests'][test_type] = {'tests': test_content}
51+
52+
# Write back to file with preserved formatting
53+
with open(file_path, 'w') as f:
54+
yaml.dump(data, f, default_flow_style=False, sort_keys=False, indent=2)
55+
56+
print(f"Successfully transformed {file_path}")
57+
58+
59+
def main():
60+
if len(sys.argv) != 2:
61+
print("Usage: python fix_acceptance_tests_yml.py <airbyte_repo_path>")
62+
sys.exit(1)
63+
64+
repo_path = Path(sys.argv[1])
65+
66+
for file_path in repo_path.glob('airbyte-integrations/connectors/source-*/acceptance-test-config.yml'):
67+
try:
68+
transform(file_path)
69+
except AlreadyUpdatedError:
70+
print(f"File {file_path} has already been updated, skipping transformation")
71+
except yaml.YAMLError as e:
72+
print(f"Error parsing YAML file {file_path}: {e}")
73+
except Exception as e:
74+
print(f"Error transforming {file_path}: {e}")
75+
76+
77+
if __name__ == "__main__":
78+
main()

0 commit comments

Comments
 (0)