[py-svn] py-trunk commit 9fa2fbdcde2d: add ignore_errors to local.remove()

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Jun 7 20:57:57 CEST 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User holger krekel <holger at merlinux.eu>
# Date 1275936516 -7200
# Node ID 9fa2fbdcde2d52974731617c87da2f12f7923ae0
# Parent  eb9c9a4ba265a25ef7ca9c0fc3a4a7da470b07e5
add ignore_errors to local.remove()

--- a/py/_path/local.py
+++ b/py/_path/local.py
@@ -157,14 +157,18 @@ class LocalPath(FSBase):
     def __lt__(self, other):
         return str(self) < str(other)
 
-    def remove(self, rec=1):
-        """ remove a file or directory (or a directory tree if rec=1).  """
+    def remove(self, rec=1, ignore_errors=False):
+        """ remove a file or directory (or a directory tree if rec=1). 
+        if ignore_errors is True, errors while removing directories will 
+        be ignored.
+        """
         if self.check(dir=1, link=0):
             if rec:
                 # force remove of readonly files on windows 
                 if iswin32: 
                     self.chmod(448, rec=1) # octcal 0700
-                py.error.checked_call(py.std.shutil.rmtree, self.strpath)
+                py.error.checked_call(py.std.shutil.rmtree, self.strpath,
+                    ignore_errors=ignore_errors)
             else:
                 py.error.checked_call(os.rmdir, self.strpath)
         else:

--- a/testing/path/test_local.py
+++ b/testing/path/test_local.py
@@ -60,6 +60,17 @@ class TestLocalPath(common.CommonFSTests
         readonly_dir.remove()
         assert not readonly_dir.check(exists=1)
 
+    def test_remove_routes_ignore_errors(self, tmpdir, monkeypatch):
+        l = []
+        monkeypatch.setattr(py.std.shutil, 'rmtree', 
+            lambda *args, **kwargs: l.append(kwargs))
+        tmpdir.remove()
+        assert not l[0]['ignore_errors'] 
+        for val in (True, False):
+            l[:] = []
+            tmpdir.remove(ignore_errors=val)
+            assert l[0]['ignore_errors'] == val
+
     def test_initialize_curdir(self):
         assert str(local()) == py.std.os.getcwd()
 

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,6 +12,7 @@ Bug fixes / Maintenance
 - streamline py.path.local.mkdtemp implementation and usage
 - don't print empty lines when showing junitxml-filename
 - fix py.code.compile(source) to generate unique filenames
+- add optional boolean ignore_errors parameter to py.path.local.remove
 
 Changes between 1.3.0 and 1.3.1
 ==================================================



More information about the pytest-commit mailing list