test_objectspec.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. skipIfPY3,
  35. )
  36. @skipIfPY3
  37. class ParseObjectTests(TestCase):
  38. """Test parse_object."""
  39. def test_nonexistent(self):
  40. r = MemoryRepo()
  41. self.assertRaises(KeyError, parse_object, r, "thisdoesnotexist")
  42. def test_blob_by_sha(self):
  43. r = MemoryRepo()
  44. b = Blob.from_string("Blah")
  45. r.object_store.add_object(b)
  46. self.assertEqual(b, parse_object(r, b.id))
  47. @skipIfPY3
  48. class ParseCommitRangeTests(TestCase):
  49. """Test parse_commit_range."""
  50. def test_nonexistent(self):
  51. r = MemoryRepo()
  52. self.assertRaises(KeyError, parse_commit_range, r, "thisdoesnotexist")
  53. def test_commit_by_sha(self):
  54. r = MemoryRepo()
  55. c1, c2, c3 = build_commit_graph(r.object_store, [[1], [2, 1],
  56. [3, 1, 2]])
  57. self.assertEqual([c1], list(parse_commit_range(r, c1.id)))