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

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

Issue 10835012: Extension Docs Server: Include a list of samples used in the api reference page. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: api_data_source is a factory Created 8 years, 5 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 unittest 8 import unittest
9 9
10 from handlebar_dict_generator import HandlebarDictGenerator 10 from handlebar_dict_generator import HandlebarDictGenerator
11 from handlebar_dict_generator import _GetLinkToRefType 11 from handlebar_dict_generator import _GetLinkToRefType
12 from handlebar_dict_generator import _FormatValue 12 from handlebar_dict_generator import _FormatValue
13 import third_party.json_schema_compiler.json_comment_eater as comment_eater 13 import third_party.json_schema_compiler.json_comment_eater as comment_eater
14 import third_party.json_schema_compiler.model as model 14 import third_party.json_schema_compiler.model as model
15 15
16 class DictGeneratorTest(unittest.TestCase): 16 class DictGeneratorTest(unittest.TestCase):
17 def setUp(self): 17 def setUp(self):
18 self._base_path = os.path.join('test_data', 'test_json') 18 self._base_path = os.path.join('test_data', 'test_json')
19 19
20 def _ReadLocalFile(self, filename): 20 def _ReadLocalFile(self, filename):
21 with open(os.path.join(self._base_path, filename), 'r') as f: 21 with open(os.path.join(self._base_path, filename), 'r') as f:
22 return f.read() 22 return f.read()
23 23
24 def _GenerateTest(self, filename): 24 def _GenerateTest(self, filename):
25 expected_json = json.loads(self._ReadLocalFile('expected_' + filename)) 25 expected_json = json.loads(self._ReadLocalFile('expected_' + filename))
26 gen = HandlebarDictGenerator( 26 gen = HandlebarDictGenerator(
27 json.loads(comment_eater.Nom(self._ReadLocalFile(filename)))[0]) 27 json.loads(comment_eater.Nom(self._ReadLocalFile(filename)))[0], [])
28 print json.dumps(gen.Generate(), indent=2)
cduvall 2012/07/26 22:38:25 remove please :)
chebert 2012/07/26 23:28:36 Done.
28 self.assertEquals(expected_json, gen.Generate()) 29 self.assertEquals(expected_json, gen.Generate())
29 30
30 def testGenerate(self): 31 def testGenerate(self):
31 self._GenerateTest('test_file.json') 32 self._GenerateTest('test_file.json')
32 33
33 def testGetLinkToRefType(self): 34 def testGetLinkToRefType(self):
34 link = _GetLinkToRefType('truthTeller', 'liar.Tab') 35 link = _GetLinkToRefType('truthTeller', 'liar.Tab')
35 self.assertEquals(link['href'], 'liar.html#type-Tab') 36 self.assertEquals(link['href'], 'liar.html#type-Tab')
36 self.assertEquals(link['text'], 'Tab') 37 self.assertEquals(link['text'], 'Tab')
37 link = _GetLinkToRefType('truthTeller', 'Tab') 38 link = _GetLinkToRefType('truthTeller', 'Tab')
38 self.assertEquals(link['href'], 'truthTeller.html#type-Tab') 39 self.assertEquals(link['href'], 'truthTeller.html#type-Tab')
39 self.assertEquals(link['text'], 'Tab') 40 self.assertEquals(link['text'], 'Tab')
40 link = _GetLinkToRefType('nay', 'lies.chrome.bookmarks.Tab') 41 link = _GetLinkToRefType('nay', 'lies.chrome.bookmarks.Tab')
41 self.assertEquals(link['href'], 'lies.html#type-chrome.bookmarks.Tab') 42 self.assertEquals(link['href'], 'lies.html#type-chrome.bookmarks.Tab')
42 self.assertEquals(link['text'], 'chrome.bookmarks.Tab') 43 self.assertEquals(link['text'], 'chrome.bookmarks.Tab')
43 44
44 def testFormatValue(self): 45 def testFormatValue(self):
45 self.assertEquals('1,234,567', _FormatValue(1234567)) 46 self.assertEquals('1,234,567', _FormatValue(1234567))
46 self.assertEquals('67', _FormatValue(67)) 47 self.assertEquals('67', _FormatValue(67))
47 self.assertEquals('234,567', _FormatValue(234567)) 48 self.assertEquals('234,567', _FormatValue(234567))
48 49
49 if __name__ == '__main__': 50 if __name__ == '__main__':
50 unittest.main() 51 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698