test_utils.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # test_utils.py -- Tests for git test utilities.
  2. # Copyright (C) 2010 Google, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. # Boston, MA 02110-1301, USA.
  18. """Tests for git test utilities."""
  19. from dulwich.object_store import (
  20. MemoryObjectStore,
  21. )
  22. from dulwich.objects import (
  23. Blob,
  24. )
  25. from dulwich.tests import (
  26. TestCase,
  27. )
  28. from utils import (
  29. make_object,
  30. build_commit_graph,
  31. )
  32. class BuildCommitGraphTest(TestCase):
  33. def setUp(self):
  34. super(BuildCommitGraphTest, self).setUp()
  35. self.store = MemoryObjectStore()
  36. def test_linear(self):
  37. c1, c2 = build_commit_graph(self.store, [[1], [2, 1]])
  38. for obj_id in [c1.id, c2.id, c1.tree, c2.tree]:
  39. self.assertTrue(obj_id in self.store)
  40. self.assertEqual([], c1.parents)
  41. self.assertEqual([c1.id], c2.parents)
  42. self.assertEqual(c1.tree, c2.tree)
  43. self.assertEqual([], list(self.store[c1.tree].iteritems()))
  44. self.assertTrue(c2.commit_time > c1.commit_time)
  45. def test_merge(self):
  46. c1, c2, c3, c4 = build_commit_graph(self.store,
  47. [[1], [2, 1], [3, 1], [4, 2, 3]])
  48. self.assertEqual([c2.id, c3.id], c4.parents)
  49. self.assertTrue(c4.commit_time > c2.commit_time)
  50. self.assertTrue(c4.commit_time > c3.commit_time)
  51. def test_missing_parent(self):
  52. self.assertRaises(ValueError, build_commit_graph, self.store,
  53. [[1], [3, 2], [2, 1]])
  54. def test_trees(self):
  55. a1 = make_object(Blob, data='aaa1')
  56. a2 = make_object(Blob, data='aaa2')
  57. c1, c2 = build_commit_graph(self.store, [[1], [2, 1]],
  58. trees={1: [('a', a1)],
  59. 2: [('a', a2, 0100644)]})
  60. self.assertEqual((0100644, a1.id), self.store[c1.tree]['a'])
  61. self.assertEqual((0100644, a2.id), self.store[c2.tree]['a'])
  62. def test_attrs(self):
  63. c1, c2 = build_commit_graph(self.store, [[1], [2, 1]],
  64. attrs={1: {'message': 'Hooray!'}})
  65. self.assertEqual('Hooray!', c1.message)
  66. self.assertEqual('Commit 2', c2.message)
  67. def test_commit_time(self):
  68. c1, c2, c3 = build_commit_graph(self.store, [[1], [2, 1], [3, 2]],
  69. attrs={1: {'commit_time': 124},
  70. 2: {'commit_time': 123}})
  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)