Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Commit cc69f87

Browse files
author
misakwa
committed
Move tests into test_hook.py
1 parent 5f1f01e commit cc69f87

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

tests/test_hook.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,39 @@ def test_tpayload_pickle():
7272
person_2 = pickle.loads(PICKLED_BYTES)
7373

7474
assert person == person_2
75+
76+
77+
def test_load_slots():
78+
thrift = thriftpy.load(
79+
'addressbook.thrift',
80+
use_slots=True,
81+
module_name='addressbook_thrift'
82+
)
83+
84+
# normal structs will have slots
85+
assert thrift.PhoneNumber.__slots__ == ['type', 'number', 'mix_item']
86+
assert thrift.Person.__slots__ == ['name', 'phones', 'created_at']
87+
assert thrift.AddressBook.__slots__ == ['people']
88+
89+
# XXX: should unions have slots?
90+
91+
# exceptions will not have slots
92+
assert not hasattr(thrift.PersonNotExistsError, '__slots__')
93+
94+
# services will not have slots
95+
assert not hasattr(thrift.AddressBookService, '__slots__')
96+
97+
# enums will not have slots
98+
assert not hasattr(thrift.PhoneType, '__slots__')
99+
100+
# one cannot get/set undefined attributes
101+
person = thrift.Person()
102+
with pytest.raises(AttributeError):
103+
person.attr_not_exist = "Does not work"
104+
person.attr_not_exist
105+
106+
# should be able to pickle slotted objects - if load with module_name
107+
bob = thrift.Person(name="Bob")
108+
p_str = pickle.dumps(bob)
109+
110+
assert pickle.loads(p_str) == bob

tests/test_parser.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -260,27 +260,3 @@ def test_issue_215():
260260
thrift = load('parser-cases/issue_215.thrift')
261261
assert thrift.abool is True
262262
assert thrift.falseValue == 123
263-
264-
265-
def test_load_slots():
266-
thrift = load('addressbook.thrift', use_slots=True)
267-
268-
# normal structs will have slots
269-
assert thrift.PhoneNumber.__slots__ == ['type', 'number', 'mix_item']
270-
assert thrift.Person.__slots__ == ['name', 'phones', 'created_at']
271-
assert thrift.AddressBook.__slots__ == ['people']
272-
273-
# exceptions will not have slots
274-
assert not hasattr(thrift.PersonNotExistsError, '__slots__')
275-
276-
# services will not have slots
277-
assert not hasattr(thrift.AddressBookService, '__slots__')
278-
279-
# enums will not have slots
280-
assert not hasattr(thrift.PhoneType, '__slots__')
281-
282-
# one cannot get/set undefined attributes
283-
person = thrift.Person()
284-
with pytest.raises(AttributeError):
285-
person.attr_not_exist = "Does not work"
286-
person.attr_not_exist

0 commit comments

Comments
 (0)