def test_add_callback_incorrect_type(self): p = Progress(5) not_a_progress_handler = "I'm a string!" with self.assertRaises(ValueError): p.add_progress_handler(not_a_progress_handler)
def test_callbacks(self): cb1 = mock.create_autospec(ProgressHandler) cb2 = mock.create_autospec(ProgressHandler) callbacks = [cb1, cb2] def assert_call(expected_completion, expected_step, expected_msg): for m in callbacks: m.progress_update.assert_called_once() m.reset_mock() p = Progress(5) p.add_progress_handler(cb1) p.add_progress_handler(cb2) p.update(msg="First") assert_call(0.167, 1, "First") p.update(steps=2, msg="Second") assert_call(0.5, 3, "Second") p.update(msg="Third") assert_call(0.667, 4, "Third") p.update(msg="Last") assert_call(0.833, 5, "Last") p.mark_complete() assert_call(1.0, 6, "complete")