Skip to content

Commit 1aaecea

Browse files
p1-raNementon
authored andcommitted
task / regen / regen custom template golden record
1 parent d7831e1 commit 1aaecea

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

end_to_end_tests/regen_golden_record.py

+54-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
""" Regenerate golden-record """
2+
import filecmp
3+
import os
24
import shutil
5+
import tempfile
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+
13+
def regen_golden_record():
1014
runner = CliRunner()
1115
openapi_path = Path(__file__).parent / "openapi.json"
1216

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

0 commit comments

Comments
 (0)