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 unittest | 8 import unittest |
9 | 9 |
10 from docs_server_utils import GetLinkToRefType | 10 from docs_server_utils import GetLinkToRefType |
(...skipping 17 matching lines...) Expand all Loading... |
28 def _ReadLocalFile(self, filename): | 28 def _ReadLocalFile(self, filename): |
29 with open(os.path.join(self._base_path, filename), 'r') as f: | 29 with open(os.path.join(self._base_path, filename), 'r') as f: |
30 return f.read() | 30 return f.read() |
31 | 31 |
32 def _LoadJSON(self, filename): | 32 def _LoadJSON(self, filename): |
33 return json.loads(comment_eater.Nom(self._ReadLocalFile(filename)))[0] | 33 return json.loads(comment_eater.Nom(self._ReadLocalFile(filename)))[0] |
34 | 34 |
35 def _GenerateTest(self, filename): | 35 def _GenerateTest(self, filename): |
36 expected_json = json.loads(self._ReadLocalFile('expected_' + filename)) | 36 expected_json = json.loads(self._ReadLocalFile('expected_' + filename)) |
37 gen = HandlebarDictGenerator(self._LoadJSON(filename)) | 37 gen = HandlebarDictGenerator(self._LoadJSON(filename)) |
38 self.assertEquals(expected_json, gen.Generate([])) | 38 self.assertEquals(expected_json, gen.Generate()) |
39 | 39 |
40 def testGenerate(self): | 40 def testGenerate(self): |
41 self._GenerateTest('test_file.json') | 41 self._GenerateTest('test_file.json') |
42 | 42 |
43 def testGetLinkToRefType(self): | 43 def testGetLinkToRefType(self): |
44 link = GetLinkToRefType('truthTeller', 'liar.Tab') | 44 link = GetLinkToRefType('truthTeller', 'liar.Tab') |
45 self.assertEquals('liar.html#type-Tab', link['href']) | 45 self.assertEquals('liar.html#type-Tab', link['href']) |
46 self.assertEquals('liar.Tab', link['text']) | 46 self.assertEquals('liar.Tab', link['text']) |
47 link = GetLinkToRefType('truthTeller', 'Tab') | 47 link = GetLinkToRefType('truthTeller', 'Tab') |
48 self.assertEquals('#type-Tab', link['href']) | 48 self.assertEquals('#type-Tab', link['href']) |
49 self.assertEquals('Tab', link['text']) | 49 self.assertEquals('Tab', link['text']) |
50 link = GetLinkToRefType('nay', 'lies.chrome.bookmarks.Tab') | 50 link = GetLinkToRefType('nay', 'lies.chrome.bookmarks.Tab') |
51 self.assertEquals('lies.chrome.bookmarks.html#type-Tab', link['href']) | 51 self.assertEquals('lies.chrome.bookmarks.html#type-Tab', link['href']) |
52 self.assertEquals('lies.chrome.bookmarks.Tab', link['text']) | 52 self.assertEquals('lies.chrome.bookmarks.Tab', link['text']) |
53 | 53 |
54 def testFormatValue(self): | 54 def testFormatValue(self): |
55 self.assertEquals('1,234,567', _FormatValue(1234567)) | 55 self.assertEquals('1,234,567', _FormatValue(1234567)) |
56 self.assertEquals('67', _FormatValue(67)) | 56 self.assertEquals('67', _FormatValue(67)) |
57 self.assertEquals('234,567', _FormatValue(234567)) | 57 self.assertEquals('234,567', _FormatValue(234567)) |
58 | 58 |
59 def testFormatDescription(self): | 59 def testFormatDescription(self): |
60 dict_ = HandlebarDictGenerator(self._LoadJSON('ref_test.json')).Generate([]) | 60 dict_ = HandlebarDictGenerator(self._LoadJSON('ref_test.json')).Generate() |
61 self.assertEquals(_MakeLink('#type-type2', 'type2'), | 61 self.assertEquals(_MakeLink('#type-type2', 'type2'), |
62 _GetType(dict_, 'type1')['description']) | 62 _GetType(dict_, 'type1')['description']) |
63 self.assertEquals( | 63 self.assertEquals( |
64 'A %s, or %s' % (_MakeLink('#type-type3', 'type3'), | 64 'A %s, or %s' % (_MakeLink('#type-type3', 'type3'), |
65 _MakeLink('#type-type2', 'type2')), | 65 _MakeLink('#type-type2', 'type2')), |
66 _GetType(dict_, 'type2')['description']) | 66 _GetType(dict_, 'type2')['description']) |
67 self.assertEquals( | 67 self.assertEquals( |
68 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'), | 68 '%s != %s' % (_MakeLink('other.html#type-type2', 'other.type2'), |
69 _MakeLink('#type-type2', 'type2')), | 69 _MakeLink('#type-type2', 'type2')), |
70 _GetType(dict_, 'type3')['description']) | 70 _GetType(dict_, 'type3')['description']) |
71 | 71 |
72 if __name__ == '__main__': | 72 if __name__ == '__main__': |
73 unittest.main() | 73 unittest.main() |
OLD | NEW |