@@ -201,47 +201,43 @@ def test_extensions() -> None:
201201 # Get initial extensions list
202202 original_extensions = option (Option .GET_EXTENSIONS )
203203 assert isinstance (original_extensions , list )
204-
205- # Try to set extensions (this might fail depending on the setup)
206- try :
207- test_extensions = ['objectformat' , 'worktreeconfig' ]
208- option (Option .SET_EXTENSIONS , test_extensions , len (test_extensions ))
209-
210- # Verify they were set
211- new_extensions = option (Option .GET_EXTENSIONS )
212- assert isinstance (new_extensions , list )
213-
214- # Check that our extensions are present
215- # Note: libgit2 may add its own built-in extensions and sort them
216- for ext in test_extensions :
217- assert ext in new_extensions , f"Extension '{ ext } ' not found in { new_extensions } "
218-
219- # Test with empty list
204+
205+ # Set extensions
206+ test_extensions = ['objectformat' , 'worktreeconfig' ]
207+ option (Option .SET_EXTENSIONS , test_extensions , len (test_extensions ))
208+
209+ # Verify they were set
210+ new_extensions = option (Option .GET_EXTENSIONS )
211+ assert isinstance (new_extensions , list )
212+
213+ # Check that our extensions are present
214+ # Note: libgit2 may add its own built-in extensions and sort them
215+ for ext in test_extensions :
216+ assert ext in new_extensions , f"Extension '{ ext } ' not found in { new_extensions } "
217+
218+ # Test with empty list
219+ option (Option .SET_EXTENSIONS , [], 0 )
220+ empty_extensions = option (Option .GET_EXTENSIONS )
221+ assert isinstance (empty_extensions , list )
222+ # Even with empty input, libgit2 may have built-in extensions
223+
224+ # Test with a custom extension
225+ custom_extensions = ['myextension' , 'objectformat' ]
226+ option (Option .SET_EXTENSIONS , custom_extensions , len (custom_extensions ))
227+ custom_result = option (Option .GET_EXTENSIONS )
228+ assert 'myextension' in custom_result
229+ assert 'objectformat' in custom_result
230+
231+ # Restore original extensions
232+ if original_extensions :
233+ option (Option .SET_EXTENSIONS , original_extensions , len (original_extensions ))
234+ else :
235+ # Reset to empty list if there were no extensions
220236 option (Option .SET_EXTENSIONS , [], 0 )
221- empty_extensions = option (Option .GET_EXTENSIONS )
222- assert isinstance (empty_extensions , list )
223- # Even with empty input, libgit2 may have built-in extensions
224-
225- # Test with a custom extension
226- custom_extensions = ['myextension' , 'objectformat' ]
227- option (Option .SET_EXTENSIONS , custom_extensions , len (custom_extensions ))
228- custom_result = option (Option .GET_EXTENSIONS )
229- assert 'myextension' in custom_result
230- assert 'objectformat' in custom_result
231-
232- # Restore original extensions
233- if original_extensions :
234- option (Option .SET_EXTENSIONS , original_extensions , len (original_extensions ))
235- else :
236- # Reset to empty list if there were no extensions
237- option (Option .SET_EXTENSIONS , [], 0 )
238-
239- # Verify restoration
240- final_extensions = option (Option .GET_EXTENSIONS )
241- assert set (final_extensions ) == set (original_extensions )
242- except Exception :
243- # May fail if extensions cannot be modified
244- pass
237+
238+ # Verify restoration
239+ final_extensions = option (Option .GET_EXTENSIONS )
240+ assert set (final_extensions ) == set (original_extensions )
245241
246242
247243def test_homedir () -> None :
@@ -289,13 +285,20 @@ def test_user_agent_product() -> None:
289285
290286
291287def test_add_ssl_x509_cert () -> None :
292- # Test adding an SSL certificate (basic test, just ensure it doesn't crash)
288+ # Test adding an SSL certificate
289+ # This is a minimal test certificate (not valid, but tests the API)
293290 test_cert = "-----BEGIN CERTIFICATE-----\n MIIB...\n -----END CERTIFICATE-----"
291+
294292 try :
295293 option (Option .ADD_SSL_X509_CERT , test_cert )
296- except Exception :
297- # May fail depending on SSL backend
298- pass
294+ except pygit2 .GitError as e :
295+ # May fail if TLS backend doesn't support adding raw certs
296+ # or if the certificate format is invalid
297+ if (
298+ "TLS backend doesn't support" not in str (e )
299+ and "invalid" not in str (e ).lower ()
300+ ):
301+ raise
299302
300303
301304def test_mwindow_file_limit () -> None :
0 commit comments