| OLD | NEW |
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 | 5 |
| 6 import atexit | 6 import atexit |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import tempfile | 10 import tempfile |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 self.root_dir = None | 36 self.root_dir = None |
| 37 | 37 |
| 38 def set_up(self): | 38 def set_up(self): |
| 39 """All late initialization comes here.""" | 39 """All late initialization comes here.""" |
| 40 # You can override self.TRIAL_ROOT. | 40 # You can override self.TRIAL_ROOT. |
| 41 if not self.TRIAL_ROOT: | 41 if not self.TRIAL_ROOT: |
| 42 # Was not yet initialized. | 42 # Was not yet initialized. |
| 43 TrialDir.TRIAL_ROOT = os.path.realpath(tempfile.mkdtemp(prefix='trial')) | 43 TrialDir.TRIAL_ROOT = os.path.realpath(tempfile.mkdtemp(prefix='trial')) |
| 44 atexit.register(self._clean) | 44 atexit.register(self._clean) |
| 45 self.root_dir = os.path.join(TrialDir.TRIAL_ROOT, self.subdir) | 45 self.root_dir = os.path.join(TrialDir.TRIAL_ROOT, self.subdir) |
| 46 gclient_utils.RemoveDirectory(self.root_dir) | 46 gclient_utils.rmtree(self.root_dir) |
| 47 os.makedirs(self.root_dir) | 47 os.makedirs(self.root_dir) |
| 48 | 48 |
| 49 def tear_down(self): | 49 def tear_down(self): |
| 50 """Cleans the trial subdirectory for this instance.""" | 50 """Cleans the trial subdirectory for this instance.""" |
| 51 if not self.leak: | 51 if not self.leak: |
| 52 logging.debug('Removing %s' % self.root_dir) | 52 logging.debug('Removing %s' % self.root_dir) |
| 53 gclient_utils.RemoveDirectory(self.root_dir) | 53 gclient_utils.rmtree(self.root_dir) |
| 54 else: | 54 else: |
| 55 logging.error('Leaking %s' % self.root_dir) | 55 logging.error('Leaking %s' % self.root_dir) |
| 56 self.root_dir = None | 56 self.root_dir = None |
| 57 | 57 |
| 58 @staticmethod | 58 @staticmethod |
| 59 def _clean(): | 59 def _clean(): |
| 60 """Cleans the root trial directory.""" | 60 """Cleans the root trial directory.""" |
| 61 if not TrialDir.SHOULD_LEAK: | 61 if not TrialDir.SHOULD_LEAK: |
| 62 logging.debug('Removing %s' % TrialDir.TRIAL_ROOT) | 62 logging.debug('Removing %s' % TrialDir.TRIAL_ROOT) |
| 63 gclient_utils.RemoveDirectory(TrialDir.TRIAL_ROOT) | 63 gclient_utils.rmtree(TrialDir.TRIAL_ROOT) |
| 64 else: | 64 else: |
| 65 logging.error('Leaking %s' % TrialDir.TRIAL_ROOT) | 65 logging.error('Leaking %s' % TrialDir.TRIAL_ROOT) |
| 66 | 66 |
| 67 | 67 |
| 68 class TrialDirMixIn(object): | 68 class TrialDirMixIn(object): |
| 69 def setUp(self): | 69 def setUp(self): |
| 70 # Create a specific directory just for the test. | 70 # Create a specific directory just for the test. |
| 71 self.trial = TrialDir(self.id()) | 71 self.trial = TrialDir(self.id()) |
| 72 self.trial.set_up() | 72 self.trial.set_up() |
| 73 | 73 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 88 def tearDown(self): | 88 def tearDown(self): |
| 89 TrialDirMixIn.tearDown(self) | 89 TrialDirMixIn.tearDown(self) |
| 90 auto_stub.TestCase.tearDown(self) | 90 auto_stub.TestCase.tearDown(self) |
| 91 | 91 |
| 92 | 92 |
| 93 if '-l' in sys.argv: | 93 if '-l' in sys.argv: |
| 94 # See SHOULD_LEAK definition in TrialDir for its purpose. | 94 # See SHOULD_LEAK definition in TrialDir for its purpose. |
| 95 TrialDir.SHOULD_LEAK = True | 95 TrialDir.SHOULD_LEAK = True |
| 96 print 'Leaking!' | 96 print 'Leaking!' |
| 97 sys.argv.remove('-l') | 97 sys.argv.remove('-l') |
| OLD | NEW |