예제 #1
0
def test_next_reads_only_one_user_and_then_thoughts(user_info, thought):
    parser = ProtobufSampleParser()
    b = BytesIO(b"".join(
        _build_message_buffer(x)
        for x in (user_info, thought, user_info, thought)))
    out = parser.next(b)
    with pytest.raises(DecodeError):
        out = parser.next(b)
예제 #2
0
def test_next_reads_all_thoughts(user_info, thought):
    """
    next should only return the thoughts, not the user.
    :param parser:
    :return:
    """
    parser = ProtobufSampleParser()
    b = BytesIO(b"".join(
        _build_message_buffer(x) for x in (user_info, thought, thought)))
    out = parser.next(b)
    assert parser.user == user_info
    while out:
        assert out.snapshot == thought
        out = parser.next(b)
예제 #3
0
def test_read_message():
    class Dummy:
        def ParseFromString(self, string):
            self.string = string

    test_string = b'this is a test string'
    test_dummy = Dummy()
    assert ProtobufSampleParser().read_message(BytesIO(struct.pack("I", len(test_string)) + test_string), test_dummy),\
                "returns failure on correct string"
    assert test_string == test_dummy.string
예제 #4
0
def test_next_reads_user_first(user_info):
    parser = ProtobufSampleParser()
    b = _build_message_buffer(user_info)
    assert parser.next(BytesIO(b)) is None
    assert parser.user == user_info
예제 #5
0
def test_parse_user(user_info):
    b = _build_message_buffer(user_info)
    assert ProtobufSampleParser().parse_user(BytesIO(b)) == user_info
예제 #6
0
def test_parse_thought(thought):
    b = _build_message_buffer(thought)
    p = ProtobufSampleParser().parse_thought(BytesIO(b))
    assert p.snapshot == thought
예제 #7
0
def test_read_message_size():
    size = 0xdeadbeef
    assert ProtobufSampleParser().read_message_size(
        BytesIO(struct.pack("I", size))) == size