Mercurial > p > roundup > code
comparison test/cmp_helper.py @ 5513:19bd4b413ed6
be more lenient when comparing string results
| author | Christof Meerwald <cmeerw@cmeerw.org> |
|---|---|
| date | Sat, 18 Aug 2018 23:04:22 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 5512:c652849bfc75 | 5513:19bd4b413ed6 |
|---|---|
| 1 class StringFragmentCmpHelper: | |
| 2 def compareStringFragments(self, s, fragments): | |
| 3 """Compare a string agains a list of fragments where a tuple denotes a | |
| 4 set of alternatives | |
| 5 """ | |
| 6 pos = 0 | |
| 7 for frag in fragments: | |
| 8 if type(frag) != tuple: | |
| 9 self.assertEqual(s[pos:pos + len(frag)], frag) | |
| 10 pos += len(frag) | |
| 11 else: | |
| 12 found = False | |
| 13 for alt in frag: | |
| 14 if s[pos:pos + len(alt)] == alt: | |
| 15 pos += len(alt) | |
| 16 found = True | |
| 17 break | |
| 18 | |
| 19 if not found: | |
| 20 l = max(map(len, frag)) | |
| 21 raise AssertionError('%s != %s' % | |
| 22 (repr(s[pos:pos + l]), str(frag))) | |
| 23 self.assertEqual(s[pos:], '') |
