Skip to content

Commit 6a1c378

Browse files
committed
Write unit tests for yamale validation, use strict_titles arg to control strict schema instead of path.
1 parent fab7ba5 commit 6a1c378

File tree

4 files changed

+74
-6
lines changed

4 files changed

+74
-6
lines changed

aws_doc_sdk_examples_tools/doc_gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def validate(self):
270270
service.validate(self.errors)
271271
for example in self.examples.values():
272272
example.validate(self.errors, self.root)
273-
validate_metadata(self.root, self.errors)
273+
validate_metadata(self.root, self.validation.strict_titles, self.errors)
274274
validate_no_duplicate_api_examples(self.examples.values(), self.errors)
275275
validate_snippets(
276276
[*self.examples.values()],

aws_doc_sdk_examples_tools/metadata_validator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def validate_files(
203203
return errors
204204

205205

206-
def validate_metadata(doc_gen_root: Path, errors: MetadataErrors) -> MetadataErrors:
206+
def validate_metadata(doc_gen_root: Path, strict: bool, errors: MetadataErrors) -> MetadataErrors:
207207
config = Path(__file__).parent / "config"
208208
with open(config / "sdks.yaml") as sdks_file:
209209
sdks_yaml: Dict[str, Any] = yaml.safe_load(sdks_file)
@@ -226,12 +226,10 @@ def validate_metadata(doc_gen_root: Path, errors: MetadataErrors) -> MetadataErr
226226
validators[String.tag] = StringExtension
227227

228228
config_root = Path(__file__).parent / "config"
229-
if "aws-doc-sdk-examples" in doc_gen_root.name:
229+
if strict:
230230
example_schema = "example_strict_schema.yaml"
231-
strict = True
232231
else:
233232
example_schema = "example_schema.yaml"
234-
strict = False
235233

236234
to_validate = [
237235
# (schema, metadata_glob)
@@ -259,9 +257,12 @@ def main():
259257
help="The folder that contains schema and metadata files.",
260258
required=False,
261259
)
260+
parser.add_argument(
261+
"--strict", default=True, help="Use strict schema.", required=False
262+
)
262263
args = parser.parse_args()
263264

264-
errors = validate_metadata(Path(args.doc_gen), MetadataErrors())
265+
errors = validate_metadata(Path(args.doc_gen), args.strict, MetadataErrors())
265266

266267
if len(errors) == 0:
267268
print("Validation succeeded! 👍👍👍")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
from pathlib import Path
6+
7+
import pytest
8+
9+
from .metadata_errors import MetadataErrors
10+
from .metadata_validator import validate_metadata
11+
12+
@pytest.mark.parametrize("strict", [True, False])
13+
def test_aws_entity_usage(strict):
14+
errors = MetadataErrors()
15+
validate_metadata(Path(Path(__file__).parent / "test_resources/doc_gen_test"), strict, errors)
16+
17+
e_str = str(errors)
18+
assert "Title has AWS" in e_str
19+
assert "Title Abbrev has AWS" in e_str
20+
assert "Synopsis has AWS" in e_str
21+
assert "Synopsis list has AWS" in e_str
22+
assert "Description has AWS" in e_str
23+
24+
assert "Title has &AWS;" not in e_str
25+
assert "Title Abbrev has &AWS;" not in e_str
26+
assert "Synopsis programlisting has AWS" not in e_str
27+
assert "Synopsis list code has <code>AWS" not in e_str
28+
assert "Description programlisting has AWS" not in e_str
29+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
sns_EntityFailures:
2+
title: Title has AWS using an &AWS; SDK
3+
title_abbrev: Title Abbrev has AWS in it
4+
synopsis: "Synopsis has AWS in it."
5+
synopsis_list:
6+
- "Synopsis list has AWS in it."
7+
category: Cat
8+
languages:
9+
Java:
10+
versions:
11+
- sdk_version: 1
12+
github: java/example_code/svc_EntityFailures
13+
sdkguide:
14+
excerpts:
15+
- description: Description has AWS in it.
16+
snippet_tags:
17+
- java.example_code.svc_EntityFailures.Test
18+
services:
19+
sns:
20+
sns_EntitySuccesses:
21+
title: Title has &AWS; using an &AWS; SDK
22+
title_abbrev: Title Abbrev has &AWS; in it
23+
synopsis: "this <programlisting>Synopsis programlisting has AWS in it.</programlisting>."
24+
synopsis_list:
25+
- "Synopsis list code has <code>AWS</code> in it."
26+
category: Cat
27+
languages:
28+
Java:
29+
versions:
30+
- sdk_version: 1
31+
github: java/example_code/svc_EntityFailures
32+
sdkguide:
33+
excerpts:
34+
- description: This <emphasis><programlisting>Description programlisting has AWS in it</programlisting></emphasis> doesn't it.
35+
snippet_tags:
36+
- java.example_code.svc_EntityFailures.Test
37+
services:
38+
sns:

0 commit comments

Comments
 (0)