Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: tools/json_schema_compiler/idl_schema_test.py

Issue 23549025: Clean up JSON Schema Compiler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed enum test and added blank lines. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/json_schema_compiler/idl_schema.py ('k') | tools/json_schema_compiler/json_parse.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import idl_schema 6 import idl_schema
7 import unittest 7 import unittest
8 8
9 def getFunction(schema, name): 9 def getFunction(schema, name):
10 for item in schema['functions']: 10 for item in schema['functions']:
11 if item['name'] == name: 11 if item['name'] == name:
12 return item 12 return item
13 raise KeyError('Missing function %s' % name) 13 raise KeyError('Missing function %s' % name)
14 14
15
15 def getParams(schema, name): 16 def getParams(schema, name):
16 function = getFunction(schema, name) 17 function = getFunction(schema, name)
17 return function['parameters'] 18 return function['parameters']
18 19
20
19 def getType(schema, id): 21 def getType(schema, id):
20 for item in schema['types']: 22 for item in schema['types']:
21 if item['id'] == id: 23 if item['id'] == id:
22 return item 24 return item
23 25
26
24 class IdlSchemaTest(unittest.TestCase): 27 class IdlSchemaTest(unittest.TestCase):
25 def setUp(self): 28 def setUp(self):
26 loaded = idl_schema.Load('test/idl_basics.idl') 29 loaded = idl_schema.Load('test/idl_basics.idl')
27 self.assertEquals(1, len(loaded)) 30 self.assertEquals(1, len(loaded))
28 self.assertEquals('idl_basics', loaded[0]['namespace']) 31 self.assertEquals('idl_basics', loaded[0]['namespace'])
29 self.idl_basics = loaded[0] 32 self.idl_basics = loaded[0]
30 33
31 def testSimpleCallbacks(self): 34 def testSimpleCallbacks(self):
32 schema = self.idl_basics 35 schema = self.idl_basics
33 expected = [{'type':'function', 'name':'cb', 'parameters':[]}] 36 expected = [{'type':'function', 'name':'cb', 'parameters':[]}]
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 141
139 def testReservedWords(self): 142 def testReservedWords(self):
140 schema = idl_schema.Load('test/idl_reserved_words.idl')[0] 143 schema = idl_schema.Load('test/idl_reserved_words.idl')[0]
141 144
142 foo_type = getType(schema, 'Foo') 145 foo_type = getType(schema, 'Foo')
143 self.assertEquals(['float', 'DOMString'], foo_type['enum']) 146 self.assertEquals(['float', 'DOMString'], foo_type['enum'])
144 147
145 enum_type = getType(schema, 'enum') 148 enum_type = getType(schema, 'enum')
146 self.assertEquals(['callback', 'namespace'], enum_type['enum']) 149 self.assertEquals(['callback', 'namespace'], enum_type['enum'])
147 150
148 dictionary = getType(schema, 'dictionary'); 151 dictionary = getType(schema, 'dictionary')
149 self.assertEquals('integer', dictionary['properties']['long']['type']) 152 self.assertEquals('integer', dictionary['properties']['long']['type'])
150 153
151 mytype = getType(schema, 'MyType') 154 mytype = getType(schema, 'MyType')
152 self.assertEquals('string', mytype['properties']['interface']['type']) 155 self.assertEquals('string', mytype['properties']['interface']['type'])
153 156
154 params = getParams(schema, 'static') 157 params = getParams(schema, 'static')
155 self.assertEquals('Foo', params[0]['$ref']) 158 self.assertEquals('Foo', params[0]['$ref'])
156 self.assertEquals('enum', params[1]['$ref']) 159 self.assertEquals('enum', params[1]['$ref'])
157 160
161
158 if __name__ == '__main__': 162 if __name__ == '__main__':
159 unittest.main() 163 unittest.main()
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/idl_schema.py ('k') | tools/json_schema_compiler/json_parse.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698