From 4acce68e3368bb861c423e559ee4f106518c8106 Mon Sep 17 00:00:00 2001 From: gholt Date: Tue, 20 May 2014 15:29:51 +0000 Subject: [PATCH] Make the new xprofile tests optional. On Lucid at least, xprofile doesn't work. While others try to figure out the underlying issue, this patch would just skip the tests if the profiling code can not be imported. Change-Id: I0fee3f729742cc727edc2adabb4ed782bea7798f --- test/unit/common/middleware/test_xprofile.py | 36 ++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/test/unit/common/middleware/test_xprofile.py b/test/unit/common/middleware/test_xprofile.py index 4907ad3772..b49c2c7c05 100644 --- a/test/unit/common/middleware/test_xprofile.py +++ b/test/unit/common/middleware/test_xprofile.py @@ -19,20 +19,24 @@ import shutil import StringIO import tempfile import unittest +from nose import SkipTest from swift import gettext_ as _ -from swift.common.middleware import xprofile -from swift.common.middleware.xprofile import ProfileMiddleware -from swift.common.middleware.x_profile.exceptions import PLOTLIBNotInstalled,\ - MethodNotAllowed, NotFoundException, ODFLIBNotInstalled -from swift.common.middleware.x_profile.html_viewer import HTMLViewer,\ - PLOTLIB_INSTALLED -from swift.common.middleware.x_profile.profile_model import Stats2,\ - ProfileLog, ODFLIB_INSTALLED - - from swift.common.swob import Request, Response +try: + from swift.common.middleware import xprofile + from swift.common.middleware.xprofile import ProfileMiddleware + from swift.common.middleware.x_profile.exceptions import ( + MethodNotAllowed, NotFoundException, ODFLIBNotInstalled, + PLOTLIBNotInstalled) + from swift.common.middleware.x_profile.html_viewer import ( + HTMLViewer, PLOTLIB_INSTALLED) + from swift.common.middleware.x_profile.profile_model import ( + ODFLIB_INSTALLED, ProfileLog, Stats2) +except ImportError: + xprofile = None + class FakeApp(object): @@ -45,6 +49,8 @@ class FakeApp(object): class TestXProfile(unittest.TestCase): def test_get_profiler(self): + if xprofile is None: + raise SkipTest self.assert_(xprofile.get_profiler('cProfile') is not None) self.assert_(xprofile.get_profiler('eventlet.green.profile') is not None) @@ -53,6 +59,8 @@ class TestXProfile(unittest.TestCase): class TestProfilers(unittest.TestCase): def setUp(self): + if xprofile is None: + raise SkipTest self.profilers = [xprofile.get_profiler('cProfile'), xprofile.get_profiler('eventlet.green.profile')] @@ -75,6 +83,8 @@ class TestProfilers(unittest.TestCase): class TestProfileMiddleware(unittest.TestCase): def setUp(self): + if xprofile is None: + raise SkipTest self.got_statuses = [] self.app = ProfileMiddleware(FakeApp, {}) self.tempdir = os.path.dirname(self.app.log_filename_prefix) @@ -182,6 +192,8 @@ class TestProfileMiddleware(unittest.TestCase): class Test_profile_log(unittest.TestCase): def setUp(self): + if xprofile is None: + raise SkipTest self.log_filename_prefix1 = tempfile.mkdtemp() + '/unittest.profile' self.profile_log1 = ProfileLog(self.log_filename_prefix1, False) self.pids1 = ['123', '456', str(os.getpid())] @@ -266,6 +278,8 @@ class Test_profile_log(unittest.TestCase): class Test_html_viewer(unittest.TestCase): def setUp(self): + if xprofile is None: + raise SkipTest self.app = ProfileMiddleware(FakeApp, {}) self.log_files = [] self.tempdir = tempfile.mkdtemp() @@ -454,6 +468,8 @@ class Test_html_viewer(unittest.TestCase): class TestStats2(unittest.TestCase): def setUp(self): + if xprofile is None: + raise SkipTest self.profile_file = tempfile.mktemp('profile', 'unittest') self.profilers = [xprofile.get_profiler('cProfile'), xprofile.get_profiler('eventlet.green.profile')]