allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#6448] Capture zip stderr and log on exception
Date Fri, 19 Jul 2013 21:00:52 GMT
Updated Branches:
  refs/heads/master ec7edd86a -> 5cddfe0fd


[#6448] Capture zip stderr and log on exception

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/5cddfe0f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/5cddfe0f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/5cddfe0f

Branch: refs/heads/master
Commit: 5cddfe0fd350f3aa93a1551bd952fb465d69d26c
Parents: ec7edd8
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Fri Jul 19 13:19:22 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Jul 19 21:00:37 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py     | 10 ++++--
 Allura/allura/tests/unit/test_repo.py | 49 ++++++++++++++++++++++--------
 2 files changed, 45 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5cddfe0f/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 3d893cc..a3d9a44 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -23,7 +23,7 @@ import mimetypes
 import logging
 import string
 import re
-from subprocess import Popen
+from subprocess import Popen, PIPE
 from difflib import SequenceMatcher
 from hashlib import sha1
 from datetime import datetime
@@ -741,7 +741,13 @@ def zipdir(source, zipfile, exclude=None):
     command = [zipbin, '-r', zipfile, source_fn]
     if exclude:
         command += ['-x', exclude]
-    Popen(command, cwd=working_dir).communicate()
+    p = Popen(command, cwd=working_dir, stdout=PIPE, stderr=PIPE)
+    stdout, stderr = p.communicate()
+    if p.returncode != 0:
+        raise Exception(
+            "Command: {0} returned non-zero exit code {1}\n"
+            "STDOUT: {2}\n"
+            "STDERR: {3}".format(command, p.returncode, stdout, stderr))
 
 
 Mapper.compile_all()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5cddfe0f/Allura/allura/tests/unit/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_repo.py b/Allura/allura/tests/unit/test_repo.py
index 5fb6590..499f604 100644
--- a/Allura/allura/tests/unit/test_repo.py
+++ b/Allura/allura/tests/unit/test_repo.py
@@ -288,15 +288,40 @@ class TestCommit(unittest.TestCase):
         commit.get_tree.assert_called_with(create=True)
 
 
-@patch('allura.model.repository.Popen')
-@patch('allura.model.repository.tg')
-def test_zipdir(tg, popen):
-    tg.config = {'scm.repos.tarball.zip_binary': '/bin/zip'}
-    src = '/fake/path/to/repo'
-    zipfile = '/fake/zip/file.tmp'
-    zipdir(src, zipfile)
-    popen.assert_called_once_with(['/bin/zip', '-r', zipfile, 'repo'], cwd='/fake/path/to')
-    popen.reset_mock()
-    src = '/fake/path/to/repo/'
-    zipdir(src, zipfile, exclude='file.txt')
-    popen.assert_called_once_with(['/bin/zip', '-r', zipfile, 'repo', '-x', 'file.txt'],
cwd='/fake/path/to')
+class TestZipDir(unittest.TestCase):
+    @patch('allura.model.repository.Popen')
+    @patch('allura.model.repository.tg')
+    def test_popen_called(self, tg, popen):
+        from subprocess import PIPE
+        popen.return_value.communicate.return_value = 1, 2
+        popen.return_value.returncode = 0
+        tg.config = {'scm.repos.tarball.zip_binary': '/bin/zip'}
+        src = '/fake/path/to/repo'
+        zipfile = '/fake/zip/file.tmp'
+        zipdir(src, zipfile)
+        popen.assert_called_once_with(['/bin/zip', '-r', zipfile, 'repo'],
+                cwd='/fake/path/to', stdout=PIPE, stderr=PIPE)
+        popen.reset_mock()
+        src = '/fake/path/to/repo/'
+        zipdir(src, zipfile, exclude='file.txt')
+        popen.assert_called_once_with(
+                ['/bin/zip', '-r', zipfile, 'repo', '-x', 'file.txt'],
+                cwd='/fake/path/to', stdout=PIPE, stderr=PIPE)
+
+    @patch('allura.model.repository.Popen')
+    @patch('allura.model.repository.tg')
+    def test_exception_logged(self, tg, popen):
+        tg.config = {'scm.repos.tarball.zip_binary': '/bin/zip'}
+        popen.return_value.communicate.return_value = 1, 2
+        popen.return_value.returncode = 1
+        src = '/fake/path/to/repo'
+        zipfile = '/fake/zip/file.tmp'
+        with self.assertRaises(Exception) as cm:
+            zipdir(src, zipfile)
+        emsg = str(cm.exception)
+        self.assertTrue(
+                "Command: "
+                "['/bin/zip', '-r', '/fake/zip/file.tmp', 'repo'] "
+                "returned non-zero exit code 1" in emsg)
+        self.assertTrue("STDOUT: 1" in emsg)
+        self.assertTrue("STDERR: 2" in emsg)


Mime
View raw message