]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39488: Skip test_largefile tests if not enough disk space (GH-18261)
authorGiampaolo Rodola <g.rodola@gmail.com>
Wed, 5 Feb 2020 17:20:52 +0000 (18:20 +0100)
committerGitHub <noreply@github.com>
Wed, 5 Feb 2020 17:20:52 +0000 (18:20 +0100)
Lib/test/test_largefile.py

index e309282d73e2a6ef584fa5696fc0f878a84e5f2d..c254b047e1ec52ef807e5199c1442dd8b7953f8e 100644 (file)
@@ -151,9 +151,24 @@ class TestFileMethods(LargeFileTest):
                 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().
@@ -200,6 +215,9 @@ class TestSocketSendfile(LargeFileTest, unittest.TestCase):
         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: