Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Side by Side Diff: tests/git_cl_test.py

Issue 1991563005: Add "archive" command to git_cl.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Rebase and modify unit tests accordingly. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« git_cl.py ('K') | « git_cl.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
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
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'),
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'),
tandrii(chromium) 2016/05/31 18:46:16 can you change this call to return '' instead of 4
Kevin M 2016/05/31 20:05:21 Done for a new branch "bar".
1466 ((['git', 'config', 'rietveld.server'],), ''),
1467 ((['git', 'config', 'rietveld.server'],), ''),
1468 ((['git', 'tag', 'submitted-foo-456', 'foo'],), ''),
1469 ((['git', 'branch', '-D', 'foo'],), '')]
1470
1471 class MockChangelist():
1472 def __init__(self, branch, issue):
1473 self.branch = branch
1474 self.issue = issue
1475 def GetBranch(self):
1476 return self.branch
1477 def GetIssue(self):
1478 return self.issue
1479
1480 self.mock(git_cl, 'get_cl_statuses',
1481 lambda branches, fine_grained, max_processes:
1482 [(MockChangelist('master', 1), 'open'),
1483 (MockChangelist('foo', 456), 'closed')])
1484
1485 git_cl.main(['cleanup', '-f'])
tandrii(chromium) 2016/05/31 18:46:16 assert this returns 0.
Kevin M 2016/05/31 20:05:21 Done.
1486
1457 1487
1458 if __name__ == '__main__': 1488 if __name__ == '__main__':
1459 git_cl.logging.basicConfig( 1489 git_cl.logging.basicConfig(
1460 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1490 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1461 unittest.main() 1491 unittest.main()
OLDNEW
« git_cl.py ('K') | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698