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

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

Issue 10545043: Extensions docs server: Design changes, partial template support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 import json
7 import os
8 import unittest
9
10 from local_fetcher import LocalFetcher
11 from template_data_source import TemplateDataSource
12 from third_party.handlebar import Handlebar
13
14 def _ReadFile(filename):
15 with open(filename, 'r') as f:
16 return f.read()
17
18 class TemplateDataSourceTest(unittest.TestCase):
19 def _RenderTest(self, name, base_path, data_source):
20 template_name = name + '_tmpl.html'
21 template = Handlebar(_ReadFile(os.path.join(base_path, template_name)))
22 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.
23 data_source.Render(template_name, _ReadFile(
24 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.
25
26 def testSimple(self):
27 path = os.path.join('test_data', 'template_data_source', 'simple')
28 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
29 t_data_source = TemplateDataSource(fetcher, ['./'], 0)
30
31 template_a1 = Handlebar(_ReadFile(os.path.join(path, 'test1.html')))
32 self.assertEqual(template_a1.render({}, {'templates': {}}).text,
33 t_data_source['test1'].render({}, {'templates': {}}).text)
34
35 template_a2 = Handlebar(_ReadFile(os.path.join(path, 'test2.html')))
36 self.assertEqual(template_a2.render({}, {'templates': {}}).text,
37 t_data_source['test2'].render({}, {'templates': {}}).text)
38
39 self.assertEqual(None, t_data_source['junk.html'])
40
41 def testPartials(self):
42 path = os.path.join('test_data', 'template_data_source', 'partials')
43 fetcher = LocalFetcher(path)
44 t_data_source = TemplateDataSource(fetcher, ['./'], 0)
45
46 self.assertEqual(_ReadFile(os.path.join(path, 'test.html')),
47 t_data_source['test_tmpl'].render(
48 json.loads(_ReadFile(os.path.join(path, 'input.json'))),
49 t_data_source).text)
50
51 def testRender(self):
52 path = os.path.join('test_data', 'template_data_source', 'render')
53 fetcher = LocalFetcher(path)
54 t_data_source = TemplateDataSource(fetcher, ['./'], 0)
55 self._RenderTest('test1', path, t_data_source)
56 self._RenderTest('test2', path, t_data_source)
57
58
59
60 if __name__ == '__main__':
61 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698