def test_unicode_iter(p): ctx = noop_manager() if is_exception(p.expected): ctx = raises(p.expected) with ctx: actual = list(unicode_iter(p.input)) if not is_exception(p.expected): assert p.expected == actual
def assert_writer_events(p, new_writer): buf, buf_writer = new_writer() ctx = noop_manager() if is_exception(p.expected): ctx = raises(p.expected) result_type = None with ctx: for event in p.events: result_type = buf_writer.send(event) if not is_exception(p.expected): assert result_type is WriteEventType.COMPLETE assert p.expected == buf.getvalue()
def test_blocking_reader(p): buf = BytesIO(p.data) reader = blocking_reader(p.coroutine, buf, buffer_size=1) for input, expected in zip(p.input, p.expected): if is_exception(expected): with raises(expected): reader.send(input) else: actual = reader.send(input) assert expected == actual
def reader_scaffold(reader, event_pairs): input_events = (e for e, _ in event_pairs) output_events = add_depths(e for _, e in event_pairs) for read_event, expected in zip(input_events, output_events): if is_exception(expected): with raises(expected): reader.send(read_event).value # Forces evaluation of all value thunks. else: actual = reader.send(read_event) assert expected == actual
def reader_scaffold(reader, event_pairs): input_events = (e for e, _ in event_pairs) output_events = add_depths(e for _, e in event_pairs) for read_event, expected in zip(input_events, output_events): if is_exception(expected): with raises(expected): reader.send(read_event) else: actual = reader.send(read_event) assert expected == actual
def test_catalog(p): catalog = symbols.SymbolTableCatalog() for table in REGISTER_TABLES: catalog.register(table) if is_exception(p.expected): with raises(p.expected): catalog.resolve(p.name, p.version, p.max_id) else: resolved = catalog.resolve(p.name, p.version, p.max_id) assert p.expected == resolved
def trampoline_scaffold(trampoline_func, p, *args): """Testing structure for trampolines. Args: trampoline_func (Callable): The function to construct a trampoline. p (TrampolineParams): The parameters for the test. """ trampoline = trampoline_func(p.coroutine, *args) assert len(p.input) == len(p.expected) for input, expected in zip(p.input, p.expected): if is_exception(expected): with raises(expected): trampoline.send(input) else: output = trampoline.send(input) assert expected == output
def trampoline_scaffold(trampoline_func, p): """Testing structure for trampolines. Args: trampoline_func (Callable): The function to construct a trampoline. p (TrampolineParams): The parameters for the test. """ trampoline = trampoline_func(p.coroutine) assert len(p.input) == len(p.expected) for input, expected in zip(p.input, p.expected): if is_exception(expected): with raises(expected): trampoline.send(input) else: output = trampoline.send(input) assert expected == output
def add_depths(events): """Adds the appropriate depths to an iterable of :class:`IonEvent`.""" depth = 0 for event in events: if is_exception(event): # Special case for expectation of exception. yield event else: if event.event_type == IonEventType.CONTAINER_END: depth -= 1 if event.event_type.is_stream_signal: yield event else: yield event.derive_depth(depth) if event.event_type == IonEventType.CONTAINER_START: depth += 1