Skip to content

Commit f917a87

Browse files
authored
Error on missing entities, replace on empty entities. (#58)
* Error on missing entities, replace on empty entities.
1 parent 9e8dd5c commit f917a87

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

aws_doc_sdk_examples_tools/entities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def expand_entity(
8787
entity: str, entity_map: Dict[str, str]
8888
) -> Tuple[str, Optional[EntityError]]:
8989
expanded = entity_map.get(entity)
90-
if expanded:
90+
if expanded is not None:
9191
return entity.replace(entity, expanded), None
9292
else:
93-
return "", MissingEntityError(entity)
93+
return entity, MissingEntityError(entity)

aws_doc_sdk_examples_tools/entities_test.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ def test_entity_errors_append():
1717
errors.append("invalid item")
1818

1919

20-
def test_expand_all_entities():
20+
def test_expand_missing_entities():
2121
entity_map = {
2222
"&entity1;": "expanded1",
2323
"&entity2;": "expanded2",
24-
"&entity3;": "",
2524
}
2625

2726
text = "This is a text with &entity1; and &entity2; and &entity3;"
@@ -33,6 +32,16 @@ def test_expand_all_entities():
3332
assert errors._errors[0].entity == "&entity3;"
3433

3534

35+
def test_expand_empty_entity():
36+
entity_map = {"&entity1;": "expanded1", "&entity2;": "expanded2", "&entity3;": ""}
37+
38+
text = "This is a text with &entity1; and &entity2; and &entity3;"
39+
expanded_text, errors = expand_all_entities(text, entity_map)
40+
41+
assert expanded_text == "This is a text with expanded1 and expanded2 and "
42+
assert len(errors._errors) == 0
43+
44+
3645
def test_expand_all_entities_with_no_entities():
3746
entity_map = {
3847
"&entity1;": "expanded1",

0 commit comments

Comments
 (0)