Beispiel #1
0
def test_import_hook():
    ab_1 = thriftpy2.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.")

    thriftpy2.install_import_hook()

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

import thriftpy2
thriftpy2.install_import_hook()

import const_thrift as const  # noqa


def test_num_const():
    assert -10 == const.NEGATIVE_I16
    assert -123.456 == const.NEGATIVE_DOUBLE

    assert 10 == const.I16_CONST
    assert 100000 == const.I32_CONST
    assert 123.456 == const.DOUBLE_CONST


def test_string_const():
    assert "hello" == const.DOUBLE_QUOTED_CONST
    assert "hello" == const.SINGLE_QUOTED_CONST


def test_const_with_sep():
    assert "hello" == const.CONST_WITH_SEP1
    assert "hello" == const.CONST_WITH_SEP2


def test_list_const():
    assert [1, 2, 3] == const.I32_LIST_CONST
    assert [1.1, 2.2, 3.3] == const.DOUBLE_LIST_CONST
    assert ["hello", "world"] == const.STRING_LIST_CONST
Beispiel #3
0
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import os
import multiprocessing
import socket
import time

import pytest

import thriftpy2
thriftpy2.install_import_hook()  # noqa

from thriftpy2.http import make_server, make_client, client_context  # noqa
from thriftpy2.thrift import TApplicationException  # noqa

addressbook = thriftpy2.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