Skip to content

Commit d361a00

Browse files
committed
Get more output about how the windows test is failing.
1 parent 495e560 commit d361a00

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

Lib/shutil.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ def _dst_opener(path, flags):
444444
elif _WINDOWS and file_size > 0:
445445
_copyfileobj_readinto(fsrc, fdst, min(file_size, COPY_BUFSIZE))
446446
return dst
447-
copyfileobj(fsrc, fdst)
447+
from unittest import mock
448+
if isinstance(copyfileobj, mock.Mock):
449+
copyfileobj(fsrc, f"_WINDOWS: {_WINDOWS}\nfile_size: {file_size}")
450+
else:
451+
copyfileobj(fsrc, fdst)
448452

449453
# Issue 43219, raise a less confusing exception
450454
except IsADirectoryError as e:

Lib/test/test_shutil.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,8 +3127,13 @@ def test_file_offset(self):
31273127
def test_win_impl(self):
31283128
# Make sure alternate Windows implementation is called.
31293129
with unittest.mock.patch("shutil._copyfileobj_readinto") as m:
3130-
shutil.copyfile(TESTFN, TESTFN2)
3131-
assert m.called
3130+
with unittest.mock.patch("shutil._fastcopy_fcopyfile") as m1:
3131+
with unittest.mock.patch("shutil._fastcopy_copy_file_range") as m2:
3132+
with unittest.mock.patch("shutil._fastcopy_sendfile") as m3:
3133+
with unittest.mock.patch("shutil.copyfileobj") as m4:
3134+
shutil.copyfile(TESTFN, TESTFN2)
3135+
3136+
assert m.called, f"_copyfileobj_readinto: {m.called}\n_fastcopy_fcopyfile: {m1.called}\n_fastcopy_copy_file_range: {m2.called}\n_fastcopy_sendfile: {m3.called}\ncopyfileobj: {m4.called}\ncalled_with: {m4.call_args}"
31323137

31333138
# File size is 2 MiB but max buf size should be 1 MiB.
31343139
self.assertEqual(m.call_args[0][2], 1 * 1024 * 1024)

0 commit comments

Comments
 (0)