Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 | 6 |
| 7 import atexit | 7 import atexit |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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.RemoveDirectory(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 TestCase(unittest.TestCase): | 68 class TrialDirMixIn(object): |
| 69 """Base unittest class that cleans off a trial directory in tearDown().""" | 69 """Stand alone mixin.""" |
|
Dirk Pranke
2011/06/14 06:22:09
This comment doesn't tell me anything about what t
| |
| 70 def setUp(self): | 70 def setUp(self): |
| 71 # Create a specific directory just for the test. | 71 # Create a specific directory just for the test. |
| 72 self.trial = TrialDir(self.id()) | 72 self.trial = TrialDir(self.id()) |
| 73 self.trial.set_up() | 73 self.trial.set_up() |
| 74 | 74 |
| 75 def tearDown(self): | 75 def tearDown(self): |
| 76 self.trial.tear_down() | 76 self.trial.tear_down() |
| 77 | 77 |
| 78 @property | 78 @property |
| 79 def root_dir(self): | 79 def root_dir(self): |
| 80 return self.trial.root_dir | 80 return self.trial.root_dir |
| 81 | 81 |
| 82 | 82 |
| 83 class TestCase(unittest.TestCase, TrialDirMixIn): | |
| 84 """Base unittest class that cleans off a trial directory in tearDown().""" | |
| 85 def setUp(self): | |
| 86 unittest.TestCase.setUp(self) | |
| 87 TrialDirMixIn.setUp(self) | |
| 88 | |
| 89 def tearDown(self): | |
| 90 TrialDirMixIn.tearDown(self) | |
| 91 unittest.TestCase.tearDown(self) | |
| 92 | |
| 93 | |
| 83 if '-l' in sys.argv: | 94 if '-l' in sys.argv: |
| 84 # See SHOULD_LEAK definition in TrialDir for its purpose. | 95 # See SHOULD_LEAK definition in TrialDir for its purpose. |
| 85 TrialDir.SHOULD_LEAK = True | 96 TrialDir.SHOULD_LEAK = True |
| 86 print 'Leaking!' | 97 print 'Leaking!' |
| 87 sys.argv.remove('-l') | 98 sys.argv.remove('-l') |
| OLD | NEW |