Skip to content

Commit 08b1971

Browse files
committed
Hide warnings
1 parent 6a8ea6e commit 08b1971

File tree

14 files changed

+108
-75
lines changed

14 files changed

+108
-75
lines changed

dulwich/client.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,12 +1478,7 @@ def archive(
14781478

14791479
@staticmethod
14801480
def _warn_filter_objects() -> None:
1481-
import warnings
1482-
1483-
warnings.warn(
1484-
"object filtering not recognized by server, ignoring",
1485-
UserWarning,
1486-
)
1481+
logging.warning("object filtering not recognized by server, ignoring")
14871482

14881483

14891484
def check_wants(wants: Set[bytes], refs: Mapping[bytes, bytes]) -> None:

dulwich/signature.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,12 +1293,13 @@ def verify(self, data: bytes, signature: bytes) -> None:
12931293
args.extend(["-r", self.revocation_file])
12941294

12951295
try:
1296-
subprocess.run(
1297-
args,
1298-
stdin=open(data_filename, "rb"),
1299-
capture_output=True,
1300-
check=True,
1301-
)
1296+
with open(data_filename, "rb") as data_file:
1297+
subprocess.run(
1298+
args,
1299+
stdin=data_file,
1300+
capture_output=True,
1301+
check=True,
1302+
)
13021303
except subprocess.CalledProcessError as e:
13031304
raise BadSignature(
13041305
f"SSH signature verification failed: {e.stderr.decode('utf-8', errors='replace')}"

tests/compat/test_partial_clone.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,15 @@ def determine_wants(refs, depth=None):
390390
# Get all refs
391391
return list(refs.values())
392392

393-
# Fetch with filter
394-
result = client.fetch(
395-
path,
396-
dest_repo,
397-
determine_wants=determine_wants,
398-
progress=None,
399-
filter_spec=b"blob:none",
400-
)
393+
# Fetch with filter (may warn if server doesn't support filtering)
394+
with self.assertLogs(level="WARNING"):
395+
result = client.fetch(
396+
path,
397+
dest_repo,
398+
determine_wants=determine_wants,
399+
progress=None,
400+
filter_spec=b"blob:none",
401+
)
401402

402403
# The fetch should succeed with partial clone
403404
self.assertIsNotNone(result)
@@ -430,13 +431,14 @@ def test_clone_with_filter(self) -> None:
430431

431432
client, path = get_transport_and_path(f"git://localhost:{daemon_port}/")
432433

433-
# Clone with blob:limit filter
434-
cloned_repo = client.clone(
435-
path,
436-
dest_path,
437-
mkdir=False,
438-
filter_spec=b"blob:limit=100",
439-
)
434+
# Clone with blob:limit filter (may warn if server doesn't support filtering)
435+
with self.assertLogs(level="WARNING"):
436+
cloned_repo = client.clone(
437+
path,
438+
dest_path,
439+
mkdir=False,
440+
filter_spec=b"blob:limit=100",
441+
)
440442
self.addCleanup(cloned_repo.close)
441443

442444
# Verify clone succeeded
@@ -483,6 +485,11 @@ def _start_git_daemon(self, repo_path):
483485
def cleanup_daemon():
484486
daemon_process.terminate()
485487
daemon_process.wait(timeout=2)
488+
# Close pipes to avoid ResourceWarning
489+
if daemon_process.stdout:
490+
daemon_process.stdout.close()
491+
if daemon_process.stderr:
492+
daemon_process.stderr.close()
486493

487494
self.addCleanup(cleanup_daemon)
488495

tests/porcelain/test_ignore.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,10 @@ def test_quote_path_true_unicode_filenames(self) -> None:
5959

6060
# Test with quote_path=True (default)
6161
abs_paths = [os.path.join(self.test_dir, f) for f in test_files]
62-
ignored_quoted = set(
63-
check_ignore(self.test_dir, abs_paths, quote_path=True)
64-
)
62+
ignored_quoted = set(check_ignore(self.test_dir, abs_paths, quote_path=True))
6563

6664
# Test with quote_path=False
67-
ignored_unquoted = set(
68-
check_ignore(self.test_dir, abs_paths, quote_path=False)
69-
)
65+
ignored_unquoted = set(check_ignore(self.test_dir, abs_paths, quote_path=False))
7066

7167
# Verify quoted results
7268
expected_quoted = {
@@ -100,12 +96,8 @@ def test_quote_path_ascii_filenames(self) -> None:
10096

10197
# Test both settings
10298
abs_paths = [os.path.join(self.test_dir, f) for f in test_files]
103-
ignored_quoted = set(
104-
check_ignore(self.test_dir, abs_paths, quote_path=True)
105-
)
106-
ignored_unquoted = set(
107-
check_ignore(self.test_dir, abs_paths, quote_path=False)
108-
)
99+
ignored_quoted = set(check_ignore(self.test_dir, abs_paths, quote_path=True))
100+
ignored_unquoted = set(check_ignore(self.test_dir, abs_paths, quote_path=False))
109101

110102
# Both should return the same results for ASCII filenames
111103
expected = {"test.txt", "file.tmp"}

tests/porcelain/test_lfs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ def test_clone_with_builtin_lfs_no_config(self):
276276
with self.assertRaises(KeyError):
277277
config.get((b"filter", b"lfs"), b"smudge")
278278

279-
# Clone the repository
280-
cloned_repo = porcelain.clone(source_dir, clone_dir)
279+
# Clone the repository (may warn about missing LFS objects)
280+
with self.assertLogs("dulwich.lfs", level="WARNING"):
281+
cloned_repo = porcelain.clone(source_dir, clone_dir)
281282

282283
# Verify that built-in LFS filter was used
283284
normalizer = cloned_repo.get_blob_normalizer()

tests/test_annotate.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
"""Tests for annotate support."""
2020

21-
import os
2221
import tempfile
23-
import unittest
2422
from typing import Any
2523
from unittest import TestCase
2624

tests/test_bisect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import tempfile
2727

2828
from dulwich.bisect import BisectState
29-
from dulwich.objects import Tree
3029
from dulwich.repo import Repo
3130
from dulwich.tests.utils import make_commit
3231

tests/test_filters.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ def test_optional_filter_failure_fallback(self) -> None:
385385
f.write(b"test content\n")
386386

387387
# Adding file should work and fallback to original content
388-
worktree.stage(["test.txt"])
388+
with self.assertLogs(level="WARNING"):
389+
worktree.stage(["test.txt"])
389390

390391
# Check that original content was preserved
391392
index = self.repo.open_index()
@@ -579,7 +580,8 @@ def test_fallback_to_individual_commands(self):
579580
)
580581

581582
test_data = b"hello world\n"
582-
result = driver.clean(test_data)
583+
with self.assertLogs(level="WARNING"):
584+
result = driver.clean(test_data)
583585

584586
# Should fallback to tr command and uppercase
585587
self.assertEqual(result, b"HELLO WORLD\n")
@@ -1156,7 +1158,8 @@ def test_malformed_process_response_handling(self):
11561158
)
11571159

11581160
# Should fallback to clean_cmd when process fails
1159-
result = driver.clean(b"test data")
1161+
with self.assertLogs(level="WARNING"):
1162+
result = driver.clean(b"test data")
11601163
self.assertEqual(result, b"test data")
11611164

11621165
finally:

tests/test_lfs_integration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,6 @@ def test_missing_lfs_object(self) -> None:
145145
blob.data = pointer.to_bytes()
146146

147147
# Checkout should return the pointer as-is when object is missing
148-
checked_out = self.normalizer.checkout_normalize(blob, b"missing.bin")
148+
with self.assertLogs("dulwich.lfs", level="WARNING"):
149+
checked_out = self.normalizer.checkout_normalize(blob, b"missing.bin")
149150
self.assertEqual(checked_out.data, blob.data)

tests/test_rebase.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
"""Tests for dulwich.rebase."""
2323

2424
import importlib.util
25-
import os
26-
import tempfile
2725

2826
from dulwich.objects import Blob, Commit, Tree
2927
from dulwich.rebase import (
@@ -36,7 +34,7 @@
3634
rebase,
3735
start_interactive,
3836
)
39-
from dulwich.repo import MemoryRepo, Repo
37+
from dulwich.repo import MemoryRepo
4038
from dulwich.tests.utils import make_commit
4139

4240
from . import DependencyMissing, TestCase

0 commit comments

Comments
 (0)