view test/cmp_helper.py @ 7751:bd013590d8d6

docs: optimize head section of templates Reordered the head section of website/www using capo.js to improve speed. Tried to do the same for the doc/_template/layout.html. Due to a bug in sphinx, we get duplicate viewport tags. https://github.com/sphinx-doc/sphinx/issues/11699 but I think it's harmless.
author John Rouillard <rouilj@ieee.org>
date Fri, 01 Mar 2024 14:07:28 -0500
parents 19bd4b413ed6
children
line wrap: on
line source

class StringFragmentCmpHelper:
    def compareStringFragments(self, s, fragments):
        """Compare a string agains a list of fragments where a tuple denotes a
        set of alternatives
        """
        pos = 0
        for frag in fragments:
            if type(frag) != tuple:
                self.assertEqual(s[pos:pos + len(frag)], frag)
                pos += len(frag)
            else:
                found = False
                for alt in frag:
                    if s[pos:pos + len(alt)] == alt:
                        pos += len(alt)
                        found = True
                        break

                if not found:
                    l = max(map(len, frag))
                    raise AssertionError('%s != %s' %
                                         (repr(s[pos:pos + l]), str(frag)))
        self.assertEqual(s[pos:], '')

Roundup Issue Tracker: http://roundup-tracker.org/