test_objectspec.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. parse_refspec,
  28. )
  29. from dulwich.repo import MemoryRepo
  30. from dulwich.tests import (
  31. TestCase,
  32. )
  33. from dulwich.tests.utils import (
  34. build_commit_graph,
  35. )
  36. class ParseObjectTests(TestCase):
  37. """Test parse_object."""
  38. def test_nonexistent(self):
  39. r = MemoryRepo()
  40. self.assertRaises(KeyError, parse_object, r, "thisdoesnotexist")
  41. def test_blob_by_sha(self):
  42. r = MemoryRepo()
  43. b = Blob.from_string(b"Blah")
  44. r.object_store.add_object(b)
  45. self.assertEqual(b, parse_object(r, b.id))
  46. class ParseCommitRangeTests(TestCase):
  47. """Test parse_commit_range."""
  48. def test_nonexistent(self):
  49. r = MemoryRepo()
  50. self.assertRaises(KeyError, parse_commit_range, r, "thisdoesnotexist")
  51. def test_commit_by_sha(self):
  52. r = MemoryRepo()
  53. c1, c2, c3 = build_commit_graph(r.object_store, [[1], [2, 1],
  54. [3, 1, 2]])
  55. self.assertEqual([c1], list(parse_commit_range(r, c1.id)))
  56. class ParseRefspecTests(TestCase):
  57. def test_nonexistent(self):
  58. r = {}
  59. self.assertRaises(KeyError, parse_refspec, r, "thisdoesnotexist")
  60. def test_head(self):
  61. r = {"refs/heads/foo": "bla"}
  62. self.assertEquals("refs/heads/foo", parse_refspec(r, "foo"))
  63. def test_full(self):
  64. r = {"refs/heads/foo": "bla"}
  65. self.assertEquals("refs/heads/foo", parse_refspec(r, "refs/heads/foo"))