Skip to content

Commit ef2332c

Browse files
committed
Adds support to update/fix headings with wrong capitalization
1 parent 5d3945e commit ef2332c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
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: 2 additions & 2 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}")

0 commit comments

Comments
 (0)