]> review.fuel-infra Code Review - openstack-build/horizon-build.git/commitdiff
Update Remove_selenium_dependency_when_not_using_selenium_tests.patch
authorThomas Goirand <thomas@goirand.fr>
Sat, 18 Oct 2014 07:41:09 +0000 (15:41 +0800)
committerThomas Goirand <thomas@goirand.fr>
Sat, 18 Oct 2014 07:42:22 +0000 (15:42 +0800)
Rewritten-From: 3a0f98bf07e4d3dc315a303852e43d1e6d629f6b

xenial/debian/patches/Remove_selenium_dependency_when_not_using_selenium_tests.patch

index b3725d7df79e2ca145e86e8e5d046f5435170edb..e72bf5ca49c0b6f2f5c92caf441f589ca9f7640c 100644 (file)
@@ -8,13 +8,14 @@ Origin: upstream, https://review.openstack.org/#/c/126777/
 Last-Update: 2014-10-08
 
 diff --git a/horizon/test/webdriver.py b/horizon/test/webdriver.py
-index 0974e91..7b832c8 100644
+index 0974e91..8750c9d 100644
 --- a/horizon/test/webdriver.py
 +++ b/horizon/test/webdriver.py
-@@ -17,62 +17,70 @@
+@@ -17,62 +17,79 @@
  #   limitations under the License.
  #
  
++import logging
 +import os
  import platform
  import shutil
@@ -22,17 +23,20 @@ index 0974e91..7b832c8 100644
  
 -from selenium.common import exceptions as selenium_exceptions
 -from selenium.webdriver import firefox
-+from django.utils import unittest
++LOG = logging.getLogger(__name__)
  
-+with_sel = os.environ.get('WITH_SELENIUM', False)
-+if with_sel:
++try:
++    # NOTE: Several distribution can't ship selenium due to its
++    # non-free license. So they have to patch it out of test-requirements.txt
++    # Avoid import failure and force not running selenium tests.
++    # The entire file is encapsulated in the try block because the classes
++    # inherit from the firefox class contained in selenium.webdriver, and
++    # python will throw a NameError if the import is skipped.
 +    from selenium.common import exceptions as selenium_exceptions
 +    from selenium.webdriver import firefox
  
 -class FirefoxBinary(firefox.firefox_binary.FirefoxBinary):
 -    """Workarounds selenium firefox issues.
-+    @unittest.skipUnless(os.environ.get('WITH_SELENIUM', False),
-+                        "The WITH_SELENIUM env variable is not set.")
 +    class FirefoxBinary(firefox.firefox_binary.FirefoxBinary):
 +        """Workarounds selenium firefox issues.
  
@@ -95,27 +99,13 @@ index 0974e91..7b832c8 100644
 +                command, stdout=self._log_file, stderr=subprocess.STDOUT,
 +                env=self._firefox_env)
  
-+    @unittest.skipUnless(os.environ.get('WITH_SELENIUM', False),
-+                        "The WITH_SELENIUM env variable is not set.")
 +    class WebDriver(firefox.webdriver.WebDriver):
 +        """Workarounds selenium firefox issues."""
  
 -class WebDriver(firefox.webdriver.WebDriver):
 -    """Workarounds selenium firefox issues."""
--
--    def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
--                 capabilities=None, proxy=None):
--        try:
--            super(WebDriver, self).__init__(
--                firefox_profile, FirefoxBinary(), timeout, capabilities, proxy)
--        except selenium_exceptions.WebDriverException:
--            # If we can't start, cleanup profile
--            shutil.rmtree(self.profile.path)
--            if self.profile.tempfolder is not None:
--                shutil.rmtree(self.profile.tempfolder)
--            raise
 +        def __init__(self, firefox_profile=None, firefox_binary=None,
-+                    timeout=30, capabilities=None, proxy=None):
++                     timeout=30, capabilities=None, proxy=None):
 +            try:
 +                super(WebDriver, self).__init__(
 +                    firefox_profile, FirefoxBinary(), timeout, capabilities,
@@ -126,3 +116,21 @@ index 0974e91..7b832c8 100644
 +                if self.profile.tempfolder is not None:
 +                    shutil.rmtree(self.profile.tempfolder)
 +                raise
+-    def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30,
+-                 capabilities=None, proxy=None):
+-        try:
+-            super(WebDriver, self).__init__(
+-                firefox_profile, FirefoxBinary(), timeout, capabilities, proxy)
+-        except selenium_exceptions.WebDriverException:
+-            # If we can't start, cleanup profile
+-            shutil.rmtree(self.profile.path)
+-            if self.profile.tempfolder is not None:
+-                shutil.rmtree(self.profile.tempfolder)
+-            raise
++except ImportError as e:
++    # NOTE(saschpe): Several distribution can't ship selenium due to its
++    # non-free license. So they have to patch it out of test-requirements.txt
++    # Avoid import failure and force not running selenium tests.
++    LOG.warning("{0}, force WITH_SELENIUM=False".format(str(e)))
++    os.environ['WITH_SELENIUM'] = ''