OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 from infra.libs import git2 |
| 6 from infra.libs.git2.test import test_util |
| 7 |
| 8 |
| 9 class TestRef(test_util.TestBasis): |
| 10 def testComparison(self): |
| 11 r = self.mkRepo() |
| 12 O = r['refs/heads/branch_O'] |
| 13 self.assertEqual(O, O) |
| 14 self.assertEqual(O, r['refs/heads/branch_O']) |
| 15 |
| 16 N = r['refs/heads/branch_K'] |
| 17 self.assertNotEqual(O, N) |
| 18 |
| 19 def testRepr(self): |
| 20 r = self.mkRepo() |
| 21 O = r['refs/heads/branch_O'] |
| 22 self.assertEqual("Ref(%r, 'refs/heads/branch_O')" % r, repr(O)) |
| 23 |
| 24 def testCommit(self): |
| 25 r = self.mkRepo() |
| 26 self.assertEqual( |
| 27 r['refs/heads/branch_O'].commit.hsh, |
| 28 self.repo['O']) |
| 29 |
| 30 def testCommitBogus(self): |
| 31 r = self.mkRepo() |
| 32 self.assertIs(r['refs/heads/bogus'].commit, git2.INVALID) |
| 33 # exercise __ne__ and __eq__ |
| 34 self.assertNotEqual(r['refs/heads/bogus'].commit, |
| 35 r['refs/heads/other_bogus'].commit) |
| 36 self.assertFalse(r['refs/heads/bogus'].commit == |
| 37 r['refs/heads/other_bogus'].commit) |
| 38 |
| 39 def testTo(self): |
| 40 r = self.mkRepo() |
| 41 A = r['refs/heads/root_A'] |
| 42 O = r['refs/heads/branch_O'] |
| 43 self.assertEqual( |
| 44 list(c.hsh for c in A.to(O)), |
| 45 [self.repo[c] for c in 'BCDLMNO'] |
| 46 ) |
| 47 |
| 48 def testNonFastForward(self): |
| 49 r = self.mkRepo() |
| 50 O = r['refs/heads/branch_O'] |
| 51 D = r.get_commit(self.repo['D']) |
| 52 with self.assertRaises(git2.CalledProcessError): |
| 53 O.fast_forward_push(D) |
| 54 self.assertEqual( |
| 55 self.repo.git('rev-parse', 'branch_O').stdout.strip(), |
| 56 self.repo['O']) |
| 57 |
| 58 def testFastForward(self): |
| 59 r = self.mkRepo() |
| 60 O = r['refs/heads/branch_O'] |
| 61 S = r.get_commit(self.repo['S']) |
| 62 self.capture_stdio(O.fast_forward_push, S) |
| 63 self.assertEqual(O.commit.hsh, self.repo['S']) |
| 64 self.assertEqual( |
| 65 self.repo.git('rev-parse', 'branch_O').stdout.strip(), |
| 66 self.repo['S']) |
| 67 |
| 68 |
OLD | NEW |