@@ -32,6 +32,15 @@ def setUpClass(cls):
3232
3333 super ().setUpClass ()
3434
35+ def _parse_table (self , table_index : int ):
36+ """Parse HTML table at given index from README.md content."""
37+
38+ table_cell_re = re .compile (r"<td>(.*?)</td>" )
39+ tables = re .findall (r"<table style.*?</table>" , self .readme_content , re .DOTALL ) # type: ignore[attr-defined]
40+ table = tables [table_index ]
41+ rows = re .findall (r"<tr>(.*?)</tr>" , table , re .DOTALL )
42+ return [table_cell_re .findall (line ) for line in rows [1 :]]
43+
3544 def test_supported_countries_count (self ):
3645 actual_country_count = len (list_supported_countries (include_aliases = False ))
3746 readme_country_count = int (
@@ -46,7 +55,6 @@ def test_supported_countries_count(self):
4655 )
4756
4857 def test_supported_countries_table (self ):
49- # Parse table data.
5058 country_alpha_2_codes = set ()
5159 country_default_languages = {}
5260 country_names = []
@@ -57,12 +65,10 @@ def test_supported_countries_table(self):
5765 subdivision_group_re = re .compile (r"\w+:\s*([^\n:]+)" )
5866 subdivision_and_aliases_re = re .compile (r",(?![^()]*\))" )
5967 subdivision_aliases_re = re .compile (r"(.*?)\s\(([^()]*)\)" )
60- table_cell_re = re .compile (r"<td>(.*?)</td>" )
6168 default_value_re = re .compile (r"<strong>(.*?)</strong>" )
6269
63- countries_table = re .findall (r"<table style.*?</table>" , self .readme_content , re .DOTALL )[0 ]
64- rows = re .findall (r"<tr>(.*?)</tr>" , countries_table , re .DOTALL )
65- table_content = [table_cell_re .findall (line ) for line in rows [1 :]]
70+ # Parse 1st table.
71+ table_content = self ._parse_table (0 )
6672
6773 for row in table_content :
6874 # Country: 1st column.
@@ -226,17 +232,14 @@ def test_supported_countries_table(self):
226232 )
227233
228234 def test_supported_markets_table (self ):
229- # Parse table data.
230235 market_mic_codes = set ()
231236 market_default_languages = {}
232237 market_names = []
233238 market_supported_languages = {}
234- table_cell_re = re .compile (r"<td>(.*?)</td>" )
235239 default_value_re = re .compile (r"<strong>(.*?)</strong>" )
236240
237- markets_table = re .findall (r"<table style.*?</table>" , self .readme_content , re .DOTALL )[1 ]
238- rows = re .findall (r"<tr>(.*?)</tr>" , markets_table , re .DOTALL )
239- table_content = [table_cell_re .findall (line ) for line in rows [1 :]]
241+ # Parse 2nd table.
242+ table_content = self ._parse_table (1 )
240243 replace_chars = str .maketrans (
241244 {
242245 " " : "" ,
0 commit comments