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 sys | 11 import sys |
12 import tempfile | 12 import tempfile |
13 import unittest | 13 import unittest |
14 | 14 |
15 import auto_stub | 15 import auto_stub |
16 | 16 |
17 ROOT_DIR = unicode(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | 17 ROOT_DIR = unicode(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
18 sys.path.insert(0, ROOT_DIR) | 18 sys.path.insert(0, ROOT_DIR) |
19 | 19 |
20 import isolate | 20 import isolate |
| 21 from utils import file_path |
21 # Create shortcuts. | 22 # Create shortcuts. |
22 from isolate import KEY_TOUCHED, KEY_TRACKED, KEY_UNTRACKED | 23 from isolate import KEY_TOUCHED, KEY_TRACKED, KEY_UNTRACKED |
23 | 24 |
24 | 25 |
25 ALGO = hashlib.sha1 | 26 ALGO = hashlib.sha1 |
26 | 27 |
27 | 28 |
28 def _size(*args): | 29 def _size(*args): |
29 return os.stat(os.path.join(ROOT_DIR, *args)).st_size | 30 return os.stat(os.path.join(ROOT_DIR, *args)).st_size |
30 | 31 |
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 'h': hash_file('tests', 'isolate', 'touch_root.py'), | 1169 'h': hash_file('tests', 'isolate', 'touch_root.py'), |
1169 's': _size('tests', 'isolate', 'touch_root.py'), | 1170 's': _size('tests', 'isolate', 'touch_root.py'), |
1170 }, | 1171 }, |
1171 u'isolate.py': { | 1172 u'isolate.py': { |
1172 'm': 488, | 1173 'm': 488, |
1173 'h': hash_file('isolate.py'), | 1174 'h': hash_file('isolate.py'), |
1174 's': _size('isolate.py'), | 1175 's': _size('isolate.py'), |
1175 }, | 1176 }, |
1176 }, | 1177 }, |
1177 'isolate_file': isolate.safe_relpath( | 1178 'isolate_file': isolate.safe_relpath( |
1178 isolate.trace_inputs.get_native_path_case(isolate_file), | 1179 file_path.get_native_path_case(isolate_file), |
1179 os.path.dirname(options.isolated)), | 1180 os.path.dirname(options.isolated)), |
1180 'relative_cwd': os.path.join(u'tests', 'isolate'), | 1181 'relative_cwd': os.path.join(u'tests', 'isolate'), |
1181 'variables': { | 1182 'variables': { |
1182 'foo': 'bar', | 1183 'foo': 'bar', |
1183 'OS': isolate.get_flavor(), | 1184 'OS': isolate.get_flavor(), |
1184 'chromeos': options.variables['chromeos'], | 1185 'chromeos': options.variables['chromeos'], |
1185 }, | 1186 }, |
1186 'version': '1.0', | 1187 'version': '1.0', |
1187 } | 1188 } |
1188 self._cleanup_isolated(expected_saved_state) | 1189 self._cleanup_isolated(expected_saved_state) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 'child_isolated_files': [], | 1225 'child_isolated_files': [], |
1225 'command': ['python', 'touch_root.py'], | 1226 'command': ['python', 'touch_root.py'], |
1226 'files': { | 1227 'files': { |
1227 os.path.join(u'tests', 'isolate', 'touch_root.py'): { | 1228 os.path.join(u'tests', 'isolate', 'touch_root.py'): { |
1228 'm': 488, | 1229 'm': 488, |
1229 'h': hash_file('tests', 'isolate', 'touch_root.py'), | 1230 'h': hash_file('tests', 'isolate', 'touch_root.py'), |
1230 's': _size('tests', 'isolate', 'touch_root.py'), | 1231 's': _size('tests', 'isolate', 'touch_root.py'), |
1231 }, | 1232 }, |
1232 }, | 1233 }, |
1233 'isolate_file': isolate.safe_relpath( | 1234 'isolate_file': isolate.safe_relpath( |
1234 isolate.trace_inputs.get_native_path_case(isolate_file), | 1235 file_path.get_native_path_case(isolate_file), |
1235 os.path.dirname(options.isolated)), | 1236 os.path.dirname(options.isolated)), |
1236 'relative_cwd': os.path.join(u'tests', 'isolate'), | 1237 'relative_cwd': os.path.join(u'tests', 'isolate'), |
1237 'variables': { | 1238 'variables': { |
1238 'foo': 'bar', | 1239 'foo': 'bar', |
1239 'OS': isolate.get_flavor(), | 1240 'OS': isolate.get_flavor(), |
1240 'chromeos': chromeos_value, | 1241 'chromeos': chromeos_value, |
1241 }, | 1242 }, |
1242 'version': '1.0', | 1243 'version': '1.0', |
1243 } | 1244 } |
1244 self._cleanup_isolated(expected_saved_state) | 1245 self._cleanup_isolated(expected_saved_state) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 'child_isolated_files': [], | 1282 'child_isolated_files': [], |
1282 'command': ['python', 'touch_root.py'], | 1283 'command': ['python', 'touch_root.py'], |
1283 'files': { | 1284 'files': { |
1284 os.path.join(u'tests', 'isolate', 'touch_root.py'): { | 1285 os.path.join(u'tests', 'isolate', 'touch_root.py'): { |
1285 'm': 488, | 1286 'm': 488, |
1286 'h': hash_file('tests', 'isolate', 'touch_root.py'), | 1287 'h': hash_file('tests', 'isolate', 'touch_root.py'), |
1287 's': _size('tests', 'isolate', 'touch_root.py'), | 1288 's': _size('tests', 'isolate', 'touch_root.py'), |
1288 }, | 1289 }, |
1289 }, | 1290 }, |
1290 'isolate_file': isolate.safe_relpath( | 1291 'isolate_file': isolate.safe_relpath( |
1291 isolate.trace_inputs.get_native_path_case(isolate_file), | 1292 file_path.get_native_path_case(isolate_file), |
1292 os.path.dirname(options.isolated)), | 1293 os.path.dirname(options.isolated)), |
1293 'relative_cwd': os.path.join(u'tests', 'isolate'), | 1294 'relative_cwd': os.path.join(u'tests', 'isolate'), |
1294 'variables': { | 1295 'variables': { |
1295 'foo': 'bar', | 1296 'foo': 'bar', |
1296 'BAZ': os.path.join('tests', 'isolate'), | 1297 'BAZ': os.path.join('tests', 'isolate'), |
1297 'OS': isolate.get_flavor(), | 1298 'OS': isolate.get_flavor(), |
1298 'chromeos': chromeos_value, | 1299 'chromeos': chromeos_value, |
1299 }, | 1300 }, |
1300 'version': '1.0', | 1301 'version': '1.0', |
1301 } | 1302 } |
1302 self._cleanup_isolated(expected_saved_state) | 1303 self._cleanup_isolated(expected_saved_state) |
1303 self._cleanup_saved_state(actual_saved_state) | 1304 self._cleanup_saved_state(actual_saved_state) |
1304 self.assertEqual(expected_saved_state, actual_saved_state) | 1305 self.assertEqual(expected_saved_state, actual_saved_state) |
1305 | 1306 |
1306 def test_variable_not_exist(self): | 1307 def test_variable_not_exist(self): |
1307 isolate_file = os.path.join( | 1308 isolate_file = os.path.join( |
1308 ROOT_DIR, 'tests', 'isolate', 'touch_root.isolate') | 1309 ROOT_DIR, 'tests', 'isolate', 'touch_root.isolate') |
1309 options = self._get_option(isolate_file) | 1310 options = self._get_option(isolate_file) |
1310 options.variables['PRODUCT_DIR'] = os.path.join(u'tests', u'isolate') | 1311 options.variables['PRODUCT_DIR'] = os.path.join(u'tests', u'isolate') |
1311 native_cwd = isolate.trace_inputs.get_native_path_case(unicode(self.cwd)) | 1312 native_cwd = file_path.get_native_path_case(unicode(self.cwd)) |
1312 try: | 1313 try: |
1313 isolate.load_complete_state(options, self.cwd, None, False) | 1314 isolate.load_complete_state(options, self.cwd, None, False) |
1314 self.fail() | 1315 self.fail() |
1315 except isolate.ExecutionError, e: | 1316 except isolate.ExecutionError, e: |
1316 self.assertEqual( | 1317 self.assertEqual( |
1317 'PRODUCT_DIR=%s is not a directory' % | 1318 'PRODUCT_DIR=%s is not a directory' % |
1318 os.path.join(native_cwd, 'tests', 'isolate'), | 1319 os.path.join(native_cwd, 'tests', 'isolate'), |
1319 e.args[0]) | 1320 e.args[0]) |
1320 | 1321 |
1321 def test_variable(self): | 1322 def test_variable(self): |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 'h': hash_file('isolate.py'), | 1362 'h': hash_file('isolate.py'), |
1362 's': _size('isolate.py'), | 1363 's': _size('isolate.py'), |
1363 }, | 1364 }, |
1364 os.path.join(u'tests', 'isolate', 'touch_root.py'): { | 1365 os.path.join(u'tests', 'isolate', 'touch_root.py'): { |
1365 'm': 488, | 1366 'm': 488, |
1366 'h': hash_file('tests', 'isolate', 'touch_root.py'), | 1367 'h': hash_file('tests', 'isolate', 'touch_root.py'), |
1367 's': _size('tests', 'isolate', 'touch_root.py'), | 1368 's': _size('tests', 'isolate', 'touch_root.py'), |
1368 }, | 1369 }, |
1369 }, | 1370 }, |
1370 'isolate_file': isolate.safe_relpath( | 1371 'isolate_file': isolate.safe_relpath( |
1371 isolate.trace_inputs.get_native_path_case(isolate_file), | 1372 file_path.get_native_path_case(isolate_file), |
1372 os.path.dirname(options.isolated)), | 1373 os.path.dirname(options.isolated)), |
1373 'relative_cwd': os.path.join(u'tests', 'isolate'), | 1374 'relative_cwd': os.path.join(u'tests', 'isolate'), |
1374 'variables': { | 1375 'variables': { |
1375 'foo': 'bar', | 1376 'foo': 'bar', |
1376 'PRODUCT_DIR': '.', | 1377 'PRODUCT_DIR': '.', |
1377 'OS': isolate.get_flavor(), | 1378 'OS': isolate.get_flavor(), |
1378 'chromeos': chromeos_value, | 1379 'chromeos': chromeos_value, |
1379 }, | 1380 }, |
1380 'version': '1.0', | 1381 'version': '1.0', |
1381 } | 1382 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 'h': hash_file('tests', 'isolate', 'files1', 'test_file2.txt'), | 1457 'h': hash_file('tests', 'isolate', 'files1', 'test_file2.txt'), |
1457 's': _size('tests', 'isolate', 'files1', 'test_file2.txt'), | 1458 's': _size('tests', 'isolate', 'files1', 'test_file2.txt'), |
1458 }, | 1459 }, |
1459 os.path.join(u'tests', 'isolate', 'no_run.isolate'): { | 1460 os.path.join(u'tests', 'isolate', 'no_run.isolate'): { |
1460 'm': 416, | 1461 'm': 416, |
1461 'h': hash_file('tests', 'isolate', 'no_run.isolate'), | 1462 'h': hash_file('tests', 'isolate', 'no_run.isolate'), |
1462 's': _size('tests', 'isolate', 'no_run.isolate'), | 1463 's': _size('tests', 'isolate', 'no_run.isolate'), |
1463 }, | 1464 }, |
1464 }, | 1465 }, |
1465 'isolate_file': isolate.safe_relpath( | 1466 'isolate_file': isolate.safe_relpath( |
1466 isolate.trace_inputs.get_native_path_case(isolate_file), | 1467 file_path.get_native_path_case(isolate_file), |
1467 os.path.dirname(options.isolated)), | 1468 os.path.dirname(options.isolated)), |
1468 'relative_cwd': os.path.join(u'tests', 'isolate'), | 1469 'relative_cwd': os.path.join(u'tests', 'isolate'), |
1469 'variables': { | 1470 'variables': { |
1470 'foo': 'bar', | 1471 'foo': 'bar', |
1471 'PRODUCT_DIR': os.path.join(u'..', '..', 'third_party'), | 1472 'PRODUCT_DIR': os.path.join(u'..', '..', 'third_party'), |
1472 'OS': isolate.get_flavor(), | 1473 'OS': isolate.get_flavor(), |
1473 'chromeos': chromeos_value, | 1474 'chromeos': chromeos_value, |
1474 }, | 1475 }, |
1475 'version': '1.0', | 1476 'version': '1.0', |
1476 } | 1477 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 u's': _size('tests', 'isolate', 'split.py'), | 1577 u's': _size('tests', 'isolate', 'split.py'), |
1577 }, | 1578 }, |
1578 os.path.join(u'test', 'data', 'foo.txt'): { | 1579 os.path.join(u'test', 'data', 'foo.txt'): { |
1579 u'm': 416, | 1580 u'm': 416, |
1580 u'h': unicode( | 1581 u'h': unicode( |
1581 hash_file('tests', 'isolate', 'test', 'data', 'foo.txt')), | 1582 hash_file('tests', 'isolate', 'test', 'data', 'foo.txt')), |
1582 u's': _size('tests', 'isolate', 'test', 'data', 'foo.txt'), | 1583 u's': _size('tests', 'isolate', 'test', 'data', 'foo.txt'), |
1583 }, | 1584 }, |
1584 }, | 1585 }, |
1585 u'isolate_file': isolate.safe_relpath( | 1586 u'isolate_file': isolate.safe_relpath( |
1586 isolate.trace_inputs.get_native_path_case(isolate_file), | 1587 file_path.get_native_path_case(isolate_file), |
1587 unicode(os.path.dirname(options.isolated))), | 1588 unicode(os.path.dirname(options.isolated))), |
1588 u'relative_cwd': u'.', | 1589 u'relative_cwd': u'.', |
1589 u'variables': { | 1590 u'variables': { |
1590 u'OS': unicode(isolate.get_flavor()), | 1591 u'OS': unicode(isolate.get_flavor()), |
1591 u'DEPTH': u'.', | 1592 u'DEPTH': u'.', |
1592 u'PRODUCT_DIR': u'files1', | 1593 u'PRODUCT_DIR': u'files1', |
1593 }, | 1594 }, |
1594 u'version': u'1.0', | 1595 u'version': u'1.0', |
1595 } | 1596 } |
1596 self._cleanup_isolated(expected_saved_state) | 1597 self._cleanup_isolated(expected_saved_state) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 self.assertEqual(0, isolate.CMDrun(isolate.OptionParserIsolate(), cmd)) | 1687 self.assertEqual(0, isolate.CMDrun(isolate.OptionParserIsolate(), cmd)) |
1687 | 1688 |
1688 | 1689 |
1689 if __name__ == '__main__': | 1690 if __name__ == '__main__': |
1690 logging.basicConfig( | 1691 logging.basicConfig( |
1691 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR, | 1692 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR, |
1692 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') | 1693 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s') |
1693 if '-v' in sys.argv: | 1694 if '-v' in sys.argv: |
1694 unittest.TestCase.maxDiff = None | 1695 unittest.TestCase.maxDiff = None |
1695 unittest.main() | 1696 unittest.main() |
OLD | NEW |