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

Commit

Permalink
Merge pull request #39 from mikekap/develop
Browse files Browse the repository at this point in the history
Fix set constants.
  • Loading branch information
lxyu committed Sep 11, 2014
2 parents fbec1ea + f8a1b36 commit 667d3c8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/parser-cases/json/consts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"num3": 30000000000,
"str": "hello",
"lst": [1, 2, 3],
"mp": {"key": "val"}
"mp": {"key": "val"},
"st": [1, 2, 3]
},
"includes": [],
"namespaces": {},
Expand Down
1 change: 1 addition & 0 deletions tests/parser-cases/thrift/consts.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ const i32 num2 = 2000
const i64 num3 = 30000000000
const string str = "hello"
const list<i32> lst = [1, 2, 3]
const set<i32> st = [1, 2, 3]
const map<string, string> mp = {"key": "val"}
9 changes: 8 additions & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ def _json(name):
return json.load(open(path))


def _to_json(value):
if isinstance(value, (set, frozenset)):
return list(sorted(value))

assert False


def _thrift(name):
path = os.path.join('parser-cases', 'thrift', name + '.thrift')
return parse(open(path).read())
return json.loads(json.dumps(parse(open(path).read()), default=_to_json))


class TestParser(object):
Expand Down
4 changes: 3 additions & 1 deletion thriftpy/parser/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ def cast(self, data):


class SetType(ContainerType): # ['set', v_type]
pass

def cast(self, data):
return frozenset(map(self[1].cast, data))


BASE_TYPE_MAPS = {
Expand Down

0 comments on commit 667d3c8

Please # to comment.