OLD | NEW |
---|---|
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 copy | |
6 import json | 7 import json |
7 import os | 8 import os |
8 import sys | 9 import sys |
9 import unittest | 10 import unittest |
10 | 11 |
11 from api_data_source import (APIDataSource, | 12 from api_data_source import (APIDataSource, |
12 _JSCModel, | 13 _JSCModel, |
13 _FormatValue, | 14 _FormatValue, |
14 _RemoveNoDocs) | 15 _RemoveNoDocs, |
16 _InlineDocs) | |
15 from compiled_file_system import CompiledFileSystem | 17 from compiled_file_system import CompiledFileSystem |
16 from file_system import FileNotFoundError | 18 from file_system import FileNotFoundError |
17 from local_file_system import LocalFileSystem | 19 from local_file_system import LocalFileSystem |
18 from object_store_creator import ObjectStoreCreator | 20 from object_store_creator import ObjectStoreCreator |
19 from reference_resolver import ReferenceResolver | 21 from reference_resolver import ReferenceResolver |
20 import third_party.json_schema_compiler.model as model | |
21 | 22 |
22 def _MakeLink(href, text): | 23 def _MakeLink(href, text): |
23 return '<a href="%s">%s</a>' % (href, text) | 24 return '<a href="%s">%s</a>' % (href, text) |
24 | 25 |
25 def _GetType(dict_, name): | 26 def _GetType(dict_, name): |
26 for type_ in dict_['types']: | 27 for type_ in dict_['types']: |
27 if type_['name'] == name: | 28 if type_['name'] == name: |
28 return type_ | 29 return type_ |
29 | 30 |
30 class FakeSamplesDataSource(object): | 31 class FakeSamplesDataSource(object): |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 self.assertEquals( | 106 self.assertEquals( |
106 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'), | 107 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'), |
107 _MakeLink('ref_test.html#type-type2', 'type2')), | 108 _MakeLink('ref_test.html#type-type2', 'type2')), |
108 _GetType(dict_, 'type3')['description']) | 109 _GetType(dict_, 'type3')['description']) |
109 | 110 |
110 def testRemoveNoDocs(self): | 111 def testRemoveNoDocs(self): |
111 d = self._LoadJSON('nodoc_test.json') | 112 d = self._LoadJSON('nodoc_test.json') |
112 _RemoveNoDocs(d) | 113 _RemoveNoDocs(d) |
113 self.assertEqual(self._LoadJSON('expected_nodoc.json'), d) | 114 self.assertEqual(self._LoadJSON('expected_nodoc.json'), d) |
114 | 115 |
116 def testInlineDocs(self): | |
117 schema = { | |
118 "namespace": "storage", | |
119 "properties": { | |
120 "key2": { | |
121 "description": "second key", | |
122 "$ref": "Key" | |
123 }, | |
124 "key1": { | |
125 "description": "first key", | |
126 "$ref": "Key" | |
127 } | |
128 }, | |
129 "types": [ | |
130 { | |
131 "inline_doc": True, | |
132 "type": "string", | |
133 "id": "Key", # Should be inlined into both properties and be removed | |
134 # from types. | |
135 "description": "This is a key.", # This description should disappear. | |
136 "marker": True # This should appear three times in the output. | |
137 }, | |
138 { | |
139 "items": { | |
140 "$ref": "Key" | |
141 }, | |
142 "type": "array", | |
143 "id": "KeyList", | |
144 "description": "A list of keys" | |
145 } | |
146 ] | |
147 } | |
148 | |
149 inlined_correct = { | |
not at google - send to devlin
2013/04/25 02:22:09
usual terminology in tests is "expected"
| |
150 "namespace": "storage", | |
151 "properties": { | |
152 "key2": { | |
153 "marker": True, | |
154 "type": "string", | |
155 "description": "second key" | |
156 }, | |
157 "key1": { | |
158 "marker": True, | |
159 "type": "string", | |
160 "description": "first key" | |
161 } | |
162 }, | |
163 "types": [ | |
164 { | |
165 "items": { | |
166 "marker": True, | |
167 "type": "string" | |
168 }, | |
169 "type": "array", | |
170 "id": "KeyList", | |
171 "description": "A list of keys" | |
172 } | |
173 ] | |
174 } | |
175 | |
176 inlined_docs = copy.deepcopy(schema) | |
177 _InlineDocs(inlined_docs) | |
178 self.assertEqual(inlined_docs, inlined_correct) | |
not at google - send to devlin
2013/04/25 02:22:09
and idiom is to put the expected value first in th
| |
179 | |
180 | |
115 if __name__ == '__main__': | 181 if __name__ == '__main__': |
116 unittest.main() | 182 unittest.main() |
OLD | NEW |