Skip to content

Commit

Permalink
Add unit tests for command line progress
Browse files Browse the repository at this point in the history
These test both percentage steps and a spinner where the number
of steps is unknown.
  • Loading branch information
Nick-Hall committed Feb 8, 2024
1 parent 3e19b5f commit 60041f3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions gramps/cli/test/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 60041f3

Please sign in to comment.