summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2016-03-07 09:38:11 +0100
committerIan Cordasco <graffatcolmingov@gmail.com>2016-04-01 17:41:06 -0500
commit9b5f422c34bdb9d09f41c74c2b919a52824d7639 (patch)
treea19a878d48c9c8b9547c3f579d65405436ad789c
parentb4d21581e267e821d5ac524b4dfc63c149ffcfd5 (diff)
downloadpbr-9b5f422c34bdb9d09f41c74c2b919a52824d7639.tar.gz
package: fix wrong catch in email parsing
email.MessageError exception does not exist, so if an error occur, the code block will fail completely. Fix the path to the correct class. Co-Authored-By: Ian Cordasco <graffatcolmingov@gmail.com> Change-Id: Ic4e69405ca6346191da66a86f0b7aa5b3b75bed6
-rw-r--r--pbr/packaging.py3
-rw-r--r--pbr/tests/test_packaging.py15
2 files changed, 17 insertions, 1 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py
index 0f05574..b78b4d9 100644
--- a/pbr/packaging.py
+++ b/pbr/packaging.py
@@ -23,6 +23,7 @@ from __future__ import unicode_literals
from distutils.command import install as du_install
from distutils import log
import email
+import email.errors
import os
import re
import sys
@@ -663,7 +664,7 @@ def _get_version_from_pkg_metadata(package_name):
continue
try:
pkg_metadata = email.message_from_file(pkg_metadata_file)
- except email.MessageError:
+ except email.errors.MessageError:
continue
# Check to make sure we're in our own dir
diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py
index f5ab7c2..50ff2ad 100644
--- a/pbr/tests/test_packaging.py
+++ b/pbr/tests/test_packaging.py
@@ -38,6 +38,8 @@
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+import email
+import email.errors
import imp
import os
import re
@@ -477,6 +479,19 @@ class TestVersions(base.BaseTestCase):
self.useFixture(GPGKeyFixture())
self.useFixture(base.DiveDir(self.package_dir))
+ def test_email_parsing_errors_are_handled(self):
+ mocked_open = mock.mock_open()
+ with mock.patch('pbr.packaging.open', mocked_open):
+ with mock.patch('email.message_from_file') as message_from_file:
+ message_from_file.side_effect = [
+ email.errors.MessageError('Test'),
+ {'Name': 'pbr_testpackage'}]
+ version = packaging._get_version_from_pkg_metadata(
+ 'pbr_testpackage')
+
+ self.assertTrue(message_from_file.called)
+ self.assertIsNone(version)
+
def test_capitalized_headers(self):
self.repo.commit()
self.repo.tag('1.2.3')