Chromium Code Reviews| 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 1367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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): | 1384 def test_description_display(self): |
| 1385 out = StringIO.StringIO() | 1385 out = StringIO.StringIO() |
| 1386 self.mock(git_cl.sys, 'stdout', out) | 1386 self.mock(git_cl.sys, 'stdout', out) |
| 1387 | 1387 |
| 1388 class MockChangelist(): | 1388 class MockChangelist(): |
|
tandrii(chromium)
2016/04/28 05:13:56
i think it's time to kick this outside of this thi
martiniss
2016/04/28 20:51:38
Done.
| |
| 1389 def __init__(self, **kwargs): | 1389 def __init__(self, **kwargs): |
| 1390 pass | 1390 pass |
| 1391 def GetIssue(self): | 1391 def GetIssue(self): |
| 1392 return 1 | 1392 return 1 |
| 1393 def GetDescription(self): | 1393 def GetDescription(self): |
| 1394 return 'foo' | 1394 return 'foo' |
| 1395 | 1395 |
| 1396 self.mock(git_cl, 'Changelist', MockChangelist) | 1396 self.mock(git_cl, 'Changelist', MockChangelist) |
| 1397 | 1397 |
| 1398 self.assertEqual(0, git_cl.main(['description', '-d'])) | 1398 self.assertEqual(0, git_cl.main(['description', '-d'])) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1416 def test_description_gerrit(self): | 1416 def test_description_gerrit(self): |
| 1417 out = StringIO.StringIO() | 1417 out = StringIO.StringIO() |
| 1418 self.mock(git_cl.sys, 'stdout', out) | 1418 self.mock(git_cl.sys, 'stdout', out) |
| 1419 self.mock(git_cl.Changelist, 'GetDescription', | 1419 self.mock(git_cl.Changelist, 'GetDescription', |
| 1420 lambda *args: 'foobar') | 1420 lambda *args: 'foobar') |
| 1421 | 1421 |
| 1422 self.assertEqual(0, git_cl.main([ | 1422 self.assertEqual(0, git_cl.main([ |
| 1423 'description', 'https://code.review.org/123123', '-d', '--gerrit'])) | 1423 'description', 'https://code.review.org/123123', '-d', '--gerrit'])) |
| 1424 self.assertEqual('foobar\n', out.getvalue()) | 1424 self.assertEqual('foobar\n', out.getvalue()) |
| 1425 | 1425 |
| 1426 def test_description_set_raw(self): | |
| 1427 out = StringIO.StringIO() | |
| 1428 self.mock(git_cl.sys, 'stdout', out) | |
| 1429 | |
| 1430 set_desc = [] | |
| 1431 class MockChangelist(): | |
| 1432 def __init__(self, **kwargs): | |
| 1433 pass | |
| 1434 def GetIssue(self): | |
| 1435 return 1 | |
| 1436 def GetDescription(self): | |
| 1437 return 'foo' | |
| 1438 def UpdateDescription(self, desc): | |
| 1439 set_desc.append(desc) | |
| 1440 | |
| 1441 self.mock(git_cl, 'Changelist', MockChangelist) | |
| 1442 | |
| 1443 self.assertEqual(0, git_cl.main(['description', '-n', 'hihi'])) | |
| 1444 self.assertEqual('hihi', set_desc[0]) | |
| 1445 | |
| 1446 def test_description_set_stdin(self): | |
| 1447 out = StringIO.StringIO() | |
| 1448 self.mock(git_cl.sys, 'stdout', out) | |
| 1449 | |
| 1450 set_desc = [] | |
| 1451 class MockChangelist(): | |
| 1452 def __init__(self, **kwargs): | |
| 1453 pass | |
| 1454 def GetIssue(self): | |
| 1455 return 1 | |
| 1456 def GetDescription(self): | |
| 1457 return 'foo' | |
| 1458 def UpdateDescription(self, desc): | |
| 1459 set_desc.append(desc) | |
| 1460 | |
| 1461 self.mock(git_cl, 'Changelist', MockChangelist) | |
| 1462 self.mock(git_cl.sys, 'stdin', ['hi', 'there']) | |
| 1463 | |
| 1464 self.assertEqual(0, git_cl.main(['description', '-n', '-'])) | |
| 1465 self.assertEqual('hi\nthere', set_desc[0]) | |
| 1466 | |
| 1426 | 1467 |
| 1427 if __name__ == '__main__': | 1468 if __name__ == '__main__': |
| 1428 git_cl.logging.basicConfig( | 1469 git_cl.logging.basicConfig( |
| 1429 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1470 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 1430 unittest.main() | 1471 unittest.main() |
| OLD | NEW |