OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 # Run build_server so that files needed by tests are copied to the local | 6 # Run build_server so that files needed by tests are copied to the local |
7 # third_party directory. | 7 # third_party directory. |
8 import build_server | 8 import build_server |
9 build_server.main() | 9 build_server.main() |
10 | 10 |
11 from handler import Handler | 11 from handler import Handler |
12 from local_renderer import LocalRenderer | 12 from local_renderer import LocalRenderer |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
15 import sys | 15 import sys |
16 import time | 16 import time |
17 import unittest | 17 import unittest |
18 | 18 |
19 # Arguments set up if __main__ specifies them. | 19 # Arguments set up if __main__ specifies them. |
20 _BASE_PATH = os.path.join( | 20 _BASE_PATH = os.path.join( |
21 os.path.abspath(os.path.dirname(__file__)), os.pardir, os.pardir) | 21 os.path.abspath(os.path.dirname(__file__)), os.pardir, os.pardir) |
22 _EXPLICIT_TEST_FILES = None | 22 _EXPLICIT_TEST_FILES = None |
23 | 23 |
24 def _GetPublicFiles(): | 24 def _GetPublicFiles(): |
25 '''Gets all public files mapped to their contents. | 25 '''Gets all public files mapped to their contents. |
26 ''' | 26 ''' |
27 public_path = os.path.join(_BASE_PATH, 'docs', 'templates', 'public', '') | 27 public_path = os.path.join(_BASE_PATH, 'docs', 'templates', 'public', '') |
28 public_files = {} | 28 public_files = {} |
29 for path, dirs, files in os.walk(public_path): | 29 for path, dirs, files in os.walk(public_path, topdown=True): |
| 30 dirs[:] = [d for d in dirs if d != '.svn'] |
30 relative_path = path[len(public_path):] | 31 relative_path = path[len(public_path):] |
31 for filename in files: | 32 for filename in files: |
32 with open(os.path.join(path, filename), 'r') as f: | 33 with open(os.path.join(path, filename), 'r') as f: |
33 public_files[os.path.join(relative_path, filename)] = f.read() | 34 public_files[os.path.join(relative_path, filename)] = f.read() |
34 return public_files | 35 return public_files |
35 | 36 |
36 class IntegrationTest(unittest.TestCase): | 37 class IntegrationTest(unittest.TestCase): |
37 def setUp(self): | 38 def setUp(self): |
38 self._renderer = LocalRenderer(_BASE_PATH) | 39 self._renderer = LocalRenderer(_BASE_PATH) |
39 | 40 |
(...skipping 13 matching lines...) Expand all Loading... |
53 finally: | 54 finally: |
54 print('Took %s seconds' % (time.time() - start_time)) | 55 print('Took %s seconds' % (time.time() - start_time)) |
55 | 56 |
56 public_files = _GetPublicFiles() | 57 public_files = _GetPublicFiles() |
57 | 58 |
58 print('Rendering %s public files...' % len(public_files.keys())) | 59 print('Rendering %s public files...' % len(public_files.keys())) |
59 start_time = time.time() | 60 start_time = time.time() |
60 try: | 61 try: |
61 for path, content in _GetPublicFiles().iteritems(): | 62 for path, content in _GetPublicFiles().iteritems(): |
62 def check_result(render_content, render_status, _): | 63 def check_result(render_content, render_status, _): |
63 self.assertEqual(200, render_status) | 64 self.assertEqual(200, render_status, |
| 65 'Got %s when rendering %s' % (render_status, path)) |
64 # This is reaaaaally rough since usually these will be tiny templates | 66 # This is reaaaaally rough since usually these will be tiny templates |
65 # that render large files. At least it'll catch zero-length responses. | 67 # that render large files. At least it'll catch zero-length responses. |
66 self.assertTrue(len(render_content) >= len(content)) | 68 self.assertTrue(len(render_content) >= len(content), |
| 69 'Content was "%s" when rendering %s' % (render_content, path)) |
67 check_result(*self._renderer.Render(path)) | 70 check_result(*self._renderer.Render(path)) |
68 # Samples are internationalized, test some locales. | 71 # Samples are internationalized, test some locales. |
69 if path.endswith('/samples.html'): | 72 if path.endswith('/samples.html'): |
70 for lang in ['en-US', 'es', 'ar']: | 73 for lang in ['en-US', 'es', 'ar']: |
71 check_result(*self._renderer.Render( | 74 check_result(*self._renderer.Render( |
72 path, headers={'Accept-Language': '%s;q=0.8' % lang})) | 75 path, headers={'Accept-Language': '%s;q=0.8' % lang})) |
73 finally: | 76 finally: |
74 print('Took %s seconds' % (time.time() - start_time)) | 77 print('Took %s seconds' % (time.time() - start_time)) |
75 | 78 |
76 def testExplicitFiles(self): | 79 def testExplicitFiles(self): |
(...skipping 23 matching lines...) Expand all Loading... |
100 parser.add_option('-p', '--path', default=None) | 103 parser.add_option('-p', '--path', default=None) |
101 parser.add_option('-a', '--all', action='store_true', default=False) | 104 parser.add_option('-a', '--all', action='store_true', default=False) |
102 (opts, args) = parser.parse_args() | 105 (opts, args) = parser.parse_args() |
103 if not opts.all: | 106 if not opts.all: |
104 _EXPLICIT_TEST_FILES = args | 107 _EXPLICIT_TEST_FILES = args |
105 if opts.path is not None: | 108 if opts.path is not None: |
106 _BASE_PATH = opts.path | 109 _BASE_PATH = opts.path |
107 # Kill sys.argv because we have our own flags. | 110 # Kill sys.argv because we have our own flags. |
108 sys.argv = [sys.argv[0]] | 111 sys.argv = [sys.argv[0]] |
109 unittest.main() | 112 unittest.main() |
OLD | NEW |