view test/cmp_helper.py @ 6564:21c7c2041a4b

issue2551181 - allow issueXXX#fragment to generate a link with fragment There is another ticket to add id's to elements displaying messages in issue.item.html. This change allows a fast way to link to such an element in a long issue with many messages once that other issue is committed and merged into a tracker template.
author John Rouillard <rouilj@ieee.org>
date Wed, 15 Dec 2021 23:52:25 -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/