@@ -1720,18 +1720,21 @@ def count_label(name):
1720
1720
return content .count (text )
1721
1721
1722
1722
pattern = r'\\phantomsection\\label\{\\detokenize\{index:label-(?:auto-)?\d+[a-z]*}}'
1723
- expect_labels = {match .group () for match in re .finditer (pattern , content )}
1724
- result_labels = set ()
1723
+ # labels found in the TeX output
1724
+ output_labels = frozenset (match .group () for match in re .finditer (pattern , content ))
1725
+ # labels that have been tested and occurring exactly once in the output
1726
+ tested_labels = set ()
1725
1727
1726
1728
# iterate over the (explicit) labels in the corresponding index.rst
1727
- for rst_label_name in {
1729
+ for rst_label_name in [
1728
1730
'label_1a' , 'label_1b' , 'label_2' , 'label_3' ,
1729
1731
'label_auto_1a' , 'label_auto_1b' , 'label_auto_2' , 'label_auto_3' ,
1730
- } :
1732
+ ] :
1731
1733
tex_label_name = 'index:' + rst_label_name .replace ('_' , '-' )
1732
1734
tex_label_code = r'\phantomsection\label{\detokenize{%s}}' % tex_label_name
1733
1735
assert content .count (tex_label_code ) == 1 , f'duplicated label: { tex_label_name !r} '
1734
- result_labels .add (tex_label_code )
1736
+ tested_labels .add (tex_label_code )
1735
1737
1736
- # sort the labels for a better visual diff, if any
1737
- assert sorted (result_labels ) == sorted (expect_labels )
1738
+ # ensure that we did not forget any label to check
1739
+ # and if so, report them nicely in case of failure
1740
+ assert sorted (tested_labels ) == sorted (output_labels )
0 commit comments