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 gclient_scm.py.""" | 6 """Unit tests for gclient_scm.py.""" |
7 | 7 |
8 # pylint: disable=E1103 | 8 # pylint: disable=E1103 |
9 | 9 |
10 # Import before super_mox to keep valid references. | 10 # Import before super_mox to keep valid references. |
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 | 1406 |
1407 origin_root_dir = self.root_dir | 1407 origin_root_dir = self.root_dir |
1408 self.root_dir = tempfile.mkdtemp() | 1408 self.root_dir = tempfile.mkdtemp() |
1409 self.relpath = '.' | 1409 self.relpath = '.' |
1410 self.base_path = join(self.root_dir, self.relpath) | 1410 self.base_path = join(self.root_dir, self.relpath) |
1411 | 1411 |
1412 scm = gclient_scm.CreateSCM(url=origin_root_dir, | 1412 scm = gclient_scm.CreateSCM(url=origin_root_dir, |
1413 root_dir=self.root_dir, | 1413 root_dir=self.root_dir, |
1414 relpath=self.relpath) | 1414 relpath=self.relpath) |
1415 | 1415 |
| 1416 expected_file_list = [join(self.base_path, "a"), |
| 1417 join(self.base_path, "b")] |
1416 file_list = [] | 1418 file_list = [] |
1417 options.revision = 'unmanaged' | 1419 options.revision = 'unmanaged' |
1418 scm.update(options, (), file_list) | 1420 scm.update(options, (), file_list) |
1419 | 1421 |
1420 self.assertEquals(file_list, []) | 1422 self.assertEquals(file_list, expected_file_list) |
1421 self.assertRaises(subprocess2.CalledProcessError, | 1423 self.assertEquals(scm.revinfo(options, (), None), |
1422 scm.revinfo, options, (), None) | 1424 '069c602044c5388d2d15c3f875b057c852003458') |
1423 | |
1424 # indicates detached HEAD | 1425 # indicates detached HEAD |
1425 self.assertRaises(subprocess2.CalledProcessError, self.getCurrentBranch) | 1426 self.assertEquals(self.getCurrentBranch(), None) |
1426 self.checkInStdout('unmanaged solution; skipping') | 1427 self.checkInStdout( |
| 1428 'Checked out refs/remotes/origin/master to a detached HEAD') |
1427 | 1429 |
1428 rmtree(origin_root_dir) | 1430 rmtree(origin_root_dir) |
1429 | 1431 |
1430 def testUpdateCloneOnCommit(self): | 1432 def testUpdateCloneOnCommit(self): |
1431 if not self.enabled: | 1433 if not self.enabled: |
1432 return | 1434 return |
1433 options = self.Options() | 1435 options = self.Options() |
1434 | 1436 |
1435 origin_root_dir = self.root_dir | 1437 origin_root_dir = self.root_dir |
1436 self.root_dir = tempfile.mkdtemp() | 1438 self.root_dir = tempfile.mkdtemp() |
1437 self.relpath = '.' | 1439 self.relpath = '.' |
1438 self.base_path = join(self.root_dir, self.relpath) | 1440 self.base_path = join(self.root_dir, self.relpath) |
1439 url_with_commit_ref = origin_root_dir +\ | 1441 url_with_commit_ref = origin_root_dir +\ |
1440 '@a7142dc9f0009350b96a11f372b6ea658592aa95' | 1442 '@a7142dc9f0009350b96a11f372b6ea658592aa95' |
1441 | 1443 |
1442 scm = gclient_scm.CreateSCM(url=url_with_commit_ref, | 1444 scm = gclient_scm.CreateSCM(url=url_with_commit_ref, |
1443 root_dir=self.root_dir, | 1445 root_dir=self.root_dir, |
1444 relpath=self.relpath) | 1446 relpath=self.relpath) |
1445 | 1447 |
| 1448 expected_file_list = [join(self.base_path, "a"), |
| 1449 join(self.base_path, "b")] |
1446 file_list = [] | 1450 file_list = [] |
1447 options.revision = 'unmanaged' | 1451 options.revision = 'unmanaged' |
1448 scm.update(options, (), file_list) | 1452 scm.update(options, (), file_list) |
1449 | 1453 |
1450 self.assertEquals(file_list, []) | 1454 self.assertEquals(file_list, expected_file_list) |
1451 self.assertRaises(subprocess2.CalledProcessError, | 1455 self.assertEquals(scm.revinfo(options, (), None), |
1452 scm.revinfo, options, (), None) | 1456 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
1453 # indicates detached HEAD | 1457 # indicates detached HEAD |
1454 self.assertRaises(subprocess2.CalledProcessError, self.getCurrentBranch) | 1458 self.assertEquals(self.getCurrentBranch(), None) |
1455 self.checkInStdout('unmanaged solution; skipping') | 1459 self.checkInStdout( |
| 1460 'Checked out a7142dc9f0009350b96a11f372b6ea658592aa95 to a detached HEAD') |
1456 | 1461 |
1457 rmtree(origin_root_dir) | 1462 rmtree(origin_root_dir) |
1458 | 1463 |
1459 def testUpdateCloneOnBranch(self): | 1464 def testUpdateCloneOnBranch(self): |
1460 if not self.enabled: | 1465 if not self.enabled: |
1461 return | 1466 return |
1462 options = self.Options() | 1467 options = self.Options() |
1463 | 1468 |
1464 origin_root_dir = self.root_dir | 1469 origin_root_dir = self.root_dir |
1465 self.root_dir = tempfile.mkdtemp() | 1470 self.root_dir = tempfile.mkdtemp() |
1466 self.relpath = '.' | 1471 self.relpath = '.' |
1467 self.base_path = join(self.root_dir, self.relpath) | 1472 self.base_path = join(self.root_dir, self.relpath) |
1468 url_with_branch_ref = origin_root_dir + '@feature' | 1473 url_with_branch_ref = origin_root_dir + '@feature' |
1469 | 1474 |
1470 scm = gclient_scm.CreateSCM(url=url_with_branch_ref, | 1475 scm = gclient_scm.CreateSCM(url=url_with_branch_ref, |
1471 root_dir=self.root_dir, | 1476 root_dir=self.root_dir, |
1472 relpath=self.relpath) | 1477 relpath=self.relpath) |
1473 | 1478 |
| 1479 expected_file_list = [join(self.base_path, "a"), |
| 1480 join(self.base_path, "b"), |
| 1481 join(self.base_path, "c")] |
1474 file_list = [] | 1482 file_list = [] |
1475 options.revision = 'unmanaged' | 1483 options.revision = 'unmanaged' |
1476 scm.update(options, (), file_list) | 1484 scm.update(options, (), file_list) |
1477 | 1485 |
1478 self.assertEquals(file_list, []) | 1486 self.assertEquals(file_list, expected_file_list) |
1479 self.assertRaises(subprocess2.CalledProcessError, | 1487 self.assertEquals(scm.revinfo(options, (), None), |
1480 scm.revinfo, options, (), None) | 1488 '9a51244740b25fa2ded5252ca00a3178d3f665a9') |
1481 self.assertRaises(subprocess2.CalledProcessError, self.getCurrentBranch) | 1489 self.assertEquals(self.getCurrentBranch(), 'feature') |
1482 self.checkNotInStdout('Checked out feature to a detached HEAD') | 1490 self.checkNotInStdout('Checked out feature to a detached HEAD') |
1483 | 1491 |
1484 rmtree(origin_root_dir) | 1492 rmtree(origin_root_dir) |
1485 | 1493 |
1486 def testUpdateCloneOnDetachedBranch(self): | 1494 def testUpdateCloneOnDetachedBranch(self): |
1487 if not self.enabled: | 1495 if not self.enabled: |
1488 return | 1496 return |
1489 options = self.Options() | 1497 options = self.Options() |
1490 | 1498 |
1491 origin_root_dir = self.root_dir | 1499 origin_root_dir = self.root_dir |
1492 self.root_dir = tempfile.mkdtemp() | 1500 self.root_dir = tempfile.mkdtemp() |
1493 self.relpath = '.' | 1501 self.relpath = '.' |
1494 self.base_path = join(self.root_dir, self.relpath) | 1502 self.base_path = join(self.root_dir, self.relpath) |
1495 url_with_branch_ref = origin_root_dir + '@refs/remotes/origin/feature' | 1503 url_with_branch_ref = origin_root_dir + '@refs/remotes/origin/feature' |
1496 | 1504 |
1497 scm = gclient_scm.CreateSCM(url=url_with_branch_ref, | 1505 scm = gclient_scm.CreateSCM(url=url_with_branch_ref, |
1498 root_dir=self.root_dir, | 1506 root_dir=self.root_dir, |
1499 relpath=self.relpath) | 1507 relpath=self.relpath) |
1500 | 1508 |
| 1509 expected_file_list = [join(self.base_path, "a"), |
| 1510 join(self.base_path, "b"), |
| 1511 join(self.base_path, "c")] |
1501 file_list = [] | 1512 file_list = [] |
1502 options.revision = 'unmanaged' | 1513 options.revision = 'unmanaged' |
1503 scm.update(options, (), []) | 1514 scm.update(options, (), file_list) |
1504 | 1515 |
1505 self.assertEquals(file_list, []) | 1516 self.assertEquals(file_list, expected_file_list) |
1506 self.assertRaises(subprocess2.CalledProcessError, | 1517 self.assertEquals(scm.revinfo(options, (), None), |
1507 scm.revinfo, options, (), None) | 1518 '9a51244740b25fa2ded5252ca00a3178d3f665a9') |
1508 # indicates detached HEAD | 1519 # indicates detached HEAD |
1509 self.assertRaises(subprocess2.CalledProcessError, self.getCurrentBranch) | 1520 self.assertEquals(self.getCurrentBranch(), None) |
1510 self.checkInStdout('unmanaged solution; skipping') | 1521 self.checkInStdout( |
| 1522 'Checked out refs/remotes/origin/feature to a detached HEAD') |
1511 | 1523 |
1512 rmtree(origin_root_dir) | 1524 rmtree(origin_root_dir) |
1513 | 1525 |
1514 def testUpdateCloneOnBranchHead(self): | 1526 def testUpdateCloneOnBranchHead(self): |
1515 if not self.enabled: | 1527 if not self.enabled: |
1516 return | 1528 return |
1517 options = self.Options() | 1529 options = self.Options() |
1518 | 1530 |
1519 origin_root_dir = self.root_dir | 1531 origin_root_dir = self.root_dir |
1520 self.root_dir = tempfile.mkdtemp() | 1532 self.root_dir = tempfile.mkdtemp() |
1521 self.relpath = '.' | 1533 self.relpath = '.' |
1522 self.base_path = join(self.root_dir, self.relpath) | 1534 self.base_path = join(self.root_dir, self.relpath) |
1523 url_with_branch_ref = origin_root_dir + '@refs/heads/feature' | 1535 url_with_branch_ref = origin_root_dir + '@refs/heads/feature' |
1524 | 1536 |
1525 scm = gclient_scm.CreateSCM(url=url_with_branch_ref, | 1537 scm = gclient_scm.CreateSCM(url=url_with_branch_ref, |
1526 root_dir=self.root_dir, | 1538 root_dir=self.root_dir, |
1527 relpath=self.relpath) | 1539 relpath=self.relpath) |
1528 | 1540 |
| 1541 expected_file_list = [join(self.base_path, "a"), |
| 1542 join(self.base_path, "b"), |
| 1543 join(self.base_path, "c")] |
1529 file_list = [] | 1544 file_list = [] |
1530 options.revision = 'unmanaged' | 1545 options.revision = 'unmanaged' |
1531 scm.update(options, (), file_list) | 1546 scm.update(options, (), file_list) |
1532 | 1547 |
1533 self.assertEquals(file_list, []) | 1548 self.assertEquals(file_list, expected_file_list) |
1534 self.assertRaises(subprocess2.CalledProcessError, | 1549 self.assertEquals(scm.revinfo(options, (), None), |
1535 scm.revinfo, options, (), None) | 1550 '9a51244740b25fa2ded5252ca00a3178d3f665a9') |
1536 self.assertRaises(subprocess2.CalledProcessError, self.getCurrentBranch) | 1551 self.assertEquals(self.getCurrentBranch(), 'feature') |
1537 self.checkNotInStdout( | 1552 self.checkNotInStdout( |
1538 'Checked out refs/heads/feature to a detached HEAD') | 1553 'Checked out refs/heads/feature to a detached HEAD') |
1539 | 1554 |
1540 rmtree(origin_root_dir) | 1555 rmtree(origin_root_dir) |
1541 | 1556 |
1542 def testUpdateUpdate(self): | 1557 def testUpdateUpdate(self): |
1543 if not self.enabled: | 1558 if not self.enabled: |
1544 return | 1559 return |
1545 options = self.Options() | 1560 options = self.Options() |
1546 expected_file_list = [] | 1561 expected_file_list = [] |
(...skipping 10 matching lines...) Expand all Loading... |
1557 | 1572 |
1558 if __name__ == '__main__': | 1573 if __name__ == '__main__': |
1559 if '-v' in sys.argv: | 1574 if '-v' in sys.argv: |
1560 logging.basicConfig( | 1575 logging.basicConfig( |
1561 level=logging.DEBUG, | 1576 level=logging.DEBUG, |
1562 format='%(asctime).19s %(levelname)s %(filename)s:' | 1577 format='%(asctime).19s %(levelname)s %(filename)s:' |
1563 '%(lineno)s %(message)s') | 1578 '%(lineno)s %(message)s') |
1564 unittest.main() | 1579 unittest.main() |
1565 | 1580 |
1566 # vim: ts=2:sw=2:tw=80:et: | 1581 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |