| 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 json | 6 import json |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| 11 from api_data_source import (APIDataSource, | 11 from api_data_source import (APIDataSource, |
| 12 _JSCModel, | 12 _JSCModel, |
| 13 _FormatValue, | 13 _FormatValue, |
| 14 _RemoveNoDocs) | 14 _RemoveNoDocs) |
| 15 from compiled_file_system import CompiledFileSystem | 15 from compiled_file_system import CompiledFileSystem |
| 16 from file_system import FileNotFoundError | 16 from file_system import FileNotFoundError |
| 17 from in_memory_object_store import InMemoryObjectStore | 17 from in_memory_object_store import InMemoryObjectStore |
| 18 from local_file_system import LocalFileSystem | 18 from local_file_system import LocalFileSystem |
| 19 from reference_resolver import ReferenceResolver | 19 from reference_resolver import ReferenceResolver |
| 20 import third_party.json_schema_compiler.json_comment_eater as comment_eater | |
| 21 import third_party.json_schema_compiler.model as model | 20 import third_party.json_schema_compiler.model as model |
| 22 | 21 |
| 23 def _MakeLink(href, text): | 22 def _MakeLink(href, text): |
| 24 return '<a href="%s">%s</a>' % (href, text) | 23 return '<a href="%s">%s</a>' % (href, text) |
| 25 | 24 |
| 26 def _GetType(dict_, name): | 25 def _GetType(dict_, name): |
| 27 for type_ in dict_['types']: | 26 for type_ in dict_['types']: |
| 28 if type_['name'] == name: | 27 if type_['name'] == name: |
| 29 return type_ | 28 return type_ |
| 30 | 29 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 self.assertEqual(expected, test1) | 78 self.assertEqual(expected, test1) |
| 80 test2 = data_source.get('testFile') | 79 test2 = data_source.get('testFile') |
| 81 test2.pop('samples') | 80 test2.pop('samples') |
| 82 self.assertEqual(expected, test2) | 81 self.assertEqual(expected, test2) |
| 83 test3 = data_source.get('testFile.html') | 82 test3 = data_source.get('testFile.html') |
| 84 test3.pop('samples') | 83 test3.pop('samples') |
| 85 self.assertEqual(expected, test3) | 84 self.assertEqual(expected, test3) |
| 86 self.assertRaises(FileNotFoundError, data_source.get, 'junk') | 85 self.assertRaises(FileNotFoundError, data_source.get, 'junk') |
| 87 | 86 |
| 88 def _LoadJSON(self, filename): | 87 def _LoadJSON(self, filename): |
| 89 return json.loads(comment_eater.Nom(self._ReadLocalFile(filename))) | 88 return json.loads(self._ReadLocalFile(filename)) |
| 90 | 89 |
| 91 def testCreateId(self): | 90 def testCreateId(self): |
| 92 data_source = FakeAPIAndListDataSource( | 91 data_source = FakeAPIAndListDataSource( |
| 93 self._LoadJSON('test_file_data_source.json')) | 92 self._LoadJSON('test_file_data_source.json')) |
| 94 dict_ = _JSCModel(self._LoadJSON('test_file.json')[0], | 93 dict_ = _JSCModel(self._LoadJSON('test_file.json')[0], |
| 95 self._CreateRefResolver('test_file_data_source.json'), | 94 self._CreateRefResolver('test_file_data_source.json'), |
| 96 False).ToDict() | 95 False).ToDict() |
| 97 self.assertEquals('type-TypeA', dict_['types'][0]['id']) | 96 self.assertEquals('type-TypeA', dict_['types'][0]['id']) |
| 98 self.assertEquals('property-TypeA-b', | 97 self.assertEquals('property-TypeA-b', |
| 99 dict_['types'][0]['properties'][0]['id']) | 98 dict_['types'][0]['properties'][0]['id']) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 130 _MakeLink('ref_test.html#type-type2', 'type2')), | 129 _MakeLink('ref_test.html#type-type2', 'type2')), |
| 131 _GetType(dict_, 'type3')['description']) | 130 _GetType(dict_, 'type3')['description']) |
| 132 | 131 |
| 133 def testRemoveNoDocs(self): | 132 def testRemoveNoDocs(self): |
| 134 d = self._LoadJSON('nodoc_test.json') | 133 d = self._LoadJSON('nodoc_test.json') |
| 135 _RemoveNoDocs(d) | 134 _RemoveNoDocs(d) |
| 136 self.assertEqual(self._LoadJSON('expected_nodoc.json'), d) | 135 self.assertEqual(self._LoadJSON('expected_nodoc.json'), d) |
| 137 | 136 |
| 138 if __name__ == '__main__': | 137 if __name__ == '__main__': |
| 139 unittest.main() | 138 unittest.main() |
| OLD | NEW |