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 TestCommit(test_util.TestBasis): |
| 10 def testComparison(self): |
| 11 r = self.mkRepo() |
| 12 c = r['refs/heads/branch_O'].commit |
| 13 self.assertEqual(c, c) |
| 14 self.assertEqual(c, r['refs/heads/branch_O'].commit) |
| 15 self.assertNotEqual(c, r['refs/heads/branch_S'].commit) |
| 16 self.assertIs(c.repo, r) |
| 17 |
| 18 def testRepr(self): |
| 19 r = self.mkRepo() |
| 20 c = r['refs/heads/branch_O'].commit |
| 21 self.assertEqual("Commit(%r, %r)" % (r, self.repo['O']), repr(c)) |
| 22 |
| 23 def testData(self): |
| 24 r = self.mkRepo() |
| 25 d = r['refs/heads/branch_O'].commit.data |
| 26 self.assertEqual(d.committer.email, 'commitish@example.com') |
| 27 |
| 28 def testBogus(self): |
| 29 r = self.mkRepo() |
| 30 d = git2.Commit(r, 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef').data |
| 31 self.assertIs(d, git2.INVALID) |
| 32 self.assertIs(d.committer, git2.INVALID) |
| 33 self.assertIs(d.committer.alter(user='tom'), git2.INVALID) |
| 34 |
| 35 def testParent(self): |
| 36 r = self.mkRepo() |
| 37 c = r['refs/heads/branch_O'].commit |
| 38 self.assertEqual(c.parent.hsh, self.repo['N']) |
| 39 |
| 40 a = r['refs/heads/root_A'].commit |
| 41 self.assertIsNone(a.parent) |
| 42 |
| 43 z = r['refs/heads/branch_Z'].commit |
| 44 self.assertIs(z.parent, git2.INVALID) |
| 45 |
| 46 def testAlter(self): |
| 47 r = self.mkRepo() |
| 48 c = r['refs/heads/branch_O'].commit |
| 49 d = c.data |
| 50 |
| 51 a = c.alter(committer=d.committer.alter(email='bob@dude.example.com')) |
| 52 self.assertEqual(a.hsh, 'fadfbe63d40f60f5313a71a1c9d72a741ee91770') |
| 53 |
| 54 with self.assertRaises(Exception): |
| 55 c.alter(tree='failbeef') |
| 56 |
OLD | NEW |