2
0

test_utils.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 MemoryObjectStore
  22. from dulwich.objects import Blob
  23. from dulwich.tests.utils import build_commit_graph, make_object
  24. from . import TestCase
  25. class BuildCommitGraphTest(TestCase):
  26. def setUp(self):
  27. super().setUp()
  28. self.store = MemoryObjectStore()
  29. def test_linear(self):
  30. c1, c2 = build_commit_graph(self.store, [[1], [2, 1]])
  31. for obj_id in [c1.id, c2.id, c1.tree, c2.tree]:
  32. self.assertIn(obj_id, self.store)
  33. self.assertEqual([], c1.parents)
  34. self.assertEqual([c1.id], c2.parents)
  35. self.assertEqual(c1.tree, c2.tree)
  36. self.assertEqual([], self.store[c1.tree].items())
  37. self.assertGreater(c2.commit_time, c1.commit_time)
  38. def test_merge(self):
  39. c1, c2, c3, c4 = build_commit_graph(
  40. self.store, [[1], [2, 1], [3, 1], [4, 2, 3]]
  41. )
  42. self.assertEqual([c2.id, c3.id], c4.parents)
  43. self.assertGreater(c4.commit_time, c2.commit_time)
  44. self.assertGreater(c4.commit_time, c3.commit_time)
  45. def test_missing_parent(self):
  46. self.assertRaises(
  47. ValueError, build_commit_graph, self.store, [[1], [3, 2], [2, 1]]
  48. )
  49. def test_trees(self):
  50. a1 = make_object(Blob, data=b"aaa1")
  51. a2 = make_object(Blob, data=b"aaa2")
  52. c1, c2 = build_commit_graph(
  53. self.store,
  54. [[1], [2, 1]],
  55. trees={1: [(b"a", a1)], 2: [(b"a", a2, 0o100644)]},
  56. )
  57. self.assertEqual((0o100644, a1.id), self.store[c1.tree][b"a"])
  58. self.assertEqual((0o100644, a2.id), self.store[c2.tree][b"a"])
  59. def test_attrs(self):
  60. c1, c2 = build_commit_graph(
  61. self.store, [[1], [2, 1]], attrs={1: {"message": b"Hooray!"}}
  62. )
  63. self.assertEqual(b"Hooray!", c1.message)
  64. self.assertEqual(b"Commit 2", c2.message)
  65. def test_commit_time(self):
  66. c1, c2, c3 = build_commit_graph(
  67. self.store,
  68. [[1], [2, 1], [3, 2]],
  69. attrs={1: {"commit_time": 124}, 2: {"commit_time": 123}},
  70. )
  71. self.assertEqual(124, c1.commit_time)
  72. self.assertEqual(123, c2.commit_time)
  73. self.assertTrue(c2.commit_time < c1.commit_time < c3.commit_time)