def testPF_get_progress(self): """ Tests set/get_progress of ProgressiveFuture """ f = ProgressiveFuture() now = time.time() start, end = now + 1, now + 2 # try to update progress f.set_progress(start, end) startf, endf = f.get_progress() self.assertEqual(start, startf) self.assertEqual(end, endf) # "start" the task f.set_running_or_notify_cancel() startf, endf = f.get_progress() self.assertLessEqual(startf, time.time()) self.assertEqual(end, endf) time.sleep(0.1) # "finish" the task f.set_result(None) self.assertTrue(f.done()) startf, endf = f.get_progress() self.assertLessEqual(startf, time.time()) self.assertLessEqual(endf, time.time())
def test_get_progress(self): """Tests retrieving the progress from the future.""" f = ProgressiveFuture() now = time.time() start, end = now + 1, now + 2 f.set_progress(start, end) # update progress start_f, end_f = f.get_progress() # retrieve progress # check progress returned is same as progress set beforehand self.assertEqual(start, start_f) self.assertEqual(end, end_f) # "start" the task (set the future running) f.set_running_or_notify_cancel() # updates start and end start_f, end_f = f.get_progress() # retrieve the progress now = time.time() # check that start is a tiny bit before now self.assertLessEqual(start_f, time.time()) # check that expected duration is still 1s as task should take 1s self.assertAlmostEqual(start_f + 1, end_f) # check that the estimated end time of the futures has been updated expected_end = now + 1 self.assertTrue(expected_end - 0.1 <= end_f <= expected_end + 0.1) # end should be 1s in the future time.sleep(0.1) # wait a bit # "finish" the task f.set_result(None) self.assertTrue(f.done()) start_f, end_f = f.get_progress() # check that start is now in the past as future started in the past self.assertLessEqual(start_f, time.time()) # check that end is also now in the past as future already finished self.assertLessEqual(end_f, time.time())