[Python-modules-commits] [python-gnupg] 05/08: Avoid spurious test suite failures due to socket removal race.

Elena Grandi valhalla-guest at moszumanska.debian.org
Sat Apr 8 06:44:43 UTC 2017


This is an automated email from the git hooks/post-receive script.

valhalla-guest pushed a commit to branch gpg2
in repository python-gnupg.

commit 9bb7af658e91c2228183d8d1fbc759299116e629
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date:   Fri Feb 17 17:23:08 2017 -0500

    Avoid spurious test suite failures due to socket removal race.
    
    When gpg-agent notices that its primary socket has been removed, it
    shuts down.  When it shuts down, it closes and unlinks its other
    sockets as well.
    
    These rmtree invocations look like they might be getting the list of
    files to delete and then unlinking them one at a time.
    
    The result is a lot of errors like:
    
    File "/home/dkg/src/python-gnupg/python-gnupg/gnupg.py", line 1157, in gnupg.GPG.list_keys
    Failed example:
        shutil.rmtree("keys")
    Exception raised:
        Traceback (most recent call last):
          File "/usr/lib/python3.5/doctest.py", line 1321, in __run
            compileflags, 1), test.globs)
          File "<doctest gnupg.GPG.list_keys[1]>", line 1, in <module>
            shutil.rmtree("keys")
          File "/usr/lib/python3.5/shutil.py", line 480, in rmtree
            _rmtree_safe_fd(fd, path, onerror)
          File "/usr/lib/python3.5/shutil.py", line 438, in _rmtree_safe_fd
            onerror(os.unlink, fullname, sys.exc_info())
          File "/usr/lib/python3.5/shutil.py", line 436, in _rmtree_safe_fd
            os.unlink(name, dir_fd=topfd)
        FileNotFoundError: [Errno 2] No such file or directory: 'S.gpg-agent.extra'
    
    Simply making rmtree ignore errors (as this patch does) is enough to
    make the tests pass cleanly with GnuPG 2.1.18-6 and Python 3.5.3-1 on
    Debian stretch (testing).
---
 gnupg.py      | 8 ++++----
 test_gnupg.py | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gnupg.py b/gnupg.py
index 137a6b0..aad114b 100644
--- a/gnupg.py
+++ b/gnupg.py
@@ -1027,7 +1027,7 @@ class GPG(object):
         """Import a key from a keyserver
 
         >>> import shutil
-        >>> shutil.rmtree("keys")
+        >>> shutil.rmtree("keys", ignore_errors=True)
         >>> gpg = GPG(gnupghome="keys")
         >>> os.chmod('keys', 0x1C0)
         >>> result = gpg.recv_keys('keyserver.ubuntu.com', '92905378')  # doctest: +SKIP
@@ -1130,7 +1130,7 @@ class GPG(object):
         """ list the keys currently in the keyring
 
         >>> import shutil
-        >>> shutil.rmtree("keys")
+        >>> shutil.rmtree("keys", ignore_errors=True)
         >>> gpg = GPG(gnupghome="keys")
         >>> input = gpg.gen_key_input()
         >>> result = gpg.gen_key(input)
@@ -1184,7 +1184,7 @@ class GPG(object):
         """ search keyserver by query (using --search-keys option)
 
         >>> import shutil
-        >>> shutil.rmtree('keys')
+        >>> shutil.rmtree('keys', ignore_errors=True)
         >>> gpg = GPG(gnupghome='keys')
         >>> os.chmod('keys', 0x1C0)
         >>> result = gpg.search_keys('<vinay_sajip at hotmail.com>')  # doctest: +SKIP
@@ -1329,7 +1329,7 @@ class GPG(object):
 
         >>> import shutil
         >>> if os.path.exists("keys"):
-        ...     shutil.rmtree("keys")
+        ...     shutil.rmtree("keys", ignore_errors=True)
         >>> gpg = GPG(gnupghome="keys")
         >>> input = gpg.gen_key_input(passphrase='foo')
         >>> result = gpg.gen_key(input)
diff --git a/test_gnupg.py b/test_gnupg.py
index 3559e62..1633b39 100644
--- a/test_gnupg.py
+++ b/test_gnupg.py
@@ -153,7 +153,7 @@ class GPGTestCase(unittest.TestCase):
         if os.path.exists(hd):
             self.assertTrue(os.path.isdir(hd),
                             "Not a directory: %s" % hd)
-            shutil.rmtree(hd)
+            shutil.rmtree(hd, ignore_errors=True)
         self.homedir = hd
         self.gpg = gpg = gnupg.GPG(gnupghome=hd, gpgbinary=GPGBINARY)
         v = gpg.version
@@ -691,7 +691,7 @@ class GPGTestCase(unittest.TestCase):
             decfname = os.path.join(d, 'decrypted file')
             self.do_file_encryption_and_decryption(encfname, decfname)
         finally:
-            shutil.rmtree(d)
+            shutil.rmtree(d, ignore_errors=True)
         logger.debug("test_filename_with_spaces ends")
 
     @unittest.skip('requires network')
@@ -727,7 +727,7 @@ class GPGTestCase(unittest.TestCase):
             files = os.listdir(workdir)
             self.assertEqual(files, ["'ab?'"])
         finally:
-            shutil.rmtree(workdir)
+            shutil.rmtree(workdir, ignore_errors=True)
 
     def disabled_test_signing_with_uid(self):  # pragma: no cover
         "Test that signing with uids works. On hold for now."

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-gnupg.git



More information about the Python-modules-commits mailing list