Skip to content

Commit 6c6475c

Browse files
authored
Adds support to update/fix headings with wrong capitalization (#65)
* Refactores path excludes to be easier extendable * Adds support to update/fix headings with wrong capitalization
1 parent 24fa725 commit 6c6475c

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

tools/tests/topic_updater_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,28 @@ def test_heading_lookup(self):
107107
missing_mid.meta_text[0].rstrip(),
108108
"_ This section could be missing in the middle of the topics _")
109109

110+
def test_heading_lookup_wrong_capitalization(self):
111+
"""
112+
Checks if we can lookup different section headings in the skeleton,
113+
even if the original text is wrongly capitialized.
114+
"""
115+
wrong_upper_case_heading = self.test_skeleton.lookup_heading(
116+
"## Section with User content:")
117+
wrong_lower_case_heading = self.test_skeleton.lookup_heading(
118+
"## missing mid section")
119+
120+
self.assertEqual(wrong_upper_case_heading.header_text,
121+
"## Section with user content: provided by the user")
122+
self.assertEqual(
123+
wrong_upper_case_heading.meta_text[0].rstrip(),
124+
"_ Example section where user text is in the header _")
125+
126+
self.assertEqual(wrong_lower_case_heading.header_text,
127+
"## Missing mid section")
128+
self.assertEqual(
129+
wrong_lower_case_heading.meta_text[0].rstrip(),
130+
"_ This section could be missing in the middle of the topics _")
131+
110132
def test_title_heading_lookup(self):
111133
"""
112134
Checks if we get the correct title heading from the test skeleton.

topic_updater.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def lookup_heading(self, start_heading_line: str) -> SectionHeading:
102102
Returns: the section heading that starts like the heading line
103103
"""
104104
for heading in self.headings:
105-
if start_heading_line.startswith(
106-
heading.header_text.split(":")[0]):
105+
if start_heading_line.lower().startswith(
106+
heading.header_text.split(":")[0].lower()):
107107
return heading
108108
raise LookupError(
109109
f"Could not find heading that starts with: {start_heading_line}")
@@ -306,8 +306,7 @@ def __str__(self) -> str:
306306
return skeleton_text
307307

308308

309-
def check_skeletons(skeleton: Skeleton,
310-
topic_paths: tp.Iterator[Path]) -> bool:
309+
def check_skeletons(skeleton: Skeleton, topic_paths: tp.List[Path]) -> bool:
311310
"""
312311
Check of the topics files match the skeleton.
313312
@@ -328,8 +327,7 @@ def check_skeletons(skeleton: Skeleton,
328327
return all_files_matched
329328

330329

331-
def update_skeletons(skeleton: Skeleton,
332-
topic_paths: tp.Iterator[Path]) -> None:
330+
def update_skeletons(skeleton: Skeleton, topic_paths: tp.List[Path]) -> None:
333331
"""
334332
Update the topics files to match the skeleton.
335333
@@ -381,11 +379,16 @@ def main() -> None:
381379
if not args.topic_paths:
382380

383381
def exclude_non_topic_files(path: Path) -> bool:
384-
return not (path.name == "skeleton.md"
385-
or str(path).startswith(".github"))
382+
excluded_files = ["skeleton.md", "Readme.md"]
383+
excluded_folders = [".github", "tools"]
384+
for exclude_folder in excluded_folders:
385+
if str(path).startswith(exclude_folder):
386+
return False
387+
return path.name not in excluded_files
386388

387-
topic_paths = filter(exclude_non_topic_files,
388-
Path(".").glob("**/*.md"))
389+
topic_paths = list(
390+
filter(exclude_non_topic_files,
391+
Path(".").glob("**/*.md")))
389392
else:
390393
topic_paths = args.topic_paths
391394

0 commit comments

Comments
 (0)