~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/fixtures.py

  • Committer: Martin Pool
  • Date: 2011-11-29 00:50:36 UTC
  • mto: This revision was merged to the branch mainline in revision 6320.
  • Revision ID: mbp@canonical.com-20111129005036-1vopao4wm0yo9ekn
Slight cleanup of TimeoutFixture

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
class TimeoutFixture(object):
144
144
    """Kill a test with sigalarm if it runs too long.
145
145
    
146
 
    Only works on Unix.
 
146
    Only works on Unix at present.
147
147
    """
148
148
 
149
149
    def __init__(self, timeout_secs):
 
150
        import signal
150
151
        self.timeout_secs = timeout_secs
 
152
        self.alarm_fn = getattr(signal, 'alarm', None)
151
153
 
152
154
    def setUp(self):
153
 
        import signal
154
 
        self.alarm_fn = getattr(signal, 'alarm', None)
155
 
        if self.alarm_fn is None:
156
 
            return  # Windows etc
157
 
        self.alarm_fn(self.timeout_secs)
 
155
        if self.alarm_fn is not None:
 
156
            self.alarm_fn(self.timeout_secs)
158
157
 
159
158
    def cleanUp(self):
160
 
        if self.alarm_fn is None:
161
 
            return  # Windows etc
162
 
        self.alarm_fn(0)
 
159
        if self.alarm_fn is not None:
 
160
            self.alarm_fn(0)