Skip to content

Commit a0d0487

Browse files
committed
test: validate YAML files in the repo
We currently only check the swagger YAML file for validity. Moving the YAML check as a general repo test and adapt the swagger test as needed. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 9e7d00c commit a0d0487

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

tests/integration_tests/style/test_repo.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"""Tests enforcing git repository structure"""
55

66
import subprocess
7+
from pathlib import Path
8+
9+
import yaml
710

811

912
def test_repo_no_spaces_in_paths():
@@ -21,3 +24,15 @@ def test_repo_no_spaces_in_paths():
2124
)
2225
# If grep doesn't find any, it will exit with status 1. Otherwise 0
2326
assert res.returncode == 1, "Some files have spaces:\n" + res.stdout.decode()
27+
28+
29+
def test_repo_validate_yaml():
30+
"""
31+
Ensure all YAML files are valid
32+
33+
@type: style
34+
"""
35+
36+
repo_root = Path("..")
37+
for path in repo_root.rglob("*.y*ml"):
38+
yaml.safe_load(path.open(encoding="utf-8"))

tests/integration_tests/style/test_swagger.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,10 @@
44

55
from pathlib import Path
66

7-
import yaml
87
from openapi_spec_validator import validate_spec
98
from openapi_spec_validator.readers import read_from_filename
109

1110

12-
def check_yaml_style(yaml_spec):
13-
"""Check if the swagger definition is correctly formatted."""
14-
with open(yaml_spec, "r", encoding="utf-8") as file_stream:
15-
try:
16-
yaml.safe_load(file_stream)
17-
# pylint: disable=broad-except
18-
except Exception as exception:
19-
print(str(exception))
20-
21-
2211
def validate_swagger(swagger_spec):
2312
"""Fail if OpenAPI spec is not followed."""
2413
spec_dict, _ = read_from_filename(swagger_spec)
@@ -32,5 +21,4 @@ def test_firecracker_swagger():
3221
@type: style
3322
"""
3423
swagger_spec = Path("../src/api_server/swagger/firecracker.yaml")
35-
check_yaml_style(swagger_spec)
3624
validate_swagger(swagger_spec)

0 commit comments

Comments
 (0)