Ejemplo n.º 1
0
def test_import_hook():
    ab_1 = thriftpy.load("addressbook.thrift")
    print("Load file succeed.")
    assert ab_1.DEFAULT_LIST_SIZE == 10

    try:
        import addressbook_thrift as ab  # noqa
    except ImportError:
        print("Import hook not installed.")

    thriftpy.install_import_hook()

    import addressbook_thrift as ab_2
    print("Magic import succeed.")
    assert ab_2.DEFAULT_LIST_SIZE == 10
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-

import thriftpy
thriftpy.install_import_hook()

from thriftpy.utils import serialize, deserialize

import container_thrift as container


def test_list_item():
    l_item = container.ListItem()
    l_item.list_string = ['foo', 'bar']
    l_item.list_list_string = [['foo', 'bar']]

    b = serialize(l_item)
    l_item2 = deserialize(container.ListItem(), b)
    assert l_item == l_item2


def test_map_item():
    m_item = container.MapItem()
    m_item.map_string = {'foo': 'bar'}
    m_item.map_map_string = {'foo': {'hello': 'world'}}

    m_item2 = deserialize(container.MapItem(), serialize(m_item))
    assert m_item == m_item2


def test_mix_item():
    x_item = container.MixItem()
Ejemplo n.º 3
0
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import os
import multiprocessing
import socket
import time

import pytest

import thriftpy
thriftpy.install_import_hook()  # noqa

from thriftpy.http import make_server, client_context

addressbook = thriftpy.load(
    os.path.join(os.path.dirname(__file__), "addressbook.thrift"))


class Dispatcher():
    def __init__(self):
        self.ab = addressbook.AddressBook()
        self.ab.people = {}

    def ping(self):
        return True

    def hello(self, name):
        return "hello " + name
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-

import thriftpy
thriftpy.install_import_hook()  # noqa

from thriftpy.utils import serialize, deserialize

import container_thrift as container


def test_list_item():
    l_item = container.ListItem()
    l_item.list_string = ['foo', 'bar']
    l_item.list_list_string = [['foo', 'bar']]

    b = serialize(l_item)
    l_item2 = deserialize(container.ListItem(), b)
    assert l_item == l_item2

    l_item3 = container.ListItem()
    assert l_item != l_item3


def test_map_item():
    m_item = container.MapItem()
    m_item.map_string = {'foo': 'bar'}
    m_item.map_map_string = {'foo': {'hello': 'world'}}

    b = serialize(m_item)
    m_item2 = deserialize(container.MapItem(), b)
    assert m_item == m_item2