diff --git a/git_review/cmd.py b/git_review/cmd.py index 597ba224..fa852f57 100755 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -1008,8 +1008,8 @@ def list_reviews(remote): else: review_field_color = ("", "", "") color_reset = "" - review_field_format = ["%*s", "%*s", "%*s"] - review_field_justify = [+1, +1, -1] # +1 is justify to right + # > is right justify, < is left, field indices for py26 + review_field_format = ["{0:>{1}}", "{2:>{3}}", "{4:<{5}}"] review_list = [[r[f] for f in REVIEW_FIELDS] for r in reviews] review_field_width = dict() @@ -1026,20 +1026,15 @@ def list_reviews(remote): color_reset for i in FIELDS]) - review_field_width = [ - review_field_width[i] * review_field_justify[i] - for i in FIELDS] + review_field_width = [review_field_width[i] for i in FIELDS] for review_value in review_list: # At this point we have review_field_format - # like "%*s %*s %*s" and we need to supply - # (width1, value1, width2, value2, ...) tuple to print - # It's easy to zip() widths with actual values, - # but we need to flatten the resulting - # ((width1, value1), (width2, value2), ...) map. + # like "{:>{}} {:>{}} {:<{}}" and we need to supply + # (value1, width1, value2, width2, ...) tuple to print formatted_fields = [] for (width, value) in zip(review_field_width, review_value): - formatted_fields.extend([width, value.encode('utf-8')]) - print(review_field_format % tuple(formatted_fields)) + formatted_fields.extend([value, width]) + print(review_field_format.format(*formatted_fields)) print("Found %d items for review" % len(reviews)) return 0 diff --git a/git_review/tests/test_unit.py b/git_review/tests/test_unit.py index 3ef378b1..4a7570f9 100644 --- a/git_review/tests/test_unit.py +++ b/git_review/tests/test_unit.py @@ -102,6 +102,22 @@ class GitReviewConsole(testtools.TestCase, fixtures.TestWithFixtures): self.run_cmd_patcher.stop() super(GitReviewConsole, self).tearDown() + @mock.patch('git_review.cmd.query_reviews') + @mock.patch('git_review.cmd.get_remote_url', mock.MagicMock) + @mock.patch('git_review.cmd._has_color', False) + def test_list_reviews_output(self, mock_query): + + mock_query.return_value = self.reviews + with mock.patch('sys.stdout', new_callable=io.StringIO) as output: + cmd.list_reviews(None) + console_output = output.getvalue().split('\n') + + self.assertEqual( + ['1010101 master A simple short subject', + ' 9877 stable/codeword A longer and slightly more wordy ' + 'subject'], + console_output[:2]) + @mock.patch('git_review.cmd.query_reviews') @mock.patch('git_review.cmd.get_remote_url', mock.MagicMock) @mock.patch('git_review.cmd._has_color', False)