| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 import cStringIO | 6 import cStringIO |
| 7 import hashlib | 7 import hashlib |
| 8 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| 11 import re | 11 import re |
| 12 import shutil | 12 import shutil |
| 13 import stat | 13 import stat |
| 14 import subprocess | 14 import subprocess |
| 15 import sys | 15 import sys |
| 16 import tempfile | 16 import tempfile |
| 17 import unittest | 17 import unittest |
| 18 | 18 |
| 19 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 19 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 20 sys.path.insert(0, ROOT_DIR) | 20 sys.path.insert(0, ROOT_DIR) |
| 21 | 21 |
| 22 import isolate | 22 import isolate |
| 23 import isolateserver | 23 import isolateserver |
| 24 from utils import file_path |
| 24 | 25 |
| 25 | 26 |
| 26 VERBOSE = False | 27 VERBOSE = False |
| 27 | 28 |
| 28 ALGO = hashlib.sha1 | 29 ALGO = hashlib.sha1 |
| 29 HASH_NULL = ALGO().hexdigest() | 30 HASH_NULL = ALGO().hexdigest() |
| 30 | 31 |
| 31 | 32 |
| 32 # Keep the list hard coded. | 33 # Keep the list hard coded. |
| 33 EXPECTED_MODES = ( | 34 EXPECTED_MODES = ( |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 259 |
| 259 def _expected_saved_state(self, args, read_only, empty_file, extra_vars): | 260 def _expected_saved_state(self, args, read_only, empty_file, extra_vars): |
| 260 flavor = isolate.get_flavor() | 261 flavor = isolate.get_flavor() |
| 261 chromeos_value = int(flavor == 'linux') | 262 chromeos_value = int(flavor == 'linux') |
| 262 expected = { | 263 expected = { |
| 263 u'algo': u'sha-1', | 264 u'algo': u'sha-1', |
| 264 u'child_isolated_files': [], | 265 u'child_isolated_files': [], |
| 265 u'command': [], | 266 u'command': [], |
| 266 u'files': self._gen_files(read_only, empty_file, True), | 267 u'files': self._gen_files(read_only, empty_file, True), |
| 267 u'isolate_file': isolate.safe_relpath( | 268 u'isolate_file': isolate.safe_relpath( |
| 268 isolate.trace_inputs.get_native_path_case(unicode(self.filename())), | 269 file_path.get_native_path_case(unicode(self.filename())), |
| 269 unicode(os.path.dirname(self.isolated))), | 270 unicode(os.path.dirname(self.isolated))), |
| 270 u'relative_cwd': unicode(RELATIVE_CWD[self.case()]), | 271 u'relative_cwd': unicode(RELATIVE_CWD[self.case()]), |
| 271 u'variables': { | 272 u'variables': { |
| 272 u'EXECUTABLE_SUFFIX': u'.exe' if flavor == 'win' else u'', | 273 u'EXECUTABLE_SUFFIX': u'.exe' if flavor == 'win' else u'', |
| 273 u'OS': unicode(flavor), | 274 u'OS': unicode(flavor), |
| 274 u'chromeos': chromeos_value, | 275 u'chromeos': chromeos_value, |
| 275 }, | 276 }, |
| 276 u'version': u'1.0', | 277 u'version': u'1.0', |
| 277 } | 278 } |
| 278 if args: | 279 if args: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 355 |
| 355 def _test_missing_trailing_slash(self, mode): | 356 def _test_missing_trailing_slash(self, mode): |
| 356 try: | 357 try: |
| 357 self._execute(mode, 'missing_trailing_slash.isolate', [], True) | 358 self._execute(mode, 'missing_trailing_slash.isolate', [], True) |
| 358 self.fail() | 359 self.fail() |
| 359 except subprocess.CalledProcessError as e: | 360 except subprocess.CalledProcessError as e: |
| 360 self.assertEqual('', e.output) | 361 self.assertEqual('', e.output) |
| 361 out = e.stderr | 362 out = e.stderr |
| 362 self._expect_no_tree() | 363 self._expect_no_tree() |
| 363 self._expect_no_result() | 364 self._expect_no_result() |
| 364 root = isolate.trace_inputs.get_native_path_case(unicode(ROOT_DIR)) | 365 root = file_path.get_native_path_case(unicode(ROOT_DIR)) |
| 365 expected = ( | 366 expected = ( |
| 366 '\n' | 367 '\n' |
| 367 'Error: Input directory %s must have a trailing slash\n' % | 368 'Error: Input directory %s must have a trailing slash\n' % |
| 368 os.path.join(root, 'tests', 'isolate', 'files1') | 369 os.path.join(root, 'tests', 'isolate', 'files1') |
| 369 ) | 370 ) |
| 370 self.assertEqual(expected, out) | 371 self.assertEqual(expected, out) |
| 371 | 372 |
| 372 def _test_non_existent(self, mode): | 373 def _test_non_existent(self, mode): |
| 373 try: | 374 try: |
| 374 self._execute(mode, 'non_existent.isolate', [], True) | 375 self._execute(mode, 'non_existent.isolate', [], True) |
| 375 self.fail() | 376 self.fail() |
| 376 except subprocess.CalledProcessError as e: | 377 except subprocess.CalledProcessError as e: |
| 377 self.assertEqual('', e.output) | 378 self.assertEqual('', e.output) |
| 378 out = e.stderr | 379 out = e.stderr |
| 379 self._expect_no_tree() | 380 self._expect_no_tree() |
| 380 self._expect_no_result() | 381 self._expect_no_result() |
| 381 root = isolate.trace_inputs.get_native_path_case(unicode(ROOT_DIR)) | 382 root = file_path.get_native_path_case(unicode(ROOT_DIR)) |
| 382 expected = ( | 383 expected = ( |
| 383 '\n' | 384 '\n' |
| 384 'Error: Input file %s doesn\'t exist\n' % | 385 'Error: Input file %s doesn\'t exist\n' % |
| 385 os.path.join(root, 'tests', 'isolate', 'A_file_that_do_not_exist') | 386 os.path.join(root, 'tests', 'isolate', 'A_file_that_do_not_exist') |
| 386 ) | 387 ) |
| 387 self.assertEqual(expected, out) | 388 self.assertEqual(expected, out) |
| 388 | 389 |
| 389 def _test_all_items_invalid(self, mode): | 390 def _test_all_items_invalid(self, mode): |
| 390 out = self._execute(mode, 'all_items_invalid.isolate', | 391 out = self._execute(mode, 'all_items_invalid.isolate', |
| 391 ['--ignore_broken_item'], True) | 392 ['--ignore_broken_item'], True) |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 self._execute('run', 'symlink_outside_build_root.isolate', [], False) | 785 self._execute('run', 'symlink_outside_build_root.isolate', [], False) |
| 785 self._expect_empty_tree() | 786 self._expect_empty_tree() |
| 786 self._expect_results(['symlink_outside_build_root.py'], None, None, None) | 787 self._expect_results(['symlink_outside_build_root.py'], None, None, None) |
| 787 | 788 |
| 788 | 789 |
| 789 class Isolate_trace_read_merge(IsolateModeBase): | 790 class Isolate_trace_read_merge(IsolateModeBase): |
| 790 # Tests both trace, read and merge. | 791 # Tests both trace, read and merge. |
| 791 # Warning: merge updates .isolate files. But they are currently in their | 792 # Warning: merge updates .isolate files. But they are currently in their |
| 792 # canonical format so they shouldn't be changed. | 793 # canonical format so they shouldn't be changed. |
| 793 def _check_merge(self, filename): | 794 def _check_merge(self, filename): |
| 794 filepath = isolate.trace_inputs.get_native_path_case( | 795 filepath = file_path.get_native_path_case( |
| 795 os.path.join(unicode(ROOT_DIR), 'tests', 'isolate', filename)) | 796 os.path.join(unicode(ROOT_DIR), 'tests', 'isolate', filename)) |
| 796 expected = 'Updating %s\n' % isolate.safe_relpath(filepath, self.tempdir) | 797 expected = 'Updating %s\n' % isolate.safe_relpath(filepath, self.tempdir) |
| 797 with open(filepath, 'rb') as f: | 798 with open(filepath, 'rb') as f: |
| 798 old_content = f.read() | 799 old_content = f.read() |
| 799 out = self._execute('merge', filename, [], True) or '' | 800 out = self._execute('merge', filename, [], True) or '' |
| 800 self.assertEqual(expected, out) | 801 self.assertEqual(expected, out) |
| 801 with open(filepath, 'rb') as f: | 802 with open(filepath, 'rb') as f: |
| 802 new_content = f.read() | 803 new_content = f.read() |
| 803 self.assertEqual(old_content, new_content) | 804 self.assertEqual(old_content, new_content) |
| 804 | 805 |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 self.assertEqual('Simply works.\n', stdout) | 1168 self.assertEqual('Simply works.\n', stdout) |
| 1168 self.assertEqual(0, proc.returncode) | 1169 self.assertEqual(0, proc.returncode) |
| 1169 | 1170 |
| 1170 | 1171 |
| 1171 if __name__ == '__main__': | 1172 if __name__ == '__main__': |
| 1172 VERBOSE = '-v' in sys.argv | 1173 VERBOSE = '-v' in sys.argv |
| 1173 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 1174 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
| 1174 if VERBOSE: | 1175 if VERBOSE: |
| 1175 unittest.TestCase.maxDiff = None | 1176 unittest.TestCase.maxDiff = None |
| 1176 unittest.main() | 1177 unittest.main() |
| OLD | NEW |