test_bundle.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # test_bundle.py -- tests for bundle
  2. # Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
  3. #
  4. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  5. # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
  6. # General Public License as public by the Free Software Foundation; version 2.0
  7. # or (at your option) any later version. You can redistribute it and/or
  8. # modify it under the terms of either of these two licenses.
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # You should have received a copy of the licenses; if not, see
  17. # <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
  18. # and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
  19. # License, Version 2.0.
  20. #
  21. """Tests for bundle support."""
  22. import os
  23. import tempfile
  24. from io import BytesIO
  25. from dulwich.bundle import Bundle, read_bundle, write_bundle
  26. from dulwich.pack import PackData, write_pack_objects
  27. from . import TestCase
  28. class BundleTests(TestCase):
  29. def test_roundtrip_bundle(self) -> None:
  30. origbundle = Bundle()
  31. origbundle.version = 3
  32. origbundle.capabilities = {"foo": None}
  33. origbundle.references = {b"refs/heads/master": b"ab" * 20}
  34. origbundle.prerequisites = [(b"cc" * 20, "comment")]
  35. b = BytesIO()
  36. write_pack_objects(b.write, [])
  37. b.seek(0)
  38. origbundle.pack_data = PackData.from_file(b)
  39. with tempfile.TemporaryDirectory() as td:
  40. with open(os.path.join(td, "foo"), "wb") as f:
  41. write_bundle(f, origbundle)
  42. with open(os.path.join(td, "foo"), "rb") as f:
  43. newbundle = read_bundle(f)
  44. self.assertEqual(origbundle, newbundle)