OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Unit tests for git_cl.py.""" | 6 """Unit tests for git_cl.py.""" |
7 | 7 |
8 import os | 8 import os |
9 import StringIO | 9 import StringIO |
10 import stat | 10 import stat |
(...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 ((['git', 'config', 'branch.feature.gerritserver'],), | 1374 ((['git', 'config', 'branch.feature.gerritserver'],), |
1375 'https://chromium-review.googlesource.com'), | 1375 'https://chromium-review.googlesource.com'), |
1376 ((['SetReview', 'chromium-review.googlesource.com', 123, | 1376 ((['SetReview', 'chromium-review.googlesource.com', 123, |
1377 {'Commit-Queue': 1}],), ''), | 1377 {'Commit-Queue': 1}],), ''), |
1378 ] | 1378 ] |
1379 # TODO(tandrii): consider testing just set-commit and set-commit --clear, | 1379 # TODO(tandrii): consider testing just set-commit and set-commit --clear, |
1380 # but without copy-pasting tons of expectations, as modifying them later is | 1380 # but without copy-pasting tons of expectations, as modifying them later is |
1381 # super tedious. | 1381 # super tedious. |
1382 self.assertEqual(0, git_cl.main(['set-commit', '-d'])) | 1382 self.assertEqual(0, git_cl.main(['set-commit', '-d'])) |
1383 | 1383 |
| 1384 def test_description_display(self): |
| 1385 out = StringIO.StringIO() |
| 1386 self.mock(git_cl.sys, 'stdout', out) |
| 1387 |
| 1388 class MockChangelist(): |
| 1389 def __init__(self, **kwargs): |
| 1390 pass |
| 1391 def GetIssue(self): |
| 1392 return 1 |
| 1393 def GetDescription(self): |
| 1394 return 'foo' |
| 1395 |
| 1396 self.mock(git_cl, 'Changelist', MockChangelist) |
| 1397 |
| 1398 self.assertEqual(0, git_cl.main(['description', '-d'])) |
| 1399 self.assertEqual('foo\n', out.getvalue()) |
| 1400 |
| 1401 def test_description_rietveld(self): |
| 1402 out = StringIO.StringIO() |
| 1403 self.mock(git_cl.sys, 'stdout', out) |
| 1404 self.mock(git_cl.Changelist, 'GetDescription', |
| 1405 lambda *args: 'foobar') |
| 1406 |
| 1407 self.calls = [ |
| 1408 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 1409 ((['git', 'config', 'rietveld.server'],), ''), |
| 1410 ((['git', 'config', 'rietveld.server'],), ''), |
| 1411 ] |
| 1412 self.assertEqual(0, git_cl.main([ |
| 1413 'description', 'https://code.review.org/123123', '-d', '--rietveld'])) |
| 1414 self.assertEqual('foobar\n', out.getvalue()) |
| 1415 |
| 1416 def test_description_gerrit(self): |
| 1417 out = StringIO.StringIO() |
| 1418 self.mock(git_cl.sys, 'stdout', out) |
| 1419 self.mock(git_cl.Changelist, 'GetDescription', |
| 1420 lambda *args: 'foobar') |
| 1421 |
| 1422 self.assertEqual(0, git_cl.main([ |
| 1423 'description', 'https://code.review.org/123123', '-d', '--gerrit'])) |
| 1424 self.assertEqual('foobar\n', out.getvalue()) |
| 1425 |
1384 | 1426 |
1385 if __name__ == '__main__': | 1427 if __name__ == '__main__': |
1386 git_cl.logging.basicConfig( | 1428 git_cl.logging.basicConfig( |
1387 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1429 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
1388 unittest.main() | 1430 unittest.main() |
OLD | NEW |