view test/cmp_helper.py @ 6459:0e86ea84e59d

Debugging and test fixes for CI test_compression_br worked on my box under python 3.6. In CI it worked in 3.4 but failed on all other versions 3.6,7,8,9,dev. Error: json_dict = json.loads(b2s(brotli.decompress(f.content))) E brotli.error: BrotliDecompress failed so print f.content. Also restructured the code to not check for type of f.content. Instead try json.loads(f.content) and if we get an exception try decompressing. Use this for br and zstd tests.
author John Rouillard <rouilj@ieee.org>
date Sat, 24 Jul 2021 18:23:21 -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/