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