From 92decf96dda3704c3a303399e0e7a0920e130b95 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 2 Jun 2016 17:46:37 +1200 Subject: [PATCH] Add expect_log to the pathod test truss, and use it for last_log --- pathod/test.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pathod/test.py b/pathod/test.py index 23b7a5b65..7e597a727 100644 --- a/pathod/test.py +++ b/pathod/test.py @@ -1,5 +1,7 @@ from six.moves import cStringIO as StringIO import threading +import time + from six.moves import queue import requests @@ -49,11 +51,23 @@ class Daemon: def text_log(self): return self.logfp.getvalue() + def expect_log(self, n, timeout=1): + l = [] + start = time.time() + while True: + l = self.log() + print l + if time.time() - start >= timeout: + return None + if len(l) >= n: + break + return l + def last_log(self): """ Returns the last logged request, or None. """ - l = self.log() + l = self.expect_log(1) if not l: return None return l[0]