Example #1
0
    def test_multi_step_early_completion(self):
        # Default to estimating a single step
        p = Progress(num_steps=2)

        self.assertEqual(p.end_step, 2)
        self.assertEqual(len(p.progress_history), 1)
        self.assertEqual(p.completion(), 0.0)

        p.update(msg="Estimate how complex I am")

        self.assertEqual(p.end_step, 2)
        self.assertEqual(len(p.progress_history), 2)
        self.assertEqual(p.completion(), 0.5)

        # First step to execute may decide that more steps are required
        p.add_estimated_steps(10)

        self.assertEqual(p.end_step, 12)
        self.assertEqual(len(p.progress_history), 2)
        self.assertEqual(p.completion(), 0.083)

        p.update(steps=2, msg="Do two things")

        self.assertEqual(len(p.progress_history), 3)
        self.assertEqual(p.completion(), 0.25)

        # Finish early
        p.mark_complete()

        self.assertEqual(len(p.progress_history), 4)
        self.assertEqual(p.completion(), 1.0)
Example #2
0
def _execute_seq(data, angle: float, progress: Progress):
    progress = Progress.ensure_instance(progress, num_steps=data.shape[0], task_name='Rotate Stack')

    with progress:
        img_count = data.shape[0]
        progress.add_estimated_steps(img_count)
        for idx in range(0, img_count):
            data[idx] = _rotate_image(data[idx], angle)
            progress.update(1, f"Rotating by {angle}")

    return data
Example #3
0
    def test_cancellation(self):
        p = Progress()
        p.add_estimated_steps(10)

        with p:
            for i in range(10):
                if i < 6:
                    p.update()

                    if i == 5:
                        p.cancel("nope")
                        self.assertTrue(p.should_cancel)

                else:
                    with self.assertRaises(RuntimeError):
                        p.update()

        self.assertFalse(p.is_completed())
        self.assertTrue(p.should_cancel)