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

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

Issue 11079010: Extensions Docs Server: Preserve JSON declaration order in extensions documentation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use OrderedDict for JSON parsing Created 8 years, 2 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 | Annotate | Revision Log
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, _JscModel, _FormatValue 11 from api_data_source import APIDataSource, _JscModel, _FormatValue
12 from compiled_file_system import CompiledFileSystem 12 from compiled_file_system import CompiledFileSystem
13 from docs_server_utils import GetLinkToRefType 13 from docs_server_utils import GetLinkToRefType
14 from file_system import FileNotFoundError 14 from file_system import FileNotFoundError
15 from in_memory_object_store import InMemoryObjectStore 15 from in_memory_object_store import InMemoryObjectStore
16 from local_file_system import LocalFileSystem 16 from local_file_system import LocalFileSystem
17 import third_party.json_schema_compiler.json_comment_eater as comment_eater
18 import third_party.json_schema_compiler.model as model 17 import third_party.json_schema_compiler.model as model
19 18
20 def _MakeLink(href, text): 19 def _MakeLink(href, text):
21 return '<a href="%s">%s</a>' % (href, text) 20 return '<a href="%s">%s</a>' % (href, text)
22 21
23 def _GetType(dict_, name): 22 def _GetType(dict_, name):
24 for type_ in dict_['types']: 23 for type_ in dict_['types']:
25 if type_['name'] == name: 24 if type_['name'] == name:
26 return type_ 25 return type_
27 26
(...skipping 26 matching lines...) Expand all
54 self.assertEqual(expected, test1) 53 self.assertEqual(expected, test1)
55 test2 = data_source['testFile'] 54 test2 = data_source['testFile']
56 test2.pop('samples') 55 test2.pop('samples')
57 self.assertEqual(expected, test2) 56 self.assertEqual(expected, test2)
58 test3 = data_source['testFile.html'] 57 test3 = data_source['testFile.html']
59 test3.pop('samples') 58 test3.pop('samples')
60 self.assertEqual(expected, test3) 59 self.assertEqual(expected, test3)
61 self.assertRaises(FileNotFoundError, data_source.get, 'junk') 60 self.assertRaises(FileNotFoundError, data_source.get, 'junk')
62 61
63 def _LoadJSON(self, filename): 62 def _LoadJSON(self, filename):
64 return json.loads(comment_eater.Nom(self._ReadLocalFile(filename)))[0] 63 return json.loads(self._ReadLocalFile(filename))[0]
65 64
66 def _ToDictTest(self, filename): 65 def _ToDictTest(self, filename):
67 expected_json = json.loads(self._ReadLocalFile('expected_' + filename)) 66 expected_json = json.loads(self._ReadLocalFile('expected_' + filename))
68 gen = _JscModel(self._LoadJSON(filename)) 67 gen = _JscModel(self._LoadJSON(filename))
69 self.assertEquals(expected_json, gen.ToDict()) 68 self.assertEquals(expected_json, gen.ToDict())
70 69
71 def testCreateId(self): 70 def testCreateId(self):
72 dict_ = _JscModel(self._LoadJSON('test_file.json')).ToDict() 71 dict_ = _JscModel(self._LoadJSON('test_file.json')).ToDict()
73 self.assertEquals('type-TypeA', dict_['types'][0]['id']) 72 self.assertEquals('type-TypeA', dict_['types'][0]['id'])
74 self.assertEquals('property-TypeA-b', 73 self.assertEquals('property-TypeA-b',
(...skipping 28 matching lines...) Expand all
103 'A %s, or %s' % (_MakeLink('#type-type3', 'type3'), 102 'A %s, or %s' % (_MakeLink('#type-type3', 'type3'),
104 _MakeLink('#type-type2', 'type2')), 103 _MakeLink('#type-type2', 'type2')),
105 _GetType(dict_, 'type2')['description']) 104 _GetType(dict_, 'type2')['description'])
106 self.assertEquals( 105 self.assertEquals(
107 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'), 106 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'),
108 _MakeLink('#type-type2', 'type2')), 107 _MakeLink('#type-type2', 'type2')),
109 _GetType(dict_, 'type3')['description']) 108 _GetType(dict_, 'type3')['description'])
110 109
111 if __name__ == '__main__': 110 if __name__ == '__main__':
112 unittest.main() 111 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698