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..e5eb7b5a5118039f88ac82c22acaf0c76d6923dd |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/template_data_source_test.py |
| @@ -0,0 +1,61 @@ |
| +#!/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 |
| + |
| +def _ReadFile(filename): |
| + with open(filename, 'r') as f: |
| + return f.read() |
| + |
| +class TemplateDataSourceTest(unittest.TestCase): |
| + def _RenderTest(self, name, base_path, data_source): |
| + template_name = name + '_tmpl.html' |
| + template = Handlebar(_ReadFile(os.path.join(base_path, template_name))) |
| + self.assertEquals(_ReadFile(os.path.join(base_path, name + '.html')), |
|
not at google - send to devlin
2012/06/08 01:42:53
I think that these reference files should be calle
cduvall
2012/06/08 02:18:06
Done.
|
| + data_source.Render(template_name, _ReadFile( |
| + os.path.join(base_path, name + '.json')))) |
|
not at google - send to devlin
2012/06/08 01:42:53
nit: vertical align (I think this will become easi
cduvall
2012/06/08 02:18:06
Done.
|
| + |
| + def testSimple(self): |
| + path = os.path.join('test_data', 'template_data_source', 'simple') |
| + fetcher = LocalFetcher(path) |
|
not at google - send to devlin
2012/06/08 01:42:53
Do python unit tests have a SetUp-type thing? I t
cduvall
2012/06/08 02:18:06
Good idea. It helped with base_path, but LocalFetc
|
| + t_data_source = TemplateDataSource(fetcher, ['./'], 0) |
| + |
| + template_a1 = Handlebar(_ReadFile(os.path.join(path, 'test1.html'))) |
| + self.assertEqual(template_a1.render({}, {'templates': {}}).text, |
| + t_data_source['test1'].render({}, {'templates': {}}).text) |
| + |
| + template_a2 = Handlebar(_ReadFile(os.path.join(path, '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): |
| + path = os.path.join('test_data', 'template_data_source', 'partials') |
| + fetcher = LocalFetcher(path) |
| + t_data_source = TemplateDataSource(fetcher, ['./'], 0) |
| + |
| + self.assertEqual(_ReadFile(os.path.join(path, 'test.html')), |
| + t_data_source['test_tmpl'].render( |
| + json.loads(_ReadFile(os.path.join(path, 'input.json'))), |
| + t_data_source).text) |
| + |
| + def testRender(self): |
| + path = os.path.join('test_data', 'template_data_source', 'render') |
| + fetcher = LocalFetcher(path) |
| + t_data_source = TemplateDataSource(fetcher, ['./'], 0) |
| + self._RenderTest('test1', path, t_data_source) |
| + self._RenderTest('test2', path, t_data_source) |
| + |
| + |
| + |
| +if __name__ == '__main__': |
| + unittest.main() |