test_objectspec.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # test_objectspec.py -- tests for objectspec.py
  2. # Copyright (C) 2014 Jelmer Vernooij <jelmer@samba.org>
  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; version 2
  7. # of the License or (at your option) any later version of
  8. # the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. """Tests for revision spec parsing."""
  20. # TODO: Round-trip parse-serialize-parse and serialize-parse-serialize tests.
  21. from dulwich.objects import (
  22. Blob,
  23. )
  24. from dulwich.objectspec import (
  25. parse_object,
  26. parse_commit_range,
  27. )
  28. from dulwich.repo import MemoryRepo
  29. from dulwich.tests import (
  30. TestCase,
  31. )
  32. from dulwich.tests.utils import (
  33. build_commit_graph,
  34. )
  35. class ParseObjectTests(TestCase):
  36. """Test parse_object."""
  37. def test_nonexistent(self):
  38. r = MemoryRepo()
  39. self.assertRaises(KeyError, parse_object, r, "thisdoesnotexist")
  40. def test_blob_by_sha(self):
  41. r = MemoryRepo()
  42. b = Blob.from_string(b"Blah")
  43. r.object_store.add_object(b)
  44. self.assertEqual(b, parse_object(r, b.id))
  45. class ParseCommitRangeTests(TestCase):
  46. """Test parse_commit_range."""
  47. def test_nonexistent(self):
  48. r = MemoryRepo()
  49. self.assertRaises(KeyError, parse_commit_range, r, "thisdoesnotexist")
  50. def test_commit_by_sha(self):
  51. r = MemoryRepo()
  52. c1, c2, c3 = build_commit_graph(r.object_store, [[1], [2, 1],
  53. [3, 1, 2]])
  54. self.assertEqual([c1], list(parse_commit_range(r, c1.id)))