Skip to content

Commit 55fcff4

Browse files
committed
Create test_changelog.py
1 parent 3c7e487 commit 55fcff4

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

tests/unit/test_changelog.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
import json
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
REPO_ROOT = Path(__file__).parents[2]
9+
NEXT_RELEASE_DIR = REPO_ROOT / '.changes' / 'next-release'
10+
11+
12+
def _next_release_json_files():
13+
if not NEXT_RELEASE_DIR.is_dir():
14+
return []
15+
return [
16+
p for p in sorted(NEXT_RELEASE_DIR.iterdir())
17+
if p.suffix == '.json'
18+
]
19+
20+
21+
@pytest.mark.parametrize(
22+
"json_path",
23+
_next_release_json_files(),
24+
ids=lambda p: p.name,
25+
)
26+
def test_next_release_json_is_well_formed(json_path):
27+
raw = json_path.read_text('utf-8')
28+
try:
29+
entry = json.loads(raw)
30+
except json.JSONDecodeError as e:
31+
pytest.fail(f"{json_path.name} is not valid JSON: {e}")
32+
assert isinstance(entry, dict), (
33+
f"{json_path.name} should be a JSON object, "
34+
f"got {type(entry).__name__}"
35+
)
36+
VALID_TYPES = {'feature', 'bugfix', 'enhancement', 'api-change'}
37+
for key in ('category', 'description', 'type'):
38+
assert key in entry, f"{json_path.name} missing required key '{key}'"
39+
assert isinstance(entry[key], str) and entry[key].strip(), (
40+
f"{json_path.name} key '{key}' must be a non-empty string"
41+
)
42+
assert entry['type'] in VALID_TYPES, (
43+
f"{json_path.name} has invalid type '{entry['type']}', "
44+
f"must be one of {sorted(VALID_TYPES)}"
45+
)

0 commit comments

Comments
 (0)