forked from Thriftpy/thriftpy2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_loader.py
75 lines (50 loc) · 2.17 KB
/
test_loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from thriftpy2 import load
from thriftpy2.thrift import TPayload, TException, TType
import thriftpy2
thriftpy2.install_import_hook()
import addressbook as ab # noqa
import addressbook_thrift as ab_tt # noqa
import storm # noqa
import storm_thrift as storm_tt # noqa
def test_load_const():
assert ab.DEFAULT_LIST_SIZE == ab_tt.DEFAULT_LIST_SIZE
def test_load_enum():
assert ab.PhoneType.MOBILE == ab_tt.PhoneType.MOBILE
assert ab.PhoneType.HOME == ab_tt.PhoneType.HOME
assert ab.PhoneType.WORK == ab_tt.PhoneType.WORK
def test_load_struct():
assert ab_tt.PhoneNumber.__base__ == TPayload
ab_thrift_spec = {}
for k, vs in ab.PhoneNumber.thrift_spec.items():
ab_thrift_spec[k] = [str(v).replace('_thrift', '') for v in vs]
ab_tt_thrift_spec = {}
for k, vs in ab_tt.PhoneNumber.thrift_spec.items():
ab_tt_thrift_spec[k] = [str(v).replace('_thrift', '') for v in vs]
assert ab_thrift_spec == ab_tt_thrift_spec
assert storm_tt.NullStruct.__base__ == TPayload
assert storm.NullStruct.thrift_spec == storm_tt.NullStruct.thrift_spec
# TODO make this work
# assert ab_tt.Person.__base__ == TPayload
# assert ab.Person.thrift_spec == ab_tt.Person.thrift_spec
# assert ab_tt.AddressBook.__base__ == TPayload
# assert ab.AddressBook.thrift_spec == ab_tt.AddressBook.thrift_spec
def test_load_union():
assert storm_tt.JavaObjectArg.__base__ == TPayload
assert storm.JavaObjectArg.thrift_spec == \
storm_tt.JavaObjectArg.thrift_spec
def test_load_exc():
assert ab_tt.PersonNotExistsError.__base__ == TException
assert ab.PersonNotExistsError.thrift_spec == \
ab_tt.PersonNotExistsError.thrift_spec
def test_load_service():
assert not set(ab.AddressBookService.thrift_services).difference(
ab_tt.AddressBookService.thrift_services)
def test_load_include():
b = load("base.thrift")
g = load("parent.thrift")
ts = g.Greet.thrift_spec
assert (ts[1][2].thrift_spec == b.Hello.thrift_spec and
ts[2][0] == TType.I64 and
ts[3][2]._NAMES_TO_VALUES == b.Code._NAMES_TO_VALUES)