示例#1
0
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
示例#2
0
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
示例#3
0
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()
示例#4
0
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()
示例#5
0
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
示例#6
0
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
示例#7
0
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
示例#8
0
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
示例#9
0
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
示例#10
0
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
示例#11
0
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
示例#12
0
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
示例#13
0
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