/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/fixtures.py

  • Committer: Martin Pool
  • Date: 2011-11-28 08:21:22 UTC
  • mto: This revision was merged to the branch mainline in revision 6320.
  • Revision ID: mbp@canonical.com-20111128082122-ockiau9ltbgb6thh
Add selftest.timeout option, defaulting to 600

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
    testcase.build_tree_contents([('t/hello', 'hello world')])
139
139
    tree.add(['hello'], ['hello-id'])
140
140
    return tree
 
141
 
 
142
 
 
143
class TimeoutFixture(object):
 
144
    """Kill a test with sigalarm if it runs too long.
 
145
    
 
146
    Only works on Unix.
 
147
    """
 
148
 
 
149
    def __init__(self, timeout_secs):
 
150
        self.timeout_secs = timeout_secs
 
151
 
 
152
    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)
 
158
 
 
159
    def cleanUp(self):
 
160
        if self.alarm_fn is None:
 
161
            return  # Windows etc
 
162
        self.alarm_fn(0)