Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_directories=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_directories: Set of directory names to ignore. Note that all | |
| 87 children will be ignored too. | |
| 88 | |
| 89 Returns: | |
| 90 set of relative filepaths. | |
| 91 """ | |
| 92 if not ignore_directories: | |
| 93 ignore_directories = set() | |
| 94 | |
| 95 filepaths = set() | |
| 96 for dirname, dirnames, filenames in os.walk(directory, topdown=True): | |
| 97 basename = os.path.basename(os.path.normpath(dirname)) | |
|
Matt Giuca
2016/02/05 00:23:49
This is descending into the ignored directory, and
| |
| 98 if basename in ignore_directories: | |
| 99 dirnames[:] = [] | |
| 100 continue | |
| 101 | |
| 102 for filename in filenames: | |
| 103 relpath = os.path.relpath(os.path.join(dirname, filename), directory) | |
| 104 filepaths.add(relpath) | |
| 105 | |
| 106 return filepaths | |
| 79 | 107 |
| 80 def test_output_matches_reference(self): | 108 def test_output_matches_reference(self): |
| 81 """Tests that the output matches the reference output.""" | 109 """Tests that the output matches the reference output.""" |
| 82 expected_files = set() | 110 expected_files = self.get_relative_filepaths(TTS_REFERENCE_PATH, |
| 83 for dirname, _, filenames in os.walk(TTS_REFERENCE_PATH): | 111 {'bower_components'}) |
| 84 for filename in filenames: | 112 actual_files = self.get_relative_filepaths(self.output_dir, |
| 85 relpath = os.path.relpath( | 113 {'bower_components'}) |
| 86 os.path.join(dirname, filename), TTS_REFERENCE_PATH) | 114 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 | 115 |
| 108 def test_all_correct_contents(self): | 116 def test_all_correct_contents(self): |
| 109 """Tests that the content of all non-static output files is expected.""" | 117 """Tests that the content of all non-static output files is expected.""" |
| 110 for dirname, _, filenames in os.walk(TTS_REFERENCE_PATH): | 118 for dirname, _, filenames in os.walk(TTS_REFERENCE_PATH): |
| 111 for filename in filenames: | 119 for filename in filenames: |
| 112 if filename == caterpillar.SW_SCRIPT_NAME: | 120 if filename == caterpillar.SW_SCRIPT_NAME: |
| 113 # Service worker is partly random, so test it elsewhere. | 121 # Service worker is partly random, so test it elsewhere. |
| 114 continue | 122 continue |
| 115 | 123 |
| 116 reference_path = os.path.join(dirname, filename) | 124 reference_path = os.path.join(dirname, filename) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 '\n'.join(difflib.unified_diff( | 163 '\n'.join(difflib.unified_diff( |
| 156 output_data.split('\n'), | 164 output_data.split('\n'), |
| 157 reference_data.split('\n'), | 165 reference_data.split('\n'), |
| 158 fromfile=reference_sw_path, | 166 fromfile=reference_sw_path, |
| 159 tofile=output_sw_path, | 167 tofile=output_sw_path, |
| 160 n=0)))) | 168 n=0)))) |
| 161 | 169 |
| 162 | 170 |
| 163 if __name__ == '__main__': | 171 if __name__ == '__main__': |
| 164 unittest.main() | 172 unittest.main() |
| OLD | NEW |