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 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1389 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), | 1389 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
1390 ((['git', 'config', 'branch.feature.rietveldissue'],), ''), | 1390 ((['git', 'config', 'branch.feature.rietveldissue'],), ''), |
1391 ((['git', 'config', 'branch.feature.gerritissue'],), '123'), | 1391 ((['git', 'config', 'branch.feature.gerritissue'],), '123'), |
1392 ((['git', 'config', 'branch.feature.gerritserver'],), | 1392 ((['git', 'config', 'branch.feature.gerritserver'],), |
1393 'https://chromium-review.googlesource.com'), | 1393 'https://chromium-review.googlesource.com'), |
1394 ((['SetReview', 'chromium-review.googlesource.com', 123, | 1394 ((['SetReview', 'chromium-review.googlesource.com', 123, |
1395 {'Commit-Queue': 1}],), ''), | 1395 {'Commit-Queue': 1}],), ''), |
1396 ] | 1396 ] |
1397 # TODO(tandrii): consider testing just set-commit and set-commit --clear, | 1397 # TODO(tandrii): consider testing just set-commit and set-commit --clear, |
1398 # but without copy-pasting tons of expectations, as modifying them later is | 1398 # but without copy-pasting tons of expectations, as modifying them later is |
1399 # super tedious. | 1399 #super tedious. |
M-A Ruel
2016/06/01 12:43:17
oops
Kevin M
2016/06/01 17:49:05
Done.
| |
1400 self.assertEqual(0, git_cl.main(['set-commit', '-d'])) | 1400 self.assertEqual(0, git_cl.main(['set-commit', '-d'])) |
1401 | 1401 |
1402 def test_description_display(self): | 1402 def test_description_display(self): |
1403 out = StringIO.StringIO() | 1403 out = StringIO.StringIO() |
1404 self.mock(git_cl.sys, 'stdout', out) | 1404 self.mock(git_cl.sys, 'stdout', out) |
1405 | 1405 |
1406 self.mock(git_cl, 'Changelist', ChangelistMock) | 1406 self.mock(git_cl, 'Changelist', ChangelistMock) |
1407 ChangelistMock.desc = 'foo\n' | 1407 ChangelistMock.desc = 'foo\n' |
1408 | 1408 |
1409 self.assertEqual(0, git_cl.main(['description', '-d'])) | 1409 self.assertEqual(0, git_cl.main(['description', '-d'])) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1447 def test_description_set_stdin(self): | 1447 def test_description_set_stdin(self): |
1448 out = StringIO.StringIO() | 1448 out = StringIO.StringIO() |
1449 self.mock(git_cl.sys, 'stdout', out) | 1449 self.mock(git_cl.sys, 'stdout', out) |
1450 | 1450 |
1451 self.mock(git_cl, 'Changelist', ChangelistMock) | 1451 self.mock(git_cl, 'Changelist', ChangelistMock) |
1452 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman')) | 1452 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman')) |
1453 | 1453 |
1454 self.assertEqual(0, git_cl.main(['description', '-n', '-'])) | 1454 self.assertEqual(0, git_cl.main(['description', '-n', '-'])) |
1455 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc) | 1455 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc) |
1456 | 1456 |
1457 def test_cleanup(self): | |
1458 self.calls = \ | |
1459 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), | |
1460 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'), | |
1461 ((['git', 'config', 'branch.master.rietveldissue'],), '1'), | |
1462 ((['git', 'config', 'rietveld.autoupdate'],), ''), | |
1463 ((['git', 'config', 'rietveld.server'],), ''), | |
1464 ((['git', 'config', 'rietveld.server'],), ''), | |
1465 ((['git', 'config', 'branch.foo.rietveldissue'],), '456'), | |
1466 ((['git', 'config', 'rietveld.server'],), ''), | |
1467 ((['git', 'config', 'rietveld.server'],), ''), | |
1468 ((['git', 'config', 'branch.bar.rietveldissue'],), ''), | |
1469 ((['git', 'config', 'branch.bar.gerritissue'],), '789'), | |
1470 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | |
1471 ((['git', 'tag', 'git-cl-closed-456-foo', 'foo'],), ''), | |
1472 ((['git', 'branch', '-D', 'foo'],), '')] | |
1473 | |
1474 class MockChangelist(): | |
1475 def __init__(self, branch, issue): | |
1476 self.branch = branch | |
1477 self.issue = issue | |
1478 def GetBranch(self): | |
1479 return self.branch | |
1480 def GetIssue(self): | |
1481 return self.issue | |
1482 | |
1483 self.mock(git_cl, 'get_cl_statuses', | |
1484 lambda branches, fine_grained, max_processes: | |
1485 [(MockChangelist('master', 1), 'open'), | |
1486 (MockChangelist('foo', 456), 'closed'), | |
1487 (MockChangelist('bar', 789), 'open')]) | |
1488 | |
1489 self.assertEqual(0, git_cl.main(['cleanup', '-f'])) | |
1490 | |
1491 def test_cleanup_current_branch_fails(self): | |
1492 self.calls = \ | |
1493 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), | |
1494 'refs/heads/master'), | |
1495 ((['git', 'config', 'branch.master.rietveldissue'],), '1'), | |
1496 ((['git', 'config', 'rietveld.autoupdate'],), ''), | |
1497 ((['git', 'config', 'rietveld.server'],), ''), | |
1498 ((['git', 'config', 'rietveld.server'],), ''), | |
1499 ((['git', 'symbolic-ref', 'HEAD'],), 'master')] | |
1500 | |
1501 class MockChangelist(): | |
1502 def __init__(self, branch, issue): | |
1503 self.branch = branch | |
1504 self.issue = issue | |
1505 def GetBranch(self): | |
1506 return self.branch | |
1507 def GetIssue(self): | |
1508 return self.issue | |
1509 | |
1510 self.mock(git_cl, 'get_cl_statuses', | |
1511 lambda branches, fine_grained, max_processes: | |
1512 [(MockChangelist('master', 1), 'closed')]) | |
1513 | |
1514 self.assertEqual(1, git_cl.main(['cleanup', '-f'])) | |
1457 | 1515 |
1458 if __name__ == '__main__': | 1516 if __name__ == '__main__': |
1459 git_cl.logging.basicConfig( | 1517 git_cl.logging.basicConfig( |
1460 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1518 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
1461 unittest.main() | 1519 unittest.main() |
OLD | NEW |