From 5df0fb45ca44282e011078b5386831bb4dcbc2ee Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 28 Nov 2021 21:21:02 -0500 Subject: [PATCH] unittests: make datatests capable of parsing module subsections properly We will need to update the tests for each module that gets newly added, apparently, but the basic structure for doing so is hopefully there. --- unittests/datatests.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/unittests/datatests.py b/unittests/datatests.py index b623f1f8e..4d4d3a19e 100644 --- a/unittests/datatests.py +++ b/unittests/datatests.py @@ -119,12 +119,18 @@ class DataTests(unittest.TestCase): found_entries = set() sections = re.finditer(r"^## (.+)$", md, re.MULTILINE) # Extract the content for this section + u_subcontents = [] content = self._get_section_content("Universal options", sections, md) subsections = tee(re.finditer(r"^### (.+)$", content, re.MULTILINE)) - subcontent1 = self._get_section_content("Directories", subsections[0], content) - subcontent2 = self._get_section_content("Core options", subsections[1], content) - subcontent3 = self._get_section_content("Module options", sections, md) - for subcontent in (subcontent1, subcontent2, subcontent3): + u_subcontents.append(self._get_section_content("Directories", subsections[0], content)) + u_subcontents.append(self._get_section_content("Core options", subsections[1], content)) + + mod_subcontents = [] + content = self._get_section_content("Module options", sections, md) + subsections = tee(re.finditer(r"^### (.+)$", content, re.MULTILINE)) + for idx, mod in enumerate(['Python']): + mod_subcontents.append(self._get_section_content(f'{mod} module', subsections[idx], content)) + for subcontent in u_subcontents + mod_subcontents: # Find the option names options = set() # Match either a table row or a table heading separator: | ------ | @@ -151,9 +157,9 @@ class DataTests(unittest.TestCase): # setting of builtin options behaves # # Find all tables inside this subsection - tables = re.finditer(r"^\| (\w+) .* \|\n\| *[-|\s]+ *\|$", subcontent2, re.MULTILINE) + tables = re.finditer(r"^\| (\w+) .* \|\n\| *[-|\s]+ *\|$", u_subcontents[1], re.MULTILINE) # Get the table we want using the header of the first column - table = self._get_section_content('buildtype', tables, subcontent2) + table = self._get_section_content('buildtype', tables, u_subcontents[1]) # Get table row data rows = re.finditer(r"^\|(?: (\w+)\s+\| (\w+)\s+\| (\w+) .* | *-+ *)\|", table, re.MULTILINE) env = get_fake_env()