def t(str, value, remainder): print(str) # Test "one-shot": assert process(str) == (value, remainder) # With gibberish added: assert process(str + "asdf") == (value, remainder + "asdf") # Byte at a time: decoder = IncrBDecode() for i, c in enumerate(str): decoder.add(c) retval = decoder.process() if retval is not None: print(retval) assert retval == (value, "") assert str[i + 1:] == remainder break
def te(str, exc): print(str) try: process(str) except exc: pass else: assert False, "didn't raise exception" try: decoder = IncrBDecode() for c in str: decoder.add(c) decoder.process() except exc: pass else: assert False, "didn't raise exception"
def process(input): bd = IncrBDecode() bd.add(input) return bd.process()