Index: tests/git_cl_test.py |
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py |
index 571be654aa717d37e5f4fa1fd8680a1529d904cd..f23935b0bc5610823c1dd9a4decf1987f64e4677 100755 |
--- a/tests/git_cl_test.py |
+++ b/tests/git_cl_test.py |
@@ -21,6 +21,19 @@ import git_common |
import git_footers |
import subprocess2 |
+class ChangelistMock(object): |
+ # A class variable so we can access it when we don't have access to the |
+ # instance that's being set. |
+ desc = "" |
+ def __init__(self, **kwargs): |
+ pass |
+ def GetIssue(self): |
+ return 1 |
+ def GetDescription(self): |
+ return ChangelistMock.desc |
+ def UpdateDescription(self, desc): |
+ ChangelistMock.desc = desc |
+ |
class PresubmitMock(object): |
def __init__(self, *args, **kwargs): |
self.reviewers = [] |
@@ -1385,15 +1398,8 @@ class TestGitCl(TestCase): |
out = StringIO.StringIO() |
self.mock(git_cl.sys, 'stdout', out) |
- class MockChangelist(): |
- def __init__(self, **kwargs): |
- pass |
- def GetIssue(self): |
- return 1 |
- def GetDescription(self): |
- return 'foo' |
- |
- self.mock(git_cl, 'Changelist', MockChangelist) |
+ self.mock(git_cl, 'Changelist', ChangelistMock) |
+ ChangelistMock.desc = 'foo\n' |
self.assertEqual(0, git_cl.main(['description', '-d'])) |
self.assertEqual('foo\n', out.getvalue()) |
@@ -1423,6 +1429,26 @@ class TestGitCl(TestCase): |
'description', 'https://code.review.org/123123', '-d', '--gerrit'])) |
self.assertEqual('foobar\n', out.getvalue()) |
+ def test_description_set_raw(self): |
+ out = StringIO.StringIO() |
+ self.mock(git_cl.sys, 'stdout', out) |
+ |
+ self.mock(git_cl, 'Changelist', ChangelistMock) |
+ self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hihi')) |
+ |
+ self.assertEqual(0, git_cl.main(['description', '-n', 'hihi'])) |
+ self.assertEqual('hihi', ChangelistMock.desc) |
+ |
+ def test_description_set_stdin(self): |
+ out = StringIO.StringIO() |
+ self.mock(git_cl.sys, 'stdout', out) |
+ |
+ self.mock(git_cl, 'Changelist', ChangelistMock) |
+ self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman')) |
+ |
+ self.assertEqual(0, git_cl.main(['description', '-n', '-'])) |
+ self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc) |
+ |
if __name__ == '__main__': |
git_cl.logging.basicConfig( |