| 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 sys | 8 import sys |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| 11 from extensions_paths import SERVER2 |
| 11 from server_instance import ServerInstance | 12 from server_instance import ServerInstance |
| 12 from template_data_source import TemplateDataSource | 13 from template_data_source import TemplateDataSource |
| 13 from test_util import DisableLogging, ReadFile | 14 from test_util import DisableLogging, ReadFile |
| 14 from third_party.handlebar import Handlebar | 15 from third_party.handlebar import Handlebar |
| 15 | 16 |
| 16 | 17 |
| 17 class TemplateDataSourceTest(unittest.TestCase): | 18 class TemplateDataSourceTest(unittest.TestCase): |
| 18 | 19 |
| 19 def setUp(self): | 20 def setUp(self): |
| 20 self._base_path = os.path.join(sys.path[0], | 21 self._base_path = os.path.join(sys.path[0], |
| 21 'test_data', | 22 'test_data', |
| 22 'template_data_source') | 23 'template_data_source') |
| 23 | 24 |
| 24 def _CreateTemplateDataSource(self, partial_dir): | 25 def _CreateTemplateDataSource(self, partial_dir): |
| 25 return TemplateDataSource( | 26 return TemplateDataSource( |
| 26 ServerInstance.ForLocal(), | 27 ServerInstance.ForLocal(), |
| 27 None, # Request | 28 None, # Request |
| 28 partial_dir='docs/server2/test_data/template_data_source/%s' % | 29 partial_dir='%s/test_data/template_data_source/%s' % |
| 29 partial_dir) | 30 (SERVER2, partial_dir)) |
| 30 | 31 |
| 31 def testSimple(self): | 32 def testSimple(self): |
| 32 template_data_source = self._CreateTemplateDataSource('simple') | 33 template_data_source = self._CreateTemplateDataSource('simple') |
| 33 template_a1 = Handlebar(ReadFile(self._base_path, 'simple', 'test1.html')) | 34 template_a1 = Handlebar(ReadFile(self._base_path, 'simple', 'test1.html')) |
| 34 context = [{}, {'templates': {}}] | 35 context = [{}, {'templates': {}}] |
| 35 self.assertEqual( | 36 self.assertEqual( |
| 36 template_a1.Render(*context).text, | 37 template_a1.Render(*context).text, |
| 37 template_data_source.get('test1').Render(*context).text) | 38 template_data_source.get('test1').Render(*context).text) |
| 38 template_a2 = Handlebar(ReadFile(self._base_path, 'simple', 'test2.html')) | 39 template_a2 = Handlebar(ReadFile(self._base_path, 'simple', 'test2.html')) |
| 39 self.assertEqual( | 40 self.assertEqual( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 template_data_source = self._CreateTemplateDataSource('partials') | 51 template_data_source = self._CreateTemplateDataSource('partials') |
| 51 context = json.loads(ReadFile(self._base_path, 'partials', 'input.json')) | 52 context = json.loads(ReadFile(self._base_path, 'partials', 'input.json')) |
| 52 self.assertEqual( | 53 self.assertEqual( |
| 53 ReadFile(self._base_path, 'partials', 'test_expected.html'), | 54 ReadFile(self._base_path, 'partials', 'test_expected.html'), |
| 54 template_data_source.get('test_tmpl').Render( | 55 template_data_source.get('test_tmpl').Render( |
| 55 context, template_data_source).text) | 56 context, template_data_source).text) |
| 56 | 57 |
| 57 | 58 |
| 58 if __name__ == '__main__': | 59 if __name__ == '__main__': |
| 59 unittest.main() | 60 unittest.main() |
| OLD | NEW |