| 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 hashlib | 6 import hashlib |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 import tempfile | 13 import tempfile |
| 14 import unittest | 14 import unittest |
| 15 | 15 |
| 16 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 16 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 17 ROOT_DIR = os.path.dirname(BASE_DIR) | 17 GOOGLETEST_DIR = os.path.dirname(BASE_DIR) |
| 18 ROOT_DIR = os.path.dirname(GOOGLETEST_DIR) |
| 19 |
| 18 sys.path.insert(0, ROOT_DIR) | 20 sys.path.insert(0, ROOT_DIR) |
| 19 | 21 |
| 20 import run_isolated | 22 import run_isolated |
| 21 | 23 |
| 22 | 24 |
| 23 class FixTestCases(unittest.TestCase): | 25 class FixTestCases(unittest.TestCase): |
| 24 def setUp(self): | 26 def setUp(self): |
| 25 self.tempdir = tempfile.mkdtemp(prefix='fix_test_case') | 27 self.tempdir = tempfile.mkdtemp(prefix='fix_test_case') |
| 26 self.srcdir = os.path.join(self.tempdir, 'srcdir') | 28 self.srcdir = os.path.join(self.tempdir, 'srcdir') |
| 27 os.mkdir(self.srcdir) | 29 os.mkdir(self.srcdir) |
| 28 | 30 |
| 29 def tearDown(self): | 31 def tearDown(self): |
| 30 if self.tempdir: | 32 if self.tempdir: |
| 31 if VERBOSE: | 33 if VERBOSE: |
| 32 # If -v is used, this means the user wants to do further analisys on | 34 # If -v is used, this means the user wants to do further analisys on |
| 33 # the data. | 35 # the data. |
| 34 print('Leaking %s' % self.tempdir) | 36 print('Leaking %s' % self.tempdir) |
| 35 else: | 37 else: |
| 36 shutil.rmtree(self.tempdir) | 38 shutil.rmtree(self.tempdir) |
| 37 | 39 |
| 38 def _run(self, cmd): | 40 def _run(self, cmd): |
| 39 if VERBOSE: | 41 if VERBOSE: |
| 40 cmd = cmd + ['--verbose'] * 3 | 42 cmd = cmd + ['--verbose'] * 3 |
| 41 logging.info(cmd) | 43 logging.info(cmd) |
| 42 proc = subprocess.Popen( | 44 proc = subprocess.Popen( |
| 43 [sys.executable, os.path.join(ROOT_DIR, cmd[0])] + cmd[1:], | 45 [sys.executable] + cmd, |
| 44 cwd=self.srcdir, | 46 cwd=self.srcdir, |
| 45 stdout=subprocess.PIPE, | 47 stdout=subprocess.PIPE, |
| 46 stderr=subprocess.STDOUT) | 48 stderr=subprocess.STDOUT) |
| 47 out = proc.communicate()[0] | 49 out = proc.communicate()[0] |
| 48 if VERBOSE: | 50 if VERBOSE: |
| 49 print '\n-----' | 51 print '\n-----' |
| 50 print out.strip() | 52 print out.strip() |
| 51 print '-----\n' | 53 print '-----\n' |
| 52 self.assertEqual(0, proc.returncode) | 54 self.assertEqual(0, proc.returncode) |
| 53 return out | 55 return out |
| (...skipping 17 matching lines...) Expand all Loading... |
| 71 }], | 73 }], |
| 72 ], | 74 ], |
| 73 })) | 75 })) |
| 74 def _copy(filename): | 76 def _copy(filename): |
| 75 shutil.copy( | 77 shutil.copy( |
| 76 os.path.join(BASE_DIR, 'gtest_fake', filename), | 78 os.path.join(BASE_DIR, 'gtest_fake', filename), |
| 77 os.path.join(self.srcdir, filename)) | 79 os.path.join(self.srcdir, filename)) |
| 78 _copy('gtest_fake_base.py') | 80 _copy('gtest_fake_base.py') |
| 79 _copy('gtest_fake_pass.py') | 81 _copy('gtest_fake_pass.py') |
| 80 shutil.copy( | 82 shutil.copy( |
| 81 os.path.join(ROOT_DIR, 'run_test_cases.py'), | 83 os.path.join(GOOGLETEST_DIR, 'run_test_cases.py'), |
| 82 os.path.join(self.srcdir, 'run_test_cases.py')) | 84 os.path.join(self.srcdir, 'run_test_cases.py')) |
| 83 shutil.copy( | 85 shutil.copy( |
| 84 os.path.join(ROOT_DIR, 'run_isolated.py'), | 86 os.path.join(ROOT_DIR, 'run_isolated.py'), |
| 85 os.path.join(self.srcdir, 'run_isolated.py')) | 87 os.path.join(self.srcdir, 'run_isolated.py')) |
| 86 | 88 |
| 87 logging.debug('1. Create a .isolated file out of the .isolate file.') | 89 logging.debug('1. Create a .isolated file out of the .isolate file.') |
| 88 isolated = os.path.join(self.srcdir, 'gtest_fake_pass.isolated') | 90 isolated = os.path.join(self.srcdir, 'gtest_fake_pass.isolated') |
| 89 out = self._run(['isolate.py', 'check', '-i', isolate, '-s', isolated, | 91 out = self._run( |
| 90 '-V', 'chromeos', str(chromeos_value)]) | 92 [ |
| 93 os.path.join(ROOT_DIR, 'isolate.py'), |
| 94 'check', '-i', isolate, '-s', isolated, |
| 95 '-V', 'chromeos', str(chromeos_value), |
| 96 ]) |
| 91 if not VERBOSE: | 97 if not VERBOSE: |
| 92 self.assertEqual('', out) | 98 self.assertEqual('', out) |
| 93 | 99 |
| 94 logging.debug('2. Run fix_test_cases.py on it.') | 100 logging.debug('2. Run fix_test_cases.py on it.') |
| 95 # Give up on looking at stdout. | 101 # Give up on looking at stdout. |
| 96 _ = self._run(['fix_test_cases.py', '-s', isolated]) | 102 _ = self._run( |
| 103 [os.path.join(GOOGLETEST_DIR, 'fix_test_cases.py'), '-s', isolated]) |
| 97 | 104 |
| 98 logging.debug('3. Asserting the content of the .isolated file.') | 105 logging.debug('3. Asserting the content of the .isolated file.') |
| 99 with open(isolated) as f: | 106 with open(isolated) as f: |
| 100 actual_isolated = json.load(f) | 107 actual_isolated = json.load(f) |
| 101 gtest_fake_base_py = os.path.join(self.srcdir, 'gtest_fake_base.py') | 108 gtest_fake_base_py = os.path.join(self.srcdir, 'gtest_fake_base.py') |
| 102 gtest_fake_pass_py = os.path.join(self.srcdir, 'gtest_fake_pass.py') | 109 gtest_fake_pass_py = os.path.join(self.srcdir, 'gtest_fake_pass.py') |
| 103 run_isolated_py = os.path.join(self.srcdir, 'run_isolated.py') | 110 run_isolated_py = os.path.join(self.srcdir, 'run_isolated.py') |
| 104 run_test_cases_py = os.path.join(self.srcdir, 'run_test_cases.py') | 111 run_test_cases_py = os.path.join(self.srcdir, 'run_test_cases.py') |
| 105 expected_isolated = { | 112 expected_isolated = { |
| 106 u'command': [u'run_test_cases.py', u'gtest_fake_pass.py'], | 113 u'command': [u'run_test_cases.py', u'gtest_fake_pass.py'], |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 }], | 166 }], |
| 160 ], | 167 ], |
| 161 } | 168 } |
| 162 self.assertEqual(expected, actual) | 169 self.assertEqual(expected, actual) |
| 163 | 170 |
| 164 | 171 |
| 165 if __name__ == '__main__': | 172 if __name__ == '__main__': |
| 166 VERBOSE = '-v' in sys.argv | 173 VERBOSE = '-v' in sys.argv |
| 167 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 174 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
| 168 unittest.main() | 175 unittest.main() |
| OLD | NEW |