Skip to content

Adds support to update/fix headings with wrong capitalization #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tools/tests/topic_updater_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,28 @@ def test_heading_lookup(self):
missing_mid.meta_text[0].rstrip(),
"_ This section could be missing in the middle of the topics _")

def test_heading_lookup_wrong_capitalization(self):
"""
Checks if we can lookup different section headings in the skeleton,
even if the original text is wrongly capitialized.
"""
wrong_upper_case_heading = self.test_skeleton.lookup_heading(
"## Section with User content:")
wrong_lower_case_heading = self.test_skeleton.lookup_heading(
"## missing mid section")

self.assertEqual(wrong_upper_case_heading.header_text,
"## Section with user content: provided by the user")
self.assertEqual(
wrong_upper_case_heading.meta_text[0].rstrip(),
"_ Example section where user text is in the header _")

self.assertEqual(wrong_lower_case_heading.header_text,
"## Missing mid section")
self.assertEqual(
wrong_lower_case_heading.meta_text[0].rstrip(),
"_ This section could be missing in the middle of the topics _")

def test_title_heading_lookup(self):
"""
Checks if we get the correct title heading from the test skeleton.
Expand Down
23 changes: 13 additions & 10 deletions topic_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def lookup_heading(self, start_heading_line: str) -> SectionHeading:
Returns: the section heading that starts like the heading line
"""
for heading in self.headings:
if start_heading_line.startswith(
heading.header_text.split(":")[0]):
if start_heading_line.lower().startswith(
heading.header_text.split(":")[0].lower()):
return heading
raise LookupError(
f"Could not find heading that starts with: {start_heading_line}")
Expand Down Expand Up @@ -306,8 +306,7 @@ def __str__(self) -> str:
return skeleton_text


def check_skeletons(skeleton: Skeleton,
topic_paths: tp.Iterator[Path]) -> bool:
def check_skeletons(skeleton: Skeleton, topic_paths: tp.List[Path]) -> bool:
"""
Check of the topics files match the skeleton.

Expand All @@ -328,8 +327,7 @@ def check_skeletons(skeleton: Skeleton,
return all_files_matched


def update_skeletons(skeleton: Skeleton,
topic_paths: tp.Iterator[Path]) -> None:
def update_skeletons(skeleton: Skeleton, topic_paths: tp.List[Path]) -> None:
"""
Update the topics files to match the skeleton.

Expand Down Expand Up @@ -381,11 +379,16 @@ def main() -> None:
if not args.topic_paths:

def exclude_non_topic_files(path: Path) -> bool:
return not (path.name == "skeleton.md"
or str(path).startswith(".github"))
excluded_files = ["skeleton.md", "Readme.md"]
excluded_folders = [".github", "tools"]
for exclude_folder in excluded_folders:
if str(path).startswith(exclude_folder):
return False
return path.name not in excluded_files

topic_paths = filter(exclude_non_topic_files,
Path(".").glob("**/*.md"))
topic_paths = list(
filter(exclude_non_topic_files,
Path(".").glob("**/*.md")))
else:
topic_paths = args.topic_paths

Expand Down