forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_end_to_end.py
40 lines (30 loc) · 1.41 KB
/
test_end_to_end.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import shutil
from filecmp import cmpfiles, dircmp
from pathlib import Path
import pytest
from typer.testing import CliRunner
from openapi_python_client.cli import app
def _compare_directories(first: Path, second: Path, /):
first_printable = first.relative_to(Path.cwd())
second_printable = second.relative_to(Path.cwd())
dc = dircmp(first, second)
missing_files = dc.left_only + dc.right_only
if missing_files:
pytest.fail(f"{first_printable} or {second_printable} was missing: {missing_files}", pytrace=False)
match, mismatch, errors = cmpfiles(first, second, dc.common_files, shallow=False)
if mismatch:
for error in errors:
pytest.fail(f"{first_printable} and {second_printable} had differing files: {mismatch}, first error is {error}", pytrace=False)
for sub_path in dc.common_dirs:
_compare_directories(first / sub_path, second / sub_path)
def test_end_to_end(capsys):
runner = CliRunner()
openapi_path = Path(__file__).parent / "fastapi" / "openapi.json"
config_path = Path(__file__).parent / "config.yml"
gm_path = Path(__file__).parent / "golden-master"
output_path = Path.cwd() / "my-test-api-client"
result = runner.invoke(app, [f"--config={config_path}", "generate", f"--path={openapi_path}"])
if result.exit_code != 0:
raise result.exception
_compare_directories(gm_path, output_path)
shutil.rmtree(output_path)