From 60041f3f793c1b1f285f781d0ccec34e352d4c0c Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 8 Feb 2024 19:44:54 +0000 Subject: [PATCH] Add unit tests for command line progress These test both percentage steps and a spinner where the number of steps is unknown. --- gramps/cli/test/user_test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gramps/cli/test/user_test.py b/gramps/cli/test/user_test.py index 73029210d3d..1b5322819a0 100644 --- a/gramps/cli/test/user_test.py +++ b/gramps/cli/test/user_test.py @@ -173,6 +173,26 @@ def _progress_begin_step_end(self): self.user.step_progress() self.user.end_progress() + def test_progress_percent(self): + self.user.begin_progress("Foo", "Bar", 20) + self.user._fileout.write.assert_called_with("Bar") + for i in range(20): + self.user.step_progress() + pct = (i + 1) * 5 + self.user._fileout.write.assert_called_with("\r{:3d}% ".format(pct)) + self.user.end_progress() + self.user._fileout.write.assert_called_with("\n") + + def test_progress_spinner(self): + self.user.begin_progress("Foo", "Bar", 0) + self.user._fileout.write.assert_called_with("Bar") + for i in range(5): + self.user.step_progress() + spn = user._SPINNER[(i + 1) % 4] + self.user._fileout.write.assert_called_with("\r {} ".format(spn)) + self.user.end_progress() + self.user._fileout.write.assert_called_with("\n") + if __name__ == "__main__": unittest.main()