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

Side by Side Diff: src/end_to_end_test.py

Issue 1662833005: Fixes Caterpillar crashing while generating report. (Closed) Base URL: https://github.com/chromium/caterpillar.git@master
Patch Set: Response to CR Created 4 years, 10 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
« no previous file with comments | « src/caterpillar.py ('k') | src/report/report.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python2 1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # Copyright 2016 Google Inc. All Rights Reserved. 4 # Copyright 2016 Google Inc. All Rights Reserved.
5 # 5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License. 7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at 8 # You may obtain a copy of the License at
9 # 9 #
10 # http://www.apache.org/licenses/LICENSE-2.0 10 # http://www.apache.org/licenses/LICENSE-2.0
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 process = subprocess.Popen( 61 process = subprocess.Popen(
62 [CATERPILLAR_PATH, 'config', '-i', self.config_path], 62 [CATERPILLAR_PATH, 'config', '-i', self.config_path],
63 stdin=subprocess.PIPE, 63 stdin=subprocess.PIPE,
64 stdout=subprocess.PIPE, 64 stdout=subprocess.PIPE,
65 stderr=subprocess.STDOUT) 65 stderr=subprocess.STDOUT)
66 process.communicate(input=config_input) 66 process.communicate(input=config_input)
67 process.wait() 67 process.wait()
68 68
69 if not os.path.exists(self.config_path): 69 if not os.path.exists(self.config_path):
70 raise RuntimeError('Configuration file generation failed.') 70 raise RuntimeError('Configuration file generation failed.')
71 if process.wait():
72 raise subprocess.CalledProcessError()
73
74 if not os.path.exists(self.config_path):
75 raise RuntimeError('Configuration file generation failed.')
71 76
72 process = subprocess.Popen( 77 output = subprocess.check_output(
73 [CATERPILLAR_PATH, 'convert', '-c', self.config_path, self.input_dir, 78 [CATERPILLAR_PATH, 'convert', '-c', self.config_path, self.input_dir,
74 self.output_dir], 79 self.output_dir])
75 stdin=subprocess.PIPE, 80
76 stdout=subprocess.PIPE, 81 def get_relative_filepaths(self, directory, ignore_folders=None):
77 stderr=subprocess.STDOUT) 82 """Returns all relative filepaths in a directory and children.
78 process.wait() 83
84 Args:
85 directory: Path to directory.
86 ignore_folders: List of folder names to ignore.
Matt Giuca 2016/02/04 06:36:34 directory / folder are interchangeable, so don't m
Matthew Alger 2016/02/04 22:47:06 Done.
87
88 Returns:
89 set of relative filepaths.
90 """
91 if not ignore_folders:
92 ignore_folders = []
93
94 filepaths = set()
95 for dirname, _, filenames in os.walk(directory):
96 skip = False
97 for folder in ignore_folders:
98 if folder in dirname:
Matt Giuca 2016/02/04 06:36:34 This is not precise enough. If ignore_folders = ['
Matthew Alger 2016/02/04 22:47:06 Oh, that's much cleaner. Done.
99 skip = True
100 break
101
102 if skip:
103 continue
104
105 for filename in filenames:
106 relpath = os.path.relpath(os.path.join(dirname, filename), directory)
107 filepaths.add(relpath)
108
109 return filepaths
79 110
80 def test_output_matches_reference(self): 111 def test_output_matches_reference(self):
81 """Tests that the output matches the reference output.""" 112 """Tests that the output matches the reference output."""
82 expected_files = set() 113 expected_files = self.get_relative_filepaths(TTS_REFERENCE_PATH,
83 for dirname, _, filenames in os.walk(TTS_REFERENCE_PATH): 114 ['bower_components'])
84 for filename in filenames: 115 actual_files = self.get_relative_filepaths(self.output_dir,
85 relpath = os.path.relpath( 116 ['bower_components'])
Matt Giuca 2016/02/04 06:36:34 {'bower_components'}
Matthew Alger 2016/02/04 22:47:06 Done.
86 os.path.join(dirname, filename), TTS_REFERENCE_PATH) 117 self.assertEqual(expected_files, actual_files)
87 expected_files.add(relpath)
88
89 for dirname, _, filenames in os.walk(self.output_dir):
90 for filename in filenames:
91 relpath = os.path.relpath(
92 os.path.join(dirname, filename), self.output_dir)
93 self.assertIn(relpath, expected_files)
94
95 expected_files = set()
96 for dirname, _, filenames in os.walk(self.output_dir):
97 for filename in filenames:
98 relpath = os.path.relpath(
99 os.path.join(dirname, filename), self.output_dir)
100 expected_files.add(relpath)
101
102 for dirname, _, filenames in os.walk(TTS_REFERENCE_PATH):
103 for filename in filenames:
104 relpath = os.path.relpath(
105 os.path.join(dirname, filename), TTS_REFERENCE_PATH)
106 self.assertIn(relpath, expected_files)
107 118
108 def test_all_correct_contents(self): 119 def test_all_correct_contents(self):
109 """Tests that the content of all non-static output files is expected.""" 120 """Tests that the content of all non-static output files is expected."""
110 for dirname, _, filenames in os.walk(TTS_REFERENCE_PATH): 121 for dirname, _, filenames in os.walk(TTS_REFERENCE_PATH):
111 for filename in filenames: 122 for filename in filenames:
112 if filename == caterpillar.SW_SCRIPT_NAME: 123 if filename == caterpillar.SW_SCRIPT_NAME:
113 # Service worker is partly random, so test it elsewhere. 124 # Service worker is partly random, so test it elsewhere.
114 continue 125 continue
115 126
116 reference_path = os.path.join(dirname, filename) 127 reference_path = os.path.join(dirname, filename)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 '\n'.join(difflib.unified_diff( 166 '\n'.join(difflib.unified_diff(
156 output_data.split('\n'), 167 output_data.split('\n'),
157 reference_data.split('\n'), 168 reference_data.split('\n'),
158 fromfile=reference_sw_path, 169 fromfile=reference_sw_path,
159 tofile=output_sw_path, 170 tofile=output_sw_path,
160 n=0)))) 171 n=0))))
161 172
162 173
163 if __name__ == '__main__': 174 if __name__ == '__main__':
164 unittest.main() 175 unittest.main()
OLDNEW
« no previous file with comments | « src/caterpillar.py ('k') | src/report/report.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698