| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import shutil |
| 7 import unittest | 8 import unittest |
| 8 | 9 |
| 9 import bisect_perf_regression | 10 import bisect_perf_regression |
| 10 import source_control as source_control_module | 11 import source_control as source_control_module |
| 11 | 12 |
| 12 def _GetBisectPerformanceMetricsInstance(): | 13 def _GetBisectPerformanceMetricsInstance(): |
| 13 """Returns an instance of the BisectPerformanceMetrics class.""" | 14 """Returns an instance of the BisectPerformanceMetrics class.""" |
| 14 options_dict = { | 15 options_dict = { |
| 15 'debug_ignore_build': True, | 16 'debug_ignore_build': True, |
| 16 'debug_ignore_sync': True, | 17 'debug_ignore_sync': True, |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 276628, 'chromium') | 241 276628, 'chromium') |
| 241 | 242 |
| 242 # This method doesn't reference self; it fails if an error is thrown. | 243 # This method doesn't reference self; it fails if an error is thrown. |
| 243 # pylint: disable=R0201 | 244 # pylint: disable=R0201 |
| 244 def testDryRun(self): | 245 def testDryRun(self): |
| 245 """Does a dry run of the bisect script. | 246 """Does a dry run of the bisect script. |
| 246 | 247 |
| 247 This serves as a smoke test to catch errors in the basic execution of the | 248 This serves as a smoke test to catch errors in the basic execution of the |
| 248 script. | 249 script. |
| 249 """ | 250 """ |
| 250 bisect_instance = _GetBisectPerformanceMetricsInstance() | 251 # Disable rmtree to avoid deleting local trees. |
| 251 results = bisect_instance.Run(bisect_instance.opts.command, | 252 old_rmtree = shutil.rmtree |
| 252 bisect_instance.opts.bad_revision, | 253 try: |
| 253 bisect_instance.opts.good_revision, | 254 shutil.rmtree = lambda path, onerror: None |
| 254 bisect_instance.opts.metric) | 255 bisect_instance = _GetBisectPerformanceMetricsInstance() |
| 255 bisect_instance.FormatAndPrintResults(results) | 256 results = bisect_instance.Run(bisect_instance.opts.command, |
| 257 bisect_instance.opts.bad_revision, |
| 258 bisect_instance.opts.good_revision, |
| 259 bisect_instance.opts.metric) |
| 260 bisect_instance.FormatAndPrintResults(results) |
| 261 finally: |
| 262 shutil.rmtree = old_rmtree |
| 256 | 263 |
| 257 def testGetCommitPosition(self): | 264 def testGetCommitPosition(self): |
| 258 bisect_instance = _GetBisectPerformanceMetricsInstance() | 265 bisect_instance = _GetBisectPerformanceMetricsInstance() |
| 259 cp_git_rev = '7017a81991de983e12ab50dfc071c70e06979531' | 266 cp_git_rev = '7017a81991de983e12ab50dfc071c70e06979531' |
| 260 self.assertEqual( | 267 self.assertEqual( |
| 261 291765, bisect_instance.source_control.GetCommitPosition(cp_git_rev)) | 268 291765, bisect_instance.source_control.GetCommitPosition(cp_git_rev)) |
| 262 | 269 |
| 263 svn_git_rev = 'e6db23a037cad47299a94b155b95eebd1ee61a58' | 270 svn_git_rev = 'e6db23a037cad47299a94b155b95eebd1ee61a58' |
| 264 self.assertEqual( | 271 self.assertEqual( |
| 265 291467, bisect_instance.source_control.GetCommitPosition(svn_git_rev)) | 272 291467, bisect_instance.source_control.GetCommitPosition(svn_git_rev)) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 294 git_revision = 'a12345789a23456789a123456789a123456789' | 301 git_revision = 'a12345789a23456789a123456789a123456789' |
| 295 updated_content = bisect_instance.UpdateDepsContents( | 302 updated_content = bisect_instance.UpdateDepsContents( |
| 296 deps_contents, depot, git_revision, deps_key) | 303 deps_contents, depot, git_revision, deps_key) |
| 297 self.assertIsNotNone(updated_content) | 304 self.assertIsNotNone(updated_content) |
| 298 ss = re.compile('["\']%s["\']: ["\']%s["\']' % (deps_key, git_revision)) | 305 ss = re.compile('["\']%s["\']: ["\']%s["\']' % (deps_key, git_revision)) |
| 299 self.assertIsNotNone(re.search(ss, updated_content)) | 306 self.assertIsNotNone(re.search(ss, updated_content)) |
| 300 | 307 |
| 301 | 308 |
| 302 if __name__ == '__main__': | 309 if __name__ == '__main__': |
| 303 unittest.main() | 310 unittest.main() |
| OLD | NEW |