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

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

Issue 213673002: Add support for "documented_in" annotation in json api schema (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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 file_system import FileNotFoundError 11 from file_system import FileNotFoundError
12 from future import Future
12 from reference_resolver import ReferenceResolver 13 from reference_resolver import ReferenceResolver
13 from test_object_store import TestObjectStore 14 from test_object_store import TestObjectStore
14 from test_util import Server2Path 15 from test_util import Server2Path
15 16
16 17
17 class FakeAPIDataSource(object): 18 class FakeAPIDataSource(object):
18 def __init__(self, json_data): 19 def __init__(self, json_data):
19 self._json = json_data 20 self._json = json_data
20 21
21 def get(self, key, disable_refs=False): 22 def get(self, key, disable_refs=False):
22 assert disable_refs, 'ReferenceResolve should be disabling refs' 23 assert disable_refs, 'ReferenceResolve should be disabling refs'
23 if key not in self._json: 24 if key not in self._json:
24 raise FileNotFoundError(key) 25 raise FileNotFoundError(key)
25 return self._json[key] 26 return self._json[key]
26 27
27 28
29 class FakeNamespace(object):
30 def __init__(self):
31 self.documentation_options = {}
32
33
28 class FakeAPIModels(object): 34 class FakeAPIModels(object):
29 def __init__(self, names): 35 def __init__(self, names):
30 self._names = names 36 self._names = names
31 37
32 def GetNames(self): 38 def GetNames(self):
33 return self._names 39 return self._names
34 40
41 def GetModel(self, name):
42 return Future(value=FakeNamespace())
ahernandez 2014/03/26 22:03:32 Same as above.
not at google - send to devlin 2014/03/26 22:11:11 could you prefix them (and the existing classes I
43
35 44
36 class APIDataSourceTest(unittest.TestCase): 45 class APIDataSourceTest(unittest.TestCase):
not at google - send to devlin 2014/03/26 22:11:11 wow. this should be called ReferenceResolverTest..
ahernandez 2014/03/26 22:15:38 I didn't even notice... we can pretend it's always
37 def setUp(self): 46 def setUp(self):
38 self._base_path = Server2Path('test_data', 'test_json') 47 self._base_path = Server2Path('test_data', 'test_json')
39 48
40 def _ReadLocalFile(self, filename): 49 def _ReadLocalFile(self, filename):
41 with open(os.path.join(self._base_path, filename), 'r') as f: 50 with open(os.path.join(self._base_path, filename), 'r') as f:
42 return f.read() 51 return f.read()
43 52
44 def testGetLink(self): 53 def testGetLink(self):
45 test_data = json.loads(self._ReadLocalFile('fake_data_source.json')) 54 test_data = json.loads(self._ReadLocalFile('fake_data_source.json'))
46 resolver = ReferenceResolver(FakeAPIDataSource(test_data), 55 resolver = ReferenceResolver(FakeAPIDataSource(test_data),
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 'Hi <a href="../bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, ' 217 'Hi <a href="../bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>, '
209 '<a href="../bar.bon.html#property-bar_bon_p3">Bon Bon</a>, ' 218 '<a href="../bar.bon.html#property-bar_bon_p3">Bon Bon</a>, '
210 '<a href="../bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>', 219 '<a href="../bar.bon.html#property-bar_bon_p3">bar_bon_p3</a>',
211 resolver.ResolveAllLinks( 220 resolver.ResolveAllLinks(
212 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3', 221 'Hi $ref:bar_bon_p3, $ref:[bar_bon_p3 Bon Bon], $ref:bar_bon_p3',
213 relative_to='foo/baz/bar.html', 222 relative_to='foo/baz/bar.html',
214 namespace='bar.bon')) 223 namespace='bar.bon'))
215 224
216 if __name__ == '__main__': 225 if __name__ == '__main__':
217 unittest.main() 226 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698