| 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 docs_server_utils import GetLinkToRefType | 16 from docs_server_utils import GetLinkToRefType |
| 17 from file_system import FileNotFoundError | 17 from file_system import FileNotFoundError |
| 18 from in_memory_object_store import InMemoryObjectStore | 18 from in_memory_object_store import InMemoryObjectStore |
| 19 from local_file_system import LocalFileSystem | 19 from local_file_system import LocalFileSystem |
| 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 26 matching lines...) Expand all Loading... |
| 57 self.assertEqual(expected, test1) | 56 self.assertEqual(expected, test1) |
| 58 test2 = data_source['testFile'] | 57 test2 = data_source['testFile'] |
| 59 test2.pop('samples') | 58 test2.pop('samples') |
| 60 self.assertEqual(expected, test2) | 59 self.assertEqual(expected, test2) |
| 61 test3 = data_source['testFile.html'] | 60 test3 = data_source['testFile.html'] |
| 62 test3.pop('samples') | 61 test3.pop('samples') |
| 63 self.assertEqual(expected, test3) | 62 self.assertEqual(expected, test3) |
| 64 self.assertRaises(FileNotFoundError, data_source.get, 'junk') | 63 self.assertRaises(FileNotFoundError, data_source.get, 'junk') |
| 65 | 64 |
| 66 def _LoadJSON(self, filename): | 65 def _LoadJSON(self, filename): |
| 67 return json.loads(comment_eater.Nom(self._ReadLocalFile(filename)))[0] | 66 return json.loads(self._ReadLocalFile(filename))[0] |
| 68 | 67 |
| 69 def _ToDictTest(self, filename): | 68 def _ToDictTest(self, filename): |
| 70 expected_json = json.loads(self._ReadLocalFile('expected_' + filename)) | 69 expected_json = json.loads(self._ReadLocalFile('expected_' + filename)) |
| 71 gen = _JscModel(self._LoadJSON(filename)) | 70 gen = _JscModel(self._LoadJSON(filename)) |
| 72 self.assertEquals(expected_json, gen.ToDict()) | 71 self.assertEquals(expected_json, gen.ToDict()) |
| 73 | 72 |
| 74 def testCreateId(self): | 73 def testCreateId(self): |
| 75 dict_ = _JscModel(self._LoadJSON('test_file.json')).ToDict() | 74 dict_ = _JscModel(self._LoadJSON('test_file.json')).ToDict() |
| 76 self.assertEquals('type-TypeA', dict_['types'][0]['id']) | 75 self.assertEquals('type-TypeA', dict_['types'][0]['id']) |
| 77 self.assertEquals('property-TypeA-b', | 76 self.assertEquals('property-TypeA-b', |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 _MakeLink('#type-type2', 'type2')), | 110 _MakeLink('#type-type2', 'type2')), |
| 112 _GetType(dict_, 'type3')['description']) | 111 _GetType(dict_, 'type3')['description']) |
| 113 | 112 |
| 114 def testRemoveNoDocs(self): | 113 def testRemoveNoDocs(self): |
| 115 d = json.loads(self._ReadLocalFile('nodoc_test.json')) | 114 d = json.loads(self._ReadLocalFile('nodoc_test.json')) |
| 116 _RemoveNoDocs(d) | 115 _RemoveNoDocs(d) |
| 117 self.assertEqual(json.loads(self._ReadLocalFile('expected_nodoc.json')), d) | 116 self.assertEqual(json.loads(self._ReadLocalFile('expected_nodoc.json')), d) |
| 118 | 117 |
| 119 if __name__ == '__main__': | 118 if __name__ == '__main__': |
| 120 unittest.main() | 119 unittest.main() |
| OLD | NEW |