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

Side by Side Diff: chrome/common/extensions/docs/server2/api_data_source_test.py

Issue 14322003: Inline docs render properly in extensions doc server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merged with master Created 7 years, 8 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
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 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 local_file_system import LocalFileSystem 17 from local_file_system import LocalFileSystem
18 from object_store_creator import ObjectStoreCreator 18 from object_store_creator import ObjectStoreCreator
19 from reference_resolver import ReferenceResolver 19 from reference_resolver import ReferenceResolver
20 import third_party.json_schema_compiler.idl_schema as idl_schema
21 import third_party.json_schema_compiler.idl_parser as idl_parser
20 import third_party.json_schema_compiler.model as model 22 import third_party.json_schema_compiler.model as model
21 23
22 def _MakeLink(href, text): 24 def _MakeLink(href, text):
23 return '<a href="%s">%s</a>' % (href, text) 25 return '<a href="%s">%s</a>' % (href, text)
24 26
25 def _GetType(dict_, name): 27 def _GetType(dict_, name):
26 for type_ in dict_['types']: 28 for type_ in dict_['types']:
27 if type_['name'] == name: 29 if type_['name'] == name:
28 return type_ 30 return type_
29 31
(...skipping 11 matching lines...) Expand all
41 def get(self, key): 43 def get(self, key):
42 if key not in self._json: 44 if key not in self._json:
43 raise FileNotFoundError(key) 45 raise FileNotFoundError(key)
44 return self._json[key] 46 return self._json[key]
45 47
46 def GetAllNames(self): 48 def GetAllNames(self):
47 return self._json.keys() 49 return self._json.keys()
48 50
49 class APIDataSourceTest(unittest.TestCase): 51 class APIDataSourceTest(unittest.TestCase):
50 def setUp(self): 52 def setUp(self):
51 self._base_path = os.path.join(sys.path[0], 'test_data', 'test_json') 53 self._base_path = os.path.join(sys.path[0], 'test_data')
52 54
53 def _ReadLocalFile(self, filename): 55 def _ReadLocalFile(self, filename, test_dir='test_json'):
54 with open(os.path.join(self._base_path, filename), 'r') as f: 56 with open(os.path.join(self._base_path, test_dir, filename), 'r') as f:
55 return f.read() 57 return f.read()
56 58
57 def _CreateRefResolver(self, filename): 59 def _CreateRefResolver(self, filename):
58 data_source = FakeAPIAndListDataSource( 60 data_source = FakeAPIAndListDataSource(
59 self._LoadJSON(filename)) 61 self._LoadJSON(filename))
60 return ReferenceResolver.Factory(data_source, 62 return ReferenceResolver.Factory(data_source,
61 data_source, 63 data_source,
62 ObjectStoreCreator.Factory()).Create() 64 ObjectStoreCreator.Factory()).Create()
63 65
64 def _LoadJSON(self, filename): 66 def _LoadJSON(self, filename):
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 self.assertEquals( 107 self.assertEquals(
106 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'), 108 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'),
107 _MakeLink('ref_test.html#type-type2', 'type2')), 109 _MakeLink('ref_test.html#type-type2', 'type2')),
108 _GetType(dict_, 'type3')['description']) 110 _GetType(dict_, 'type3')['description'])
109 111
110 def testRemoveNoDocs(self): 112 def testRemoveNoDocs(self):
111 d = self._LoadJSON('nodoc_test.json') 113 d = self._LoadJSON('nodoc_test.json')
112 _RemoveNoDocs(d) 114 _RemoveNoDocs(d)
113 self.assertEqual(self._LoadJSON('expected_nodoc.json'), d) 115 self.assertEqual(self._LoadJSON('expected_nodoc.json'), d)
114 116
117 def testInlineDocs(self):
118 raw_idl = self._ReadLocalFile('inline.idl', test_dir='test_idl')
119 idl = idl_parser.IDLParser().ParseData(raw_idl)
120
121 jsc = _JSCModel(
122 idl_schema.IDLSchema(idl).process()[0],
123 None, True).ToDict()
124
125 try:
126 # Make sure that inlining worked by attempting to access the inner objects
127 # inline
cduvall 2013/04/24 00:09:54 put a '.' at the end of all comments.
jshumway 2013/04/24 00:32:41 Usually do, must have been a typo.
128 self.assertNotEqual(
129 jsc['functions'][0]['parameters'][0].get('enum_values'),
130 None)
131
132 self.assertNotEqual(jsc['functions'][2]['parameters'][0].get(
133 'properties')[3].get('enum_values'),
134 None)
135 except KeyError:
136 self.assertEqual(True, False);
137
138
115 if __name__ == '__main__': 139 if __name__ == '__main__':
116 unittest.main() 140 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698