|
36 | 36 | COMMIT_SHA = '5fe808e8953c12735680c257f56600cb0de44b10' |
37 | 37 |
|
38 | 38 |
|
39 | | -class CommitTest(utils.BareRepoTestCase): |
40 | | - |
41 | | - @utils.refcount |
42 | | - def test_commit_refcount(self): |
43 | | - commit = self.repo[COMMIT_SHA] |
44 | | - start = sys.getrefcount(commit) |
45 | | - tree = commit.tree |
46 | | - del tree |
47 | | - end = sys.getrefcount(commit) |
48 | | - assert start == end |
49 | | - |
50 | | - |
51 | | - def test_read_commit(self): |
52 | | - commit = self.repo[COMMIT_SHA] |
53 | | - assert COMMIT_SHA == str(commit.id) |
54 | | - parents = commit.parents |
55 | | - assert 1 == len(parents) |
56 | | - assert 'c2792cfa289ae6321ecf2cd5806c2194b0fd070c' == str(parents[0].id) |
57 | | - assert commit.message_encoding is None |
58 | | - assert commit.message == ('Second test data commit.\n\n' |
59 | | - 'This commit has some additional text.\n') |
60 | | - commit_time = 1288481576 |
61 | | - assert commit_time == commit.commit_time |
62 | | - assert commit.committer == Signature('Dave Borowitz', 'dborowitz@google.com', commit_time, -420) |
63 | | - assert commit.author == Signature('Dave Borowitz', 'dborowitz@google.com', 1288477363, -420) |
64 | | - assert '967fce8df97cc71722d3c2a5930ef3e6f1d27b12' == str(commit.tree.id) |
65 | | - |
66 | | - def test_new_commit(self): |
67 | | - repo = self.repo |
68 | | - message = 'New commit.\n\nMessage with non-ascii chars: ééé.\n' |
69 | | - committer = Signature('John Doe', 'jdoe@example.com', 12346, 0) |
70 | | - author = Signature( |
71 | | - 'J. David Ibáñez', 'jdavid@example.com', 12345, 0, |
72 | | - encoding='utf-8') |
73 | | - tree = '967fce8df97cc71722d3c2a5930ef3e6f1d27b12' |
74 | | - tree_prefix = tree[:5] |
75 | | - too_short_prefix = tree[:3] |
76 | | - |
77 | | - parents = [COMMIT_SHA[:5]] |
78 | | - with pytest.raises(ValueError): |
79 | | - repo.create_commit(None, author, committer, message, too_short_prefix, parents) |
80 | | - |
81 | | - sha = repo.create_commit(None, author, committer, message, |
82 | | - tree_prefix, parents) |
83 | | - commit = repo[sha] |
84 | | - |
85 | | - assert GIT_OBJ_COMMIT == commit.type |
86 | | - assert '98286caaab3f1fde5bf52c8369b2b0423bad743b' == commit.hex |
87 | | - assert commit.message_encoding is None |
88 | | - assert message == commit.message |
89 | | - assert 12346 == commit.commit_time |
90 | | - assert committer == commit.committer |
91 | | - assert author == commit.author |
92 | | - assert tree == commit.tree.hex |
93 | | - assert Oid(hex=tree) == commit.tree_id |
94 | | - assert 1 == len(commit.parents) |
95 | | - assert COMMIT_SHA == commit.parents[0].hex |
96 | | - assert Oid(hex=COMMIT_SHA) == commit.parent_ids[0] |
97 | | - |
98 | | - def test_new_commit_encoding(self): |
99 | | - repo = self.repo |
100 | | - encoding = 'iso-8859-1' |
101 | | - message = 'New commit.\n\nMessage with non-ascii chars: ééé.\n' |
102 | | - committer = Signature('John Doe', 'jdoe@example.com', 12346, 0, |
103 | | - encoding) |
104 | | - author = Signature('J. David Ibáñez', 'jdavid@example.com', 12345, 0, |
105 | | - encoding) |
106 | | - tree = '967fce8df97cc71722d3c2a5930ef3e6f1d27b12' |
107 | | - tree_prefix = tree[:5] |
108 | | - |
109 | | - parents = [COMMIT_SHA[:5]] |
110 | | - sha = repo.create_commit(None, author, committer, message, |
111 | | - tree_prefix, parents, encoding) |
112 | | - commit = repo[sha] |
113 | | - |
114 | | - assert GIT_OBJ_COMMIT == commit.type |
115 | | - assert 'iso-8859-1' == commit.message_encoding |
116 | | - assert message.encode(encoding) == commit.raw_message |
117 | | - assert 12346 == commit.commit_time |
118 | | - assert committer == commit.committer |
119 | | - assert author == commit.author |
120 | | - assert tree == commit.tree.hex |
121 | | - assert Oid(hex=tree) == commit.tree_id |
122 | | - assert 1 == len(commit.parents) |
123 | | - assert COMMIT_SHA == commit.parents[0].hex |
124 | | - assert Oid(hex=COMMIT_SHA) == commit.parent_ids[0] |
125 | | - |
126 | | - def test_modify_commit(self): |
127 | | - message = 'New commit.\n\nMessage.\n' |
128 | | - committer = ('John Doe', 'jdoe@example.com', 12346) |
129 | | - author = ('Jane Doe', 'jdoe2@example.com', 12345) |
130 | | - |
131 | | - commit = self.repo[COMMIT_SHA] |
132 | | - |
133 | | - with pytest.raises(AttributeError): setattr(commit, 'message', message) |
134 | | - with pytest.raises(AttributeError): setattr(commit, 'committer', committer) |
135 | | - with pytest.raises(AttributeError): setattr(commit, 'author', author) |
136 | | - with pytest.raises(AttributeError): setattr(commit, 'tree', None) |
137 | | - with pytest.raises(AttributeError): setattr(commit, 'parents', None) |
| 39 | +@utils.refcount |
| 40 | +def test_commit_refcount(barerepo): |
| 41 | + commit = barerepo[COMMIT_SHA] |
| 42 | + start = sys.getrefcount(commit) |
| 43 | + tree = commit.tree |
| 44 | + del tree |
| 45 | + end = sys.getrefcount(commit) |
| 46 | + assert start == end |
| 47 | + |
| 48 | + |
| 49 | +def test_read_commit(barerepo): |
| 50 | + commit = barerepo[COMMIT_SHA] |
| 51 | + assert COMMIT_SHA == str(commit.id) |
| 52 | + parents = commit.parents |
| 53 | + assert 1 == len(parents) |
| 54 | + assert 'c2792cfa289ae6321ecf2cd5806c2194b0fd070c' == str(parents[0].id) |
| 55 | + assert commit.message_encoding is None |
| 56 | + assert commit.message == ('Second test data commit.\n\n' |
| 57 | + 'This commit has some additional text.\n') |
| 58 | + commit_time = 1288481576 |
| 59 | + assert commit_time == commit.commit_time |
| 60 | + assert commit.committer == Signature('Dave Borowitz', 'dborowitz@google.com', commit_time, -420) |
| 61 | + assert commit.author == Signature('Dave Borowitz', 'dborowitz@google.com', 1288477363, -420) |
| 62 | + assert '967fce8df97cc71722d3c2a5930ef3e6f1d27b12' == str(commit.tree.id) |
| 63 | + |
| 64 | +def test_new_commit(barerepo): |
| 65 | + repo = barerepo |
| 66 | + message = 'New commit.\n\nMessage with non-ascii chars: ééé.\n' |
| 67 | + committer = Signature('John Doe', 'jdoe@example.com', 12346, 0) |
| 68 | + author = Signature( |
| 69 | + 'J. David Ibáñez', 'jdavid@example.com', 12345, 0, |
| 70 | + encoding='utf-8') |
| 71 | + tree = '967fce8df97cc71722d3c2a5930ef3e6f1d27b12' |
| 72 | + tree_prefix = tree[:5] |
| 73 | + too_short_prefix = tree[:3] |
| 74 | + |
| 75 | + parents = [COMMIT_SHA[:5]] |
| 76 | + with pytest.raises(ValueError): |
| 77 | + repo.create_commit(None, author, committer, message, too_short_prefix, parents) |
| 78 | + |
| 79 | + sha = repo.create_commit(None, author, committer, message, |
| 80 | + tree_prefix, parents) |
| 81 | + commit = repo[sha] |
| 82 | + |
| 83 | + assert GIT_OBJ_COMMIT == commit.type |
| 84 | + assert '98286caaab3f1fde5bf52c8369b2b0423bad743b' == commit.hex |
| 85 | + assert commit.message_encoding is None |
| 86 | + assert message == commit.message |
| 87 | + assert 12346 == commit.commit_time |
| 88 | + assert committer == commit.committer |
| 89 | + assert author == commit.author |
| 90 | + assert tree == commit.tree.hex |
| 91 | + assert Oid(hex=tree) == commit.tree_id |
| 92 | + assert 1 == len(commit.parents) |
| 93 | + assert COMMIT_SHA == commit.parents[0].hex |
| 94 | + assert Oid(hex=COMMIT_SHA) == commit.parent_ids[0] |
| 95 | + |
| 96 | +def test_new_commit_encoding(barerepo): |
| 97 | + repo = barerepo |
| 98 | + encoding = 'iso-8859-1' |
| 99 | + message = 'New commit.\n\nMessage with non-ascii chars: ééé.\n' |
| 100 | + committer = Signature('John Doe', 'jdoe@example.com', 12346, 0, |
| 101 | + encoding) |
| 102 | + author = Signature('J. David Ibáñez', 'jdavid@example.com', 12345, 0, |
| 103 | + encoding) |
| 104 | + tree = '967fce8df97cc71722d3c2a5930ef3e6f1d27b12' |
| 105 | + tree_prefix = tree[:5] |
| 106 | + |
| 107 | + parents = [COMMIT_SHA[:5]] |
| 108 | + sha = repo.create_commit(None, author, committer, message, |
| 109 | + tree_prefix, parents, encoding) |
| 110 | + commit = repo[sha] |
| 111 | + |
| 112 | + assert GIT_OBJ_COMMIT == commit.type |
| 113 | + assert 'iso-8859-1' == commit.message_encoding |
| 114 | + assert message.encode(encoding) == commit.raw_message |
| 115 | + assert 12346 == commit.commit_time |
| 116 | + assert committer == commit.committer |
| 117 | + assert author == commit.author |
| 118 | + assert tree == commit.tree.hex |
| 119 | + assert Oid(hex=tree) == commit.tree_id |
| 120 | + assert 1 == len(commit.parents) |
| 121 | + assert COMMIT_SHA == commit.parents[0].hex |
| 122 | + assert Oid(hex=COMMIT_SHA) == commit.parent_ids[0] |
| 123 | + |
| 124 | +def test_modify_commit(barerepo): |
| 125 | + message = 'New commit.\n\nMessage.\n' |
| 126 | + committer = ('John Doe', 'jdoe@example.com', 12346) |
| 127 | + author = ('Jane Doe', 'jdoe2@example.com', 12345) |
| 128 | + |
| 129 | + commit = barerepo[COMMIT_SHA] |
| 130 | + |
| 131 | + with pytest.raises(AttributeError): setattr(commit, 'message', message) |
| 132 | + with pytest.raises(AttributeError): setattr(commit, 'committer', committer) |
| 133 | + with pytest.raises(AttributeError): setattr(commit, 'author', author) |
| 134 | + with pytest.raises(AttributeError): setattr(commit, 'tree', None) |
| 135 | + with pytest.raises(AttributeError): setattr(commit, 'parents', None) |
0 commit comments