2626"""Tests for Index files."""
2727
2828from pathlib import Path
29+ from typing import Callable
2930
3031import pygit2
31- from pygit2 import PackBuilder
32+ from pygit2 import Oid , PackBuilder , Repository
3233
3334from . import utils
3435
3536
36- def test_create_packbuilder (testrepo ) :
37+ def test_create_packbuilder (testrepo : Repository ) -> None :
3738 # simple test of PackBuilder creation
3839 packbuilder = PackBuilder (testrepo )
3940 assert len (packbuilder ) == 0
4041
4142
42- def test_add (testrepo ) :
43+ def test_add (testrepo : Repository ) -> None :
4344 # Add a few objects and confirm that the count is correct
4445 packbuilder = PackBuilder (testrepo )
4546 objects_to_add = [obj for obj in testrepo ]
@@ -49,9 +50,10 @@ def test_add(testrepo):
4950 assert len (packbuilder ) == 2
5051
5152
52- def test_add_recursively (testrepo ) :
53+ def test_add_recursively (testrepo : Repository ) -> None :
5354 # Add the head object and referenced objects recursively and confirm that the count is correct
5455 packbuilder = PackBuilder (testrepo )
56+ assert isinstance (testrepo .head .target , Oid )
5557 packbuilder .add_recur (testrepo .head .target )
5658
5759 # expect a count of 4 made up of the following referenced objects:
@@ -63,14 +65,14 @@ def test_add_recursively(testrepo):
6365 assert len (packbuilder ) == 4
6466
6567
66- def test_repo_pack (testrepo , tmp_path ) :
68+ def test_repo_pack (testrepo : Repository , tmp_path : Path ) -> None :
6769 # pack the repo with the default strategy
6870 confirm_same_repo_after_packing (testrepo , tmp_path , None )
6971
7072
71- def test_pack_with_delegate (testrepo , tmp_path ) :
73+ def test_pack_with_delegate (testrepo : Repository , tmp_path : Path ) -> None :
7274 # loop through all branches and add each commit to the packbuilder
73- def pack_delegate (pb ) :
75+ def pack_delegate (pb : PackBuilder ) -> None :
7476 for branch in pb ._repo .branches :
7577 br = pb ._repo .branches .get (branch )
7678 for commit in br .log ():
@@ -79,15 +81,19 @@ def pack_delegate(pb):
7981 confirm_same_repo_after_packing (testrepo , tmp_path , pack_delegate )
8082
8183
82- def setup_second_repo (tmp_path ) :
84+ def setup_second_repo (tmp_path : Path ) -> Repository :
8385 # helper method to set up a second repo for comparison
8486 tmp_path_2 = tmp_path / 'test_repo2'
8587 with utils .TemporaryRepository ('testrepo.zip' , tmp_path_2 ) as path :
8688 testrepo = pygit2 .Repository (path )
8789 return testrepo
8890
8991
90- def confirm_same_repo_after_packing (testrepo , tmp_path , pack_delegate ):
92+ def confirm_same_repo_after_packing (
93+ testrepo : Repository ,
94+ tmp_path : Path ,
95+ pack_delegate : Callable [[PackBuilder ], None ] | None ,
96+ ) -> None :
9197 # Helper method to confirm the contents of two repos before and after packing
9298 pack_repo = setup_second_repo (tmp_path )
9399 pack_repo_path = Path (pack_repo .path )
0 commit comments