| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2012 The LUCI Authors. All rights reserved. | 2 # Copyright 2012 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| 11 import unittest | 11 import unittest |
| 12 | 12 |
| 13 ROOT_DIR = unicode(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 13 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath( |
| 14 __file__.decode(sys.getfilesystemencoding())))) |
| 14 sys.path.insert(0, ROOT_DIR) | 15 sys.path.insert(0, ROOT_DIR) |
| 15 | 16 |
| 16 import isolated_format | 17 import isolated_format |
| 17 import run_isolated | 18 import run_isolated |
| 18 from depot_tools import fix_encoding | 19 from depot_tools import fix_encoding |
| 19 from utils import file_path | 20 from utils import file_path |
| 20 | 21 |
| 21 import isolateserver_mock | 22 import isolateserver_mock |
| 22 import test_utils | 23 import test_utils |
| 23 | 24 |
| 24 | 25 |
| 25 CONTENTS = { | 26 CONTENTS = { |
| 26 'check_files.py': """if True: | 27 'check_files.py': """if True: |
| 27 import os, sys | 28 import os, sys |
| 28 ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 29 ROOT_DIR = os.path.dirname(os.path.abspath( |
| 30 __file__.decode(sys.getfilesystemencoding()))) |
| 29 expected = [ | 31 expected = [ |
| 30 'check_files.py', 'file1.txt', 'file1_copy.txt', 'file2.txt', | 32 'check_files.py', 'file1.txt', 'file1_copy.txt', 'file2.txt', |
| 31 'repeated_files.py', | 33 'repeated_files.py', |
| 32 ] | 34 ] |
| 33 actual = sorted(os.listdir(ROOT_DIR)) | 35 actual = sorted(os.listdir(ROOT_DIR)) |
| 34 if expected != actual: | 36 if expected != actual: |
| 35 print >> sys.stderr, 'Expected list doesn\\'t match:' | 37 print >> sys.stderr, 'Expected list doesn\\'t match:' |
| 36 print >> sys.stderr, '%s\\n%s' % (','.join(expected), ','.join(actual)) | 38 print >> sys.stderr, '%s\\n%s' % (','.join(expected), ','.join(actual)) |
| 37 sys.exit(1) | 39 sys.exit(1) |
| 38 # Check that file2.txt is in reality file3.txt. | 40 # Check that file2.txt is in reality file3.txt. |
| 39 with open(os.path.join(ROOT_DIR, 'file2.txt'), 'rb') as f: | 41 with open(os.path.join(ROOT_DIR, 'file2.txt'), 'rb') as f: |
| 40 if f.read() != 'File3\\n': | 42 if f.read() != 'File3\\n': |
| 41 print >> sys.stderr, 'file2.txt should be file3.txt in reality' | 43 print >> sys.stderr, 'file2.txt should be file3.txt in reality' |
| 42 sys.exit(2) | 44 sys.exit(2) |
| 43 print('Success')""", | 45 print('Success')""", |
| 44 'file1.txt': 'File1\n', | 46 'file1.txt': 'File1\n', |
| 45 'file2.txt': 'File2.txt\n', | 47 'file2.txt': 'File2.txt\n', |
| 46 'file3.txt': 'File3\n', | 48 'file3.txt': 'File3\n', |
| 47 'repeated_files.py': """if True: | 49 'repeated_files.py': """if True: |
| 48 import os, sys | 50 import os, sys |
| 49 expected = ['file1.txt', 'file1_copy.txt', 'repeated_files.py'] | 51 expected = ['file1.txt', 'file1_copy.txt', 'repeated_files.py'] |
| 50 actual = sorted(os.listdir(os.path.dirname(os.path.abspath(__file__)))) | 52 actual = sorted(os.listdir(os.path.dirname(os.path.abspath( |
| 53 __file__.decode(sys.getfilesystemencoding()))))) |
| 51 if expected != actual: | 54 if expected != actual: |
| 52 print >> sys.stderr, 'Expected list doesn\\'t match:' | 55 print >> sys.stderr, 'Expected list doesn\\'t match:' |
| 53 print >> sys.stderr, '%s\\n%s' % (','.join(expected), ','.join(actual)) | 56 print >> sys.stderr, '%s\\n%s' % (','.join(expected), ','.join(actual)) |
| 54 sys.exit(1) | 57 sys.exit(1) |
| 55 print('Success')""", | 58 print('Success')""", |
| 56 'max_path.py': """if True: | 59 'max_path.py': """if True: |
| 57 import os, sys | 60 import os, sys |
| 58 prefix = u'\\\\\\\\?\\\\' if sys.platform == 'win32' else u'' | 61 prefix = u'\\\\\\\\?\\\\' if sys.platform == 'win32' else u'' |
| 59 path = unicode(os.path.join(os.getcwd(), 'a' * 200, 'b' * 200)) | 62 path = os.path.join(os.getcwd().decode( |
| 63 sys.getfilesystemencoding()), 'a' * 200, 'b' * 200) |
| 60 with open(prefix + path, 'rb') as f: | 64 with open(prefix + path, 'rb') as f: |
| 61 actual = f.read() | 65 actual = f.read() |
| 62 if actual != 'File1\\n': | 66 if actual != 'File1\\n': |
| 63 print >> sys.stderr, 'Unexpected content: %s' % actual | 67 print >> sys.stderr, 'Unexpected content: %s' % actual |
| 64 sys.exit(1) | 68 sys.exit(1) |
| 65 print('Success')""", | 69 print('Success')""", |
| 66 } | 70 } |
| 67 | 71 |
| 68 | 72 |
| 69 def file_meta(filename): | 73 def file_meta(filename): |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 cached_file_path = self._test_corruption_common( | 386 cached_file_path = self._test_corruption_common( |
| 383 CONTENTS['file1.txt'][:-1] + ' ') | 387 CONTENTS['file1.txt'][:-1] + ' ') |
| 384 # TODO(maruel): This corruption is NOT detected. | 388 # TODO(maruel): This corruption is NOT detected. |
| 385 # This needs to be fixed. | 389 # This needs to be fixed. |
| 386 self.assertNotEqual(CONTENTS['file1.txt'], read_content(cached_file_path)) | 390 self.assertNotEqual(CONTENTS['file1.txt'], read_content(cached_file_path)) |
| 387 | 391 |
| 388 | 392 |
| 389 if __name__ == '__main__': | 393 if __name__ == '__main__': |
| 390 fix_encoding.fix_encoding() | 394 fix_encoding.fix_encoding() |
| 391 test_utils.main() | 395 test_utils.main() |
| OLD | NEW |