view test/cmp_helper.py @ 6363:08e209a7f22b

Use OptionValueError for indexer_language error, add configuration tests Added more tests for configuration.py. This is the last of the easy to do tests for the module. While doing that figured out how to get the proper arguments to generate OptionValueError if indexer_language is invalid. Changed implementation to generate same and updated test.
author John Rouillard <rouilj@ieee.org>
date Tue, 30 Mar 2021 18:03:37 -0400
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/