summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2012-06-23 08:11:15 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2012-06-23 08:11:15 -0700
commite0fce8706d31f104f781676b49e7fe0df83438e0 (patch)
treeb6c7f17c8fa9121e0eded89182b28f4b51de6127 /tests
parente1b74d00945ae772300432a51a71e735143c8905 (diff)
Switch to using context managers for acquiring and releasing locks.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/mail/tests.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
index cdd6dd1b9e..2215f56523 100644
--- a/tests/regressiontests/mail/tests.py
+++ b/tests/regressiontests/mail/tests.py
@@ -603,21 +603,16 @@ class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):
maddr = email.Utils.parseaddr(m.get('from'))[1]
if mailfrom != maddr:
return "553 '%s' != '%s'" % (mailfrom, maddr)
- self.sink_lock.acquire()
- self._sink.append(m)
- self.sink_lock.release()
+ with self.sink_lock:
+ self._sink.append(m)
def get_sink(self):
- self.sink_lock.acquire()
- try:
+ with self.sink_lock:
return self._sink[:]
- finally:
- self.sink_lock.release()
def flush_sink(self):
- self.sink_lock.acquire()
- self._sink[:] = []
- self.sink_lock.release()
+ with self.sink_lock:
+ self._sink[:] = []
def start(self):
assert not self.active
@@ -629,9 +624,8 @@ class FakeSMTPServer(smtpd.SMTPServer, threading.Thread):
self.active = True
self.__flag.set()
while self.active and asyncore.socket_map:
- self.active_lock.acquire()
- asyncore.loop(timeout=0.1, count=1)
- self.active_lock.release()
+ with self.active_lock:
+ asyncore.loop(timeout=0.1, count=1)
asyncore.close_all()
def stop(self):