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

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

Issue 10500004: Die build.py, Die: Part 2 (LocalFetcher, Handlebar support, build script) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Local is now a branch 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
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 os
7 import unittest
8 import test_urlfetch
9
10 from local_fetcher import LocalFetcher
11 from template_fetcher import TemplateFetcher
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 TestFetcher(LocalFetcher):
19 def FetchResource(self, branch, path):
20 result = self._Resource()
21 result.content = _ReadFile(os.path.join(self.base_path, branch, path))
22 return result
23
24 class TemplateFetcherTest(unittest.TestCase):
25 def testFetcher(self):
26 path = os.path.join('test_data', 'template_fetcher')
27 fetcher = TestFetcher(path)
28 t_fetcher = TemplateFetcher(fetcher)
29 t_fetcher.FetchTemplate('a', 'test1.tmpl')
30 t_fetcher.FetchTemplate('a', 'test2.tmpl')
31 t_fetcher.FetchTemplate('b', 'test1.tmpl')
not at google - send to devlin 2012/06/04 23:52:26 Two little things here: I thought we were doing .h
32
33 self.assertEqual(2, len(t_fetcher.AsDict('a')))
34 self.assertEqual(1, len(t_fetcher.AsDict('b')))
35 self.assertEqual(0, len(t_fetcher.AsDict('c')))
36
37 template_a1 = Handlebar(_ReadFile(os.path.join(path, 'a', 'test1.tmpl')))
38 self.assertEqual(template_a1.render('{}', {'templates': {}}).text,
39 t_fetcher['a', 'test1.tmpl'].render('{}', {'templates': {}}).text)
40
41 template_a2 = Handlebar(_ReadFile(os.path.join(path, 'a', 'test2.tmpl')))
42 self.assertEqual(template_a2.render('{}', {'templates': {}}).text,
43 t_fetcher['a', 'test2.tmpl'].render('{}', {'templates': {}}).text)
44
45 template_b1 = Handlebar(_ReadFile(os.path.join(path, 'b', 'test1.tmpl')))
46 self.assertEqual(template_b1.render('{}', {'templates': {}}).text,
47 t_fetcher['b', 'test1.tmpl'].render('{}', {'templates': {}}).text)
48
49 if __name__ == '__main__':
50 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698