2626"""Tests for Submodule objects."""
2727
2828from pathlib import Path
29+ from typing import Generator
2930
3031import pygit2
32+ from pygit2 import Repository , Submodule
3133import pytest
3234
3335from . import utils
4244
4345
4446@pytest .fixture
45- def repo (tmp_path ) :
47+ def repo (tmp_path : Path ) -> Generator [ Repository , None , None ] :
4648 with utils .TemporaryRepository ('submodulerepo.zip' , tmp_path ) as path :
4749 yield pygit2 .Repository (path )
4850
4951
50- def test_lookup_submodule (repo ) :
51- s = repo .submodules [SUBM_PATH ]
52+ def test_lookup_submodule (repo : Repository ) -> None :
53+ s : Submodule | None = repo .submodules [SUBM_PATH ]
5254 assert s is not None
5355 s = repo .submodules .get (SUBM_PATH )
5456 assert s is not None
5557
5658
57- def test_lookup_submodule_aspath (repo ) :
59+ def test_lookup_submodule_aspath (repo : Repository ) -> None :
5860 s = repo .submodules [Path (SUBM_PATH )]
5961 assert s is not None
6062
6163
62- def test_lookup_missing_submodule (repo ) :
64+ def test_lookup_missing_submodule (repo : Repository ) -> None :
6365 with pytest .raises (KeyError ):
6466 repo .submodules ['does-not-exist' ]
6567 assert repo .submodules .get ('does-not-exist' ) is None
6668
6769
68- def test_listall_submodules (repo ) :
70+ def test_listall_submodules (repo : Repository ) -> None :
6971 submodules = repo .listall_submodules ()
7072 assert len (submodules ) == 1
7173 assert submodules [0 ] == SUBM_PATH
7274
7375
74- def test_contains_submodule (repo ) :
76+ def test_contains_submodule (repo : Repository ) -> None :
7577 assert SUBM_PATH in repo .submodules
7678 assert 'does-not-exist' not in repo .submodules
7779
7880
79- def test_submodule_iterator (repo ) :
81+ def test_submodule_iterator (repo : Repository ) -> None :
8082 for s in repo .submodules :
8183 assert isinstance (s , pygit2 .Submodule )
8284 assert s .path == repo .submodules [s .path ].path
8385
8486
8587@utils .requires_network
86- def test_submodule_open (repo ) :
88+ def test_submodule_open (repo : Repository ) -> None :
8789 s = repo .submodules [SUBM_PATH ]
8890 repo .submodules .init ()
8991 repo .submodules .update ()
@@ -93,7 +95,7 @@ def test_submodule_open(repo):
9395
9496
9597@utils .requires_network
96- def test_submodule_open_from_repository_subclass (repo ) :
98+ def test_submodule_open_from_repository_subclass (repo : Repository ) -> None :
9799 class CustomRepoClass (pygit2 .Repository ):
98100 pass
99101
@@ -106,22 +108,22 @@ class CustomRepoClass(pygit2.Repository):
106108 assert r .head .target == SUBM_HEAD_SHA
107109
108110
109- def test_name (repo ) :
111+ def test_name (repo : Repository ) -> None :
110112 s = repo .submodules [SUBM_PATH ]
111113 assert SUBM_NAME == s .name
112114
113115
114- def test_path (repo ) :
116+ def test_path (repo : Repository ) -> None :
115117 s = repo .submodules [SUBM_PATH ]
116118 assert SUBM_PATH == s .path
117119
118120
119- def test_url (repo ) :
121+ def test_url (repo : Repository ) -> None :
120122 s = repo .submodules [SUBM_PATH ]
121123 assert SUBM_URL == s .url
122124
123125
124- def test_missing_url (repo ) :
126+ def test_missing_url (repo : Repository ) -> None :
125127 # Remove "url" from .gitmodules
126128 with open (Path (repo .workdir , '.gitmodules' ), 'wt' ) as f :
127129 f .write ('[submodule "TestGitRepository"]\n ' )
@@ -131,7 +133,7 @@ def test_missing_url(repo):
131133
132134
133135@utils .requires_network
134- def test_init_and_update (repo ) :
136+ def test_init_and_update (repo : Repository ) -> None :
135137 subrepo_file_path = Path (repo .workdir ) / SUBM_PATH / 'master.txt'
136138 assert not subrepo_file_path .exists ()
137139
@@ -148,7 +150,7 @@ def test_init_and_update(repo):
148150
149151
150152@utils .requires_network
151- def test_specified_update (repo ) :
153+ def test_specified_update (repo : Repository ) -> None :
152154 subrepo_file_path = Path (repo .workdir ) / SUBM_PATH / 'master.txt'
153155 assert not subrepo_file_path .exists ()
154156 repo .submodules .init (submodules = ['TestGitRepository' ])
@@ -157,7 +159,7 @@ def test_specified_update(repo):
157159
158160
159161@utils .requires_network
160- def test_update_instance (repo ) :
162+ def test_update_instance (repo : Repository ) -> None :
161163 subrepo_file_path = Path (repo .workdir ) / SUBM_PATH / 'master.txt'
162164 assert not subrepo_file_path .exists ()
163165 sm = repo .submodules ['TestGitRepository' ]
@@ -168,7 +170,7 @@ def test_update_instance(repo):
168170
169171@utils .requires_network
170172@pytest .mark .parametrize ('depth' , [0 , 1 ])
171- def test_oneshot_update (repo , depth ) :
173+ def test_oneshot_update (repo : Repository , depth : int ) -> None :
172174 status = repo .submodules .status (SUBM_NAME )
173175 assert status == (SS .IN_HEAD | SS .IN_INDEX | SS .IN_CONFIG | SS .WD_UNINITIALIZED )
174176
@@ -190,7 +192,7 @@ def test_oneshot_update(repo, depth):
190192
191193@utils .requires_network
192194@pytest .mark .parametrize ('depth' , [0 , 1 ])
193- def test_oneshot_update_instance (repo , depth ) :
195+ def test_oneshot_update_instance (repo : Repository , depth : int ) -> None :
194196 subrepo_file_path = Path (repo .workdir ) / SUBM_PATH / 'master.txt'
195197 assert not subrepo_file_path .exists ()
196198 sm = repo .submodules [SUBM_NAME ]
@@ -206,12 +208,12 @@ def test_oneshot_update_instance(repo, depth):
206208
207209
208210@utils .requires_network
209- def test_head_id (repo ) :
211+ def test_head_id (repo : Repository ) -> None :
210212 assert repo .submodules [SUBM_PATH ].head_id == SUBM_HEAD_SHA
211213
212214
213215@utils .requires_network
214- def test_head_id_null (repo ) :
216+ def test_head_id_null (repo : Repository ) -> None :
215217 gitmodules_newlines = (
216218 '\n '
217219 '[submodule "uncommitted_submodule"]\n '
@@ -230,7 +232,7 @@ def test_head_id_null(repo):
230232
231233@utils .requires_network
232234@pytest .mark .parametrize ('depth' , [0 , 1 ])
233- def test_add_submodule (repo , depth ) :
235+ def test_add_submodule (repo : Repository , depth : int ) -> None :
234236 sm_repo_path = 'test/testrepo'
235237 sm = repo .submodules .add (SUBM_URL , sm_repo_path , depth = depth )
236238
@@ -250,7 +252,7 @@ def test_add_submodule(repo, depth):
250252
251253
252254@utils .requires_network
253- def test_submodule_status (repo ) :
255+ def test_submodule_status (repo : Repository ) -> None :
254256 common_status = SS .IN_HEAD | SS .IN_INDEX | SS .IN_CONFIG
255257
256258 # Submodule needs initializing
@@ -302,7 +304,7 @@ def test_submodule_status(repo):
302304 )
303305
304306
305- def test_submodule_cache (repo ) :
307+ def test_submodule_cache (repo : Repository ) -> None :
306308 # When the cache is turned on, looking up the same submodule twice must return the same git_submodule object
307309 repo .submodules .cache_all ()
308310 sm1 = repo .submodules [SUBM_NAME ]
@@ -317,7 +319,7 @@ def test_submodule_cache(repo):
317319 assert sm3 ._subm != sm4 ._subm
318320
319321
320- def test_submodule_reload (repo ) :
322+ def test_submodule_reload (repo : Repository ) -> None :
321323 sm = repo .submodules [SUBM_NAME ]
322324 assert sm .url == 'https://github.com/libgit2/TestGitRepository'
323325
0 commit comments