view test/cmp_helper.py @ 7697:c73a1177c2b2

fix: roundup-demo, interactive mode would nuke an existing tracker. Tonu Mikk demonstrated a bug in roundup-demo. When invoked without a tracker home on the command line, it would nuke an existing directory specified interactively. There is still a minor bug. If an invalid home directory is specified, roundup-demo will prompt for the template to use before reporting: Error: Refusing to nuke non-tracker directory: but this doesn't cause data loss so not worth fixing at this time.
author John Rouillard <rouilj@ieee.org>
date Wed, 08 Nov 2023 21:18:34 -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/