1717See the License for the specific language governing permissions and
1818limitations under the License.
1919"""
20- import os . path as osp
20+ from pathlib import Path
2121import re
2222import bs4
2323import pytest
@@ -37,19 +37,16 @@ def in_between(full, sub, s0, *others):
3737
3838
3939def get_html (app , fname ):
40- with open (osp .join (str (app .outdir ), fname )) as f :
41- return f .read ()
40+ return (Path (app .outdir ) / fname ).read_text ()
41+
42+
43+ def get_soup (app , fname ):
44+ return bs4 .BeautifulSoup (get_html (app , fname ), 'html.parser' )
4245
4346
4447def in_autosummary (what , html ) -> bool :
4548 soup = bs4 .BeautifulSoup (html , "html.parser" )
46- autosummaries = soup ("table" )
47- found = False
48- for tag in autosummaries :
49- if tag .find_all ("span" , string = what ):
50- found = True
51- break
52- return found
49+ return any (tag .find_all ("span" , string = what ) for tag in soup ("table" ))
5350
5451
5552class TestAutosummaryDocumenter :
@@ -377,6 +374,11 @@ def test_module_submodule(self, app):
377374 assert re .findall (r'<td>.*href="#dummy_submodule\.submodule2'
378375 r'\.SubmoduleClass2\.func2".*</td>' , html )
379376
377+ def test_sorted_sections (self , app ):
378+ soup = get_soup (app , 'test_autoclasssumm_some_sections.html' )
379+ sections = soup .select ("p strong" )
380+ assert [s .string [:- 1 ] for s in sections ] == ["Attributes" , "DummySection" ]
381+
380382
381383class TestAutoDocSummDirective :
382384 """Test case for the :class:`autodocsumm.AutoDocSummDirective`."""
0 commit comments