Skip to content

Commit b7de1ed

Browse files
committed
task / regen / regen custom template golden record
1 parent 78d20ba commit b7de1ed

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

Diff for: end_to_end_tests/regen_golden_record.py

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
""" Regenerate golden-record """
22
import shutil
3+
import tempfile
4+
import os
5+
import filecmp
36
from pathlib import Path
47

58
from typer.testing import CliRunner
69

710
from openapi_python_client.cli import app
811

9-
if __name__ == "__main__":
12+
def regen_golden_record():
1013
runner = CliRunner()
1114
openapi_path = Path(__file__).parent / "openapi.json"
1215

@@ -24,3 +27,50 @@
2427
if result.exception:
2528
raise result.exception
2629
output_path.rename(gr_path)
30+
31+
32+
def regen_custom_template_golden_record():
33+
runner = CliRunner()
34+
openapi_path = Path(__file__).parent / "openapi.json"
35+
tpl_dir = Path(__file__).parent / "test_custom_templates"
36+
37+
gr_path = Path(__file__).parent / "golden-record"
38+
tpl_gr_path = Path(__file__).parent / "custom-templates-golden-record"
39+
40+
output_path = Path(tempfile.mkdtemp())
41+
config_path = Path(__file__).parent / "config.yml"
42+
43+
shutil.rmtree(tpl_gr_path, ignore_errors=True)
44+
45+
os.chdir(str(output_path.absolute()))
46+
result = runner.invoke(app, ["generate", f"--config={config_path}", f"--path={openapi_path}", f"--custom-template-path={tpl_dir}"])
47+
48+
if result.stdout:
49+
generated_output_path = output_path / 'my-test-api-client'
50+
for f in generated_output_path.glob("**/*"): # nb: works for Windows and Unix
51+
relative_to_generated = f.relative_to(generated_output_path)
52+
gr_file = gr_path / relative_to_generated
53+
if not gr_file.exists():
54+
print(f"{gr_file} does not exist, ignoring")
55+
continue
56+
57+
if not gr_file.is_file():
58+
continue
59+
60+
if not filecmp.cmp(gr_file, f, shallow=False):
61+
target_file = tpl_gr_path / relative_to_generated
62+
target_dir = target_file.parent
63+
64+
target_dir.mkdir(parents=True, exist_ok=True)
65+
shutil.copy(f"{f}", f"{target_file}")
66+
67+
shutil.rmtree(output_path, ignore_errors=True)
68+
69+
if result.exception:
70+
shutil.rmtree(output_path, ignore_errors=True)
71+
raise result.exception
72+
73+
74+
if __name__ == "__main__":
75+
regen_golden_record()
76+
regen_custom_template_golden_record()

0 commit comments

Comments
 (0)