@@ -71,6 +71,9 @@ def is_registered_term(index, keyword):
7171
7272.. test that comments are not indexed: boson
7373
74+ another_title
75+ =============
76+
7477test that non-comments are indexed: fermion
7578'''
7679
@@ -168,6 +171,10 @@ def test_IndexBuilder():
168171 'docname2_1' : 'title2_1' , 'docname2_2' : 'title2_2' }
169172 assert index ._filenames == {'docname1_1' : 'filename1_1' , 'docname1_2' : 'filename1_2' ,
170173 'docname2_1' : 'filename2_1' , 'docname2_2' : 'filename2_2' }
174+ # note: element iteration order (sort order) is important when the index
175+ # is frozen (serialized) during build -- however, the _mapping-related
176+ # dictionaries below may be iterated in arbitrary order by Python at
177+ # runtime.
171178 assert index ._mapping == {
172179 'ar' : {'docname1_1' , 'docname1_2' , 'docname2_1' , 'docname2_2' },
173180 'fermion' : {'docname1_1' , 'docname1_2' , 'docname2_1' , 'docname2_2' },
@@ -176,7 +183,10 @@ def test_IndexBuilder():
176183 'index' : {'docname1_1' , 'docname1_2' , 'docname2_1' , 'docname2_2' },
177184 'test' : {'docname1_1' , 'docname1_2' , 'docname2_1' , 'docname2_2' },
178185 }
179- assert index ._title_mapping == {'section_titl' : {'docname1_1' , 'docname1_2' , 'docname2_1' , 'docname2_2' }}
186+ assert index ._title_mapping == {
187+ 'another_titl' : {'docname1_1' , 'docname1_2' , 'docname2_1' , 'docname2_2' },
188+ 'section_titl' : {'docname1_1' , 'docname1_2' , 'docname2_1' , 'docname2_2' },
189+ }
180190 assert index ._objtypes == {}
181191 assert index ._objnames == {}
182192
@@ -196,8 +206,14 @@ def test_IndexBuilder():
196206 'non' : [0 , 1 , 2 , 3 ],
197207 'test' : [0 , 1 , 2 , 3 ]},
198208 'titles' : ('title1_1' , 'title1_2' , 'title2_1' , 'title2_2' ),
199- 'titleterms' : {'section_titl' : [0 , 1 , 2 , 3 ]},
200- 'alltitles' : {'section_title' : [(0 , 'section-title' ), (1 , 'section-title' ), (2 , 'section-title' ), (3 , 'section-title' )]},
209+ 'titleterms' : {
210+ 'another_titl' : [0 , 1 , 2 , 3 ],
211+ 'section_titl' : [0 , 1 , 2 , 3 ],
212+ },
213+ 'alltitles' : {
214+ 'another_title' : [(0 , 'another-title' ), (1 , 'another-title' ), (2 , 'another-title' ), (3 , 'another-title' )],
215+ 'section_title' : [(0 , None ), (1 , None ), (2 , None ), (3 , None )],
216+ },
201217 'indexentries' : {},
202218 }
203219 assert index ._objtypes == {('dummy1' , 'objtype1' ): 0 , ('dummy2' , 'objtype1' ): 1 }
@@ -238,7 +254,10 @@ def test_IndexBuilder():
238254 'index' : {'docname1_2' , 'docname2_2' },
239255 'test' : {'docname1_2' , 'docname2_2' },
240256 }
241- assert index ._title_mapping == {'section_titl' : {'docname1_2' , 'docname2_2' }}
257+ assert index ._title_mapping == {
258+ 'another_titl' : {'docname1_2' , 'docname2_2' },
259+ 'section_titl' : {'docname1_2' , 'docname2_2' },
260+ }
242261 assert index ._objtypes == {('dummy1' , 'objtype1' ): 0 , ('dummy2' , 'objtype1' ): 1 }
243262 assert index ._objnames == {0 : ('dummy1' , 'objtype1' , 'objtype1' ), 1 : ('dummy2' , 'objtype1' , 'objtype1' )}
244263
@@ -257,8 +276,14 @@ def test_IndexBuilder():
257276 'non' : [0 , 1 ],
258277 'test' : [0 , 1 ]},
259278 'titles' : ('title1_2' , 'title2_2' ),
260- 'titleterms' : {'section_titl' : [0 , 1 ]},
261- 'alltitles' : {'section_title' : [(0 , 'section-title' ), (1 , 'section-title' )]},
279+ 'titleterms' : {
280+ 'another_titl' : [0 , 1 ],
281+ 'section_titl' : [0 , 1 ],
282+ },
283+ 'alltitles' : {
284+ 'another_title' : [(0 , 'another-title' ), (1 , 'another-title' )],
285+ 'section_title' : [(0 , None ), (1 , None )],
286+ },
262287 'indexentries' : {},
263288 }
264289 assert index ._objtypes == {('dummy1' , 'objtype1' ): 0 , ('dummy2' , 'objtype1' ): 1 }
@@ -347,7 +372,8 @@ def assert_is_sorted(item, path: str):
347372 assert_is_sorted (value , f'{ path } .{ key } ' )
348373 elif isinstance (item , list ):
349374 if not is_title_tuple_type (item ) and path not in lists_not_to_sort :
350- assert item == sorted (item ), f'{ err_path } is not sorted'
375+ # sort nulls last; http://stackoverflow.com/questions/19868767/
376+ assert item == sorted (item , key = lambda x : (x is None , x )), f'{ err_path } is not sorted'
351377 for i , child in enumerate (item ):
352378 assert_is_sorted (child , f'{ path } [{ i } ]' )
353379
0 commit comments