Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_largefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,24 @@ def test_seekable(self):
self.assertTrue(f.seekable())


def skip_no_disk_space(path, required):
def decorator(fun):
def wrapper(*args, **kwargs):
if shutil.disk_usage(os.path.realpath(path)).free < required:
hsize = int(required / 1024 / 1024)
raise unittest.SkipTest(
f"required {hsize} MiB of free disk space")
return fun(*args, **kwargs)
return wrapper
return decorator


class TestCopyfile(LargeFileTest, unittest.TestCase):
open = staticmethod(io.open)

# Exact required disk space would be (size * 2), but let's give it a
# bit more tolerance.
@skip_no_disk_space(TESTFN, size * 2.5)
def test_it(self):
# Internally shutil.copyfile() can use "fast copy" methods like
# os.sendfile().
Expand Down Expand Up @@ -200,6 +215,9 @@ def run(sock):
self.thread.start()
event.set()

# Exact required disk space would be (size * 2), but let's give it a
# bit more tolerance.
@skip_no_disk_space(TESTFN, size * 2.5)
def test_it(self):
port = find_unused_port()
with socket.create_server(("", port)) as sock:
Expand Down