Skip to content

Commit cfd7d94

Browse files
committed
Fix nits I noticed
1 parent e035a87 commit cfd7d94

File tree

3 files changed

+48
-46
lines changed

3 files changed

+48
-46
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/.envrc
55
/.tox/
66
/build/
7+
/ci/
78
/dist/
89
/docs/_build/
910
/MANIFEST

pygit2/_libgit2/ffi.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ def new(a: Literal['char **']) -> _Pointer[char_pointer]: ...
337337
@overload
338338
def new(a: Literal['char[]', 'char []'], b: bytes | NULL_TYPE) -> ArrayC[char]: ...
339339
@overload
340-
def new(a: Literal['char ***']) -> Any: ... # For extensions_ptr in GET_EXTENSIONS
341-
@overload
342340
def new(a: Literal['char *[]'], b: int) -> ArrayC[char_pointer]: ... # For ext_array in SET_EXTENSIONS
343341
@overload
344342
def new(a: Literal['char *[]'], b: list[Any]) -> ArrayC[char_pointer]: ... # For string arrays

test/test_options.py

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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

247243
def test_homedir() -> None:
@@ -289,13 +285,20 @@ def test_user_agent_product() -> None:
289285

290286

291287
def 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-----\nMIIB...\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

301304
def test_mwindow_file_limit() -> None:

0 commit comments

Comments
 (0)