Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/template_data_source_test.py |
| diff --git a/chrome/common/extensions/docs/server2/template_data_source_test.py b/chrome/common/extensions/docs/server2/template_data_source_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..a96e4bd6ffcf6c84662326dfa654a13a2e35944d |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/template_data_source_test.py |
| @@ -0,0 +1,63 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import json |
| +import os |
| +import unittest |
| + |
| +from local_fetcher import LocalFetcher |
| +from template_data_source import TemplateDataSource |
| +from third_party.handlebar import Handlebar |
| + |
| +class TemplateDataSourceTest(unittest.TestCase): |
| + def setUp(self): |
| + self._base_path = os.path.join('test_data', 'template_data_source') |
| + |
| + def _ReadLocalFile(self, filename): |
| + with open(os.path.join(self._base_path, filename), 'r') as f: |
| + return f.read() |
| + |
| + def _RenderTest(self, name, data_source): |
| + template_name = name + '_tmpl.html' |
| + template = Handlebar(self._ReadLocalFile(template_name)) |
| + self.assertEquals(self._ReadLocalFile(name + '_expected.html'), |
| + data_source.Render(template_name, |
| + self._ReadLocalFile(name + '.json'))) |
|
not at google - send to devlin
2012/06/08 02:23:44
Btw, in general, if you think it's more readable t
|
| + |
| + def testSimple(self): |
| + self._base_path = os.path.join(self._base_path, 'simple') |
| + fetcher = LocalFetcher(self._base_path) |
| + t_data_source = TemplateDataSource(fetcher, ['./'], 0) |
| + |
| + template_a1 = Handlebar(self._ReadLocalFile('test1.html')) |
| + self.assertEqual(template_a1.render({}, {'templates': {}}).text, |
| + t_data_source['test1'].render({}, {'templates': {}}).text) |
| + |
| + template_a2 = Handlebar(self._ReadLocalFile('test2.html')) |
| + self.assertEqual(template_a2.render({}, {'templates': {}}).text, |
| + t_data_source['test2'].render({}, {'templates': {}}).text) |
| + |
| + self.assertEqual(None, t_data_source['junk.html']) |
| + |
| + def testPartials(self): |
| + self._base_path = os.path.join(self._base_path, 'partials') |
| + fetcher = LocalFetcher(self._base_path) |
| + t_data_source = TemplateDataSource(fetcher, ['./'], 0) |
| + |
| + self.assertEqual(self._ReadLocalFile('test.html'), |
| + t_data_source['test_tmpl'].render( |
| + json.loads(self._ReadLocalFile('input.json')), t_data_source).text) |
| + |
| + def testRender(self): |
| + self._base_path = os.path.join(self._base_path, 'render') |
| + fetcher = LocalFetcher(self._base_path) |
| + t_data_source = TemplateDataSource(fetcher, ['./'], 0) |
| + self._RenderTest('test1', t_data_source) |
| + self._RenderTest('test2', t_data_source) |
| + |
| + |
| + |
| +if __name__ == '__main__': |
| + unittest.main() |