summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarragh Bailey <daragh.bailey@gmail.com>2014-06-21 17:18:38 +0100
committerDarragh Bailey <daragh.bailey@gmail.com>2014-07-13 01:35:41 +0100
commitaa3d861126233b5963514a9b8d861f05dc6b04d5 (patch)
tree3e0200c2d46b0b4a65c1ef880e87997b7539ddb2
parent28104e4ecdfb063ad434e626231ffbc836593b6e (diff)
downloadgit-review-aa3d861126233b5963514a9b8d861f05dc6b04d5.tar.gz
Prevent long subjects in reviews causing spurious blank lines
If the last field of the review being listed exceeds the width of the console, then using whitespace padding will result in sufficient spacing being added to all other line that will appear as spurious blank lines if they were otherwise less than the console width. Instead of: 1234 master <subject> 5678 master <really-long-subject-that- wraps-to-next-line> Display: 1234 master <subject> 5678 master <really-long-subject-that- wraps-to-next-line> Change-Id: I290f652f803cf3938a1bdb72c20c85969dbb3319
-rwxr-xr-xgit_review/cmd.py8
-rw-r--r--git_review/tests/test_unit.py68
-rw-r--r--test-requirements.txt2
3 files changed, 75 insertions, 3 deletions
diff --git a/git_review/cmd.py b/git_review/cmd.py
index c0745b2..6546f1d 100755
--- a/git_review/cmd.py
+++ b/git_review/cmd.py
@@ -797,12 +797,16 @@ def list_reviews(remote):
review_field_color = ("", "", "")
color_reset = ""
review_field_format = ["%*s", "%*s", "%*s"]
- review_field_justify = [+1, +1, -1] # -1 is justify to right
+ review_field_justify = [+1, +1, -1] # +1 is justify to right
review_list = [[r[f] for f in REVIEW_FIELDS] for r in reviews]
review_field_width = dict()
- for i in FIELDS:
+ # assume last field is longest and may exceed the console width in which
+ # case using the maximum value will result in extra blank lines appearing
+ # after each entry even when only one field exceeds the console width
+ for i in FIELDS[:-1]:
review_field_width[i] = max(len(r[i]) for r in review_list)
+ review_field_width[len(FIELDS) - 1] = 1
review_field_format = " ".join([
review_field_color[i] +
diff --git a/git_review/tests/test_unit.py b/git_review/tests/test_unit.py
new file mode 100644
index 0000000..c20149e
--- /dev/null
+++ b/git_review/tests/test_unit.py
@@ -0,0 +1,68 @@
+# -*- coding: utf8 -*-
+
+# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Use of io.StringIO in python =< 2.7 requires all strings handled to be
+# unicode. See if StringIO.StringIO is available first
+try:
+ import StringIO as io
+except ImportError:
+ import io
+import textwrap
+
+import mock
+import testtools
+
+import git_review
+
+
+class GitReviewConsole(testtools.TestCase):
+ """Class for testing the console output of git-review."""
+
+ reviews = [
+ {
+ 'number': '1010101',
+ 'branch': 'master',
+ 'subject': 'A simple short subject'
+ }, {
+ 'number': '9877',
+ 'branch': 'stable/codeword',
+ 'subject': 'A longer and slightly more wordy subject'
+ }, {
+ 'number': '12345',
+ 'branch': 'master',
+ 'subject': 'A ridiculously long subject that can exceed the '
+ 'normal console width, just need to ensure the '
+ 'max width is short enough'
+ }]
+
+ @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_no_blanks(self, mock_query):
+
+ mock_query.return_value = self.reviews
+ with mock.patch('sys.stdout', new_callable=io.StringIO) as output:
+ git_review.cmd.list_reviews(None)
+ console_output = output.getvalue().split('\n')
+
+ wrapper = textwrap.TextWrapper(replace_whitespace=False,
+ drop_whitespace=False)
+ for text in console_output:
+ for line in wrapper.wrap(text):
+ self.assertEqual(line.isspace(), False,
+ "Extra blank lines appearing between reviews"
+ "in console output")
diff --git a/test-requirements.txt b/test-requirements.txt
index 44b948d..8a458d1 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,6 +1,6 @@
hacking>=0.9.2,<0.10
discover
-
+mock
fixtures>=0.3.14
testrepository>=0.0.18
testtools>=0.9.34