test_utils.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # test_utils.py -- Tests for git test utilities.
  2. # Copyright (C) 2010 Google, Inc.
  3. #
  4. # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
  5. # General Public License as public by the Free Software Foundation; version 2.0
  6. # or (at your option) any later version. You can redistribute it and/or
  7. # modify it under the terms of either of these two licenses.
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #
  15. # You should have received a copy of the licenses; if not, see
  16. # <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
  17. # and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
  18. # License, Version 2.0.
  19. #
  20. """Tests for git test utilities."""
  21. from dulwich.object_store import (
  22. MemoryObjectStore,
  23. )
  24. from dulwich.objects import (
  25. Blob,
  26. )
  27. from dulwich.tests import (
  28. TestCase,
  29. )
  30. from dulwich.tests.utils import (
  31. make_object,
  32. build_commit_graph,
  33. )
  34. class BuildCommitGraphTest(TestCase):
  35. def setUp(self):
  36. super(BuildCommitGraphTest, self).setUp()
  37. self.store = MemoryObjectStore()
  38. def test_linear(self):
  39. c1, c2 = build_commit_graph(self.store, [[1], [2, 1]])
  40. for obj_id in [c1.id, c2.id, c1.tree, c2.tree]:
  41. self.assertTrue(obj_id in self.store)
  42. self.assertEqual([], c1.parents)
  43. self.assertEqual([c1.id], c2.parents)
  44. self.assertEqual(c1.tree, c2.tree)
  45. self.assertEqual([], self.store[c1.tree].items())
  46. self.assertTrue(c2.commit_time > c1.commit_time)
  47. def test_merge(self):
  48. c1, c2, c3, c4 = build_commit_graph(self.store,
  49. [[1], [2, 1], [3, 1], [4, 2, 3]])
  50. self.assertEqual([c2.id, c3.id], c4.parents)
  51. self.assertTrue(c4.commit_time > c2.commit_time)
  52. self.assertTrue(c4.commit_time > c3.commit_time)
  53. def test_missing_parent(self):
  54. self.assertRaises(ValueError, build_commit_graph, self.store,
  55. [[1], [3, 2], [2, 1]])
  56. def test_trees(self):
  57. a1 = make_object(Blob, data=b'aaa1')
  58. a2 = make_object(Blob, data=b'aaa2')
  59. c1, c2 = build_commit_graph(self.store, [[1], [2, 1]],
  60. trees={1: [(b'a', a1)],
  61. 2: [(b'a', a2, 0o100644)]})
  62. self.assertEqual((0o100644, a1.id), self.store[c1.tree][b'a'])
  63. self.assertEqual((0o100644, a2.id), self.store[c2.tree][b'a'])
  64. def test_attrs(self):
  65. c1, c2 = build_commit_graph(self.store, [[1], [2, 1]],
  66. attrs={1: {'message': b'Hooray!'}})
  67. self.assertEqual(b'Hooray!', c1.message)
  68. self.assertEqual(b'Commit 2', c2.message)
  69. def test_commit_time(self):
  70. c1, c2, c3 = build_commit_graph(self.store, [[1], [2, 1], [3, 2]],
  71. attrs={1: {'commit_time': 124},
  72. 2: {'commit_time': 123}})
  73. self.assertEqual(124, c1.commit_time)
  74. self.assertEqual(123, c2.commit_time)
  75. self.assertTrue(c2.commit_time < c1.commit_time < c3.commit_time)