[common] include duration in 'wait()' output
This commit is contained in:
@@ -343,9 +343,16 @@ class Extractor():
|
||||
return
|
||||
|
||||
if reason:
|
||||
t = dt.datetime.fromtimestamp(until).time()
|
||||
isotime = f"{t.hour:02}:{t.minute:02}:{t.second:02}"
|
||||
self.log.info("Waiting until %s (%s)", isotime, reason)
|
||||
if seconds >= 3600.0:
|
||||
h, m = divmod(seconds, 3600.0)
|
||||
dur = f"{int(h)}h {int(m/60.0)}min"
|
||||
elif seconds >= 60.0:
|
||||
dur = str(int(seconds/60.0)) + " minutes"
|
||||
else:
|
||||
dur = str(int(seconds)) + " seconds"
|
||||
t = time.localtime(until)
|
||||
iso = f"{t.tm_hour:02}:{t.tm_min:02}:{t.tm_sec:02}"
|
||||
self.log.info("Waiting for %s until %s (%s)", dur, iso, reason)
|
||||
time.sleep(seconds)
|
||||
|
||||
def sleep(self, seconds, reason):
|
||||
|
||||
@@ -217,7 +217,23 @@ class TestExtractorWait(unittest.TestCase):
|
||||
|
||||
calls = log.info.mock_calls
|
||||
self.assertEqual(len(calls), 1)
|
||||
self._assert_isotime(calls[0][1][1], until)
|
||||
self.assertEqual(calls[0][1][1], "6 seconds")
|
||||
self._assert_isotime(calls[0][1][2], until)
|
||||
|
||||
def test_wait_seconds_long(self):
|
||||
extr = extractor.find("generic:https://example.org/")
|
||||
seconds = 5000
|
||||
until = time.time() + seconds
|
||||
|
||||
with patch("time.sleep") as sleep, patch.object(extr, "log") as log:
|
||||
extr.wait(seconds=seconds)
|
||||
|
||||
sleep.assert_called_once_with(5001.0)
|
||||
|
||||
calls = log.info.mock_calls
|
||||
self.assertEqual(len(calls), 1)
|
||||
self.assertEqual(calls[0][1][1], "1h 23min")
|
||||
self._assert_isotime(calls[0][1][2], until)
|
||||
|
||||
def test_wait_until(self):
|
||||
extr = extractor.find("generic:https://example.org/")
|
||||
@@ -232,7 +248,8 @@ class TestExtractorWait(unittest.TestCase):
|
||||
|
||||
calls = log.info.mock_calls
|
||||
self.assertEqual(len(calls), 1)
|
||||
self._assert_isotime(calls[0][1][1], until)
|
||||
self.assertEqual(calls[0][1][1], "5 seconds")
|
||||
self._assert_isotime(calls[0][1][2], until)
|
||||
|
||||
def test_wait_until_datetime(self):
|
||||
extr = extractor.find("generic:https://example.org/")
|
||||
@@ -251,7 +268,8 @@ class TestExtractorWait(unittest.TestCase):
|
||||
|
||||
calls = log.info.mock_calls
|
||||
self.assertEqual(len(calls), 1)
|
||||
self._assert_isotime(calls[0][1][1], until_local)
|
||||
self.assertEqual(calls[0][1][1], "5 seconds")
|
||||
self._assert_isotime(calls[0][1][2], until_local)
|
||||
|
||||
def _assert_isotime(self, output, until):
|
||||
if not isinstance(until, dt.datetime):
|
||||
|
||||
Reference in New Issue
Block a user