[MediaWiki-commits] [Gerrit] pywikibot/core[master]: Fix HttpServerProblemTestCase.test_502 failing

2017-01-03 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/330281 )

Change subject: Fix HttpServerProblemTestCase.test_502 failing
..


Fix HttpServerProblemTestCase.test_502 failing

HttpbinTestCase class moved to aspects.py, pytest_httpbin is now used
instead of httpbin.org site only if test case inherits HttpbinTestCase

Bug: T154452
Change-Id: Ica26594a553de2e4555ffba56056141a56c3c6c5
---
M tests/aspects.py
M tests/http_tests.py
2 files changed, 63 insertions(+), 61 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/aspects.py b/tests/aspects.py
index 305c4be..993f9cd 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -7,7 +7,7 @@
 mixin to show cache usage is included.
 """
 #
-# (C) Pywikibot team, 2014-2015
+# (C) Pywikibot team, 2014-2017
 #
 # Distributed under the terms of the MIT license.
 #
@@ -29,7 +29,6 @@
 UITestCase:
 Not integrated; direct subclass of unittest.TestCase.
 """
-import imp
 import inspect
 import itertools
 import os
@@ -60,6 +59,16 @@
 add_metaclass, execute_pwb, DrySite, DryRequest,
 WarningSourceSkipContextManager, AssertAPIErrorContextManager,
 )
+
+try:
+import pytest_httpbin
+optional_pytest_httpbin_cls_decorator = 
pytest_httpbin.use_class_based_httpbin
+except ImportError:
+pytest_httpbin = None
+
+def optional_pytest_httpbin_cls_decorator(f):
+"""Empty decorator in case pytest_httpbin is not installed."""
+return f
 
 OSWIN32 = (sys.platform == 'win32')
 
@@ -484,13 +493,10 @@
 if not hasattr(cls, 'sites'):
 return
 
-# Check is pytest is used and pytest_httpbin module is installed.
-if hasattr(sys, '_test_runner_pytest'):
-try:
-imp.find_module('pytest_httpbin')
-httpbin_used = True
-except ImportError:
-httpbin_used = False
+if issubclass(cls, HttpbinTestCase):
+# If test uses httpbin, then check is pytest test runner is used
+# and pytest_httpbin module is installed.
+httpbin_used = hasattr(sys, '_test_runner_pytest') and 
pytest_httpbin
 else:
 httpbin_used = False
 
@@ -1658,3 +1664,43 @@
 CapturingTestCase.process_assert,
 CapturingTestCase.patch_assert,
 ]
+
+
+@optional_pytest_httpbin_cls_decorator
+class HttpbinTestCase(TestCase):
+
+"""
+Custom test case class, which allows doing dry httpbin tests using 
pytest-httpbin.
+
+Test cases, which use httpbin, need to inherit this class.
+"""
+
+sites = {
+'httpbin': {
+'hostname': 'httpbin.org',
+},
+}
+
+def get_httpbin_url(self, path=''):
+"""
+Return url of httpbin.
+
+If pytest is used, returns url of local httpbin server.
+Otherwise, returns: http://httpbin.org
+"""
+if hasattr(self, 'httpbin'):
+return self.httpbin.url + path
+else:
+return 'http://httpbin.org' + path
+
+def get_httpbin_hostname(self):
+"""
+Return httpbin hostname.
+
+If pytest is used, returns hostname of local httpbin server.
+Otherwise, returns: httpbin.org
+"""
+if hasattr(self, 'httpbin'):
+return '{0}:{1}'.format(self.httpbin.host, self.httpbin.port)
+else:
+return 'httpbin.org'
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 72db94c..ca90f76 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 """Tests for http module."""
 #
-# (C) Pywikibot team, 2014-2015
+# (C) Pywikibot team, 2014-2017
 #
 # Distributed under the terms of the MIT license.
 #
@@ -25,57 +25,13 @@
 )
 
 from tests import join_images_path
-from tests.aspects import unittest, TestCase, DeprecationTestCase, 
require_modules
-
-try:
-import pytest_httpbin
-optional_pytest_httpbin_cls_decorator = 
pytest_httpbin.use_class_based_httpbin
-except ImportError:
-pytest_httpbin = None
-
-def optional_pytest_httpbin_cls_decorator(f):
-"""Empty decorator in case pytest_httpbin is not installed."""
-return f
-
-
-@optional_pytest_httpbin_cls_decorator
-class HttpbinTestCase(TestCase):
-
-"""
-Custom test case class, which allows doing dry httpbin tests using 
pytest-httpbin.
-
-Test cases, which use httpbin, need to inherit this class.
-"""
-
-sites = {
-'httpbin': {
-'hostname': 'httpbin.org',
-},
-}
-
-def get_httpbin_url(self, path=''):
-"""
-Return url of httpbin.
-
-If pytest is used, returns url of local httpbin server.
-Otherwise, returns: http://httpbin.org
-"""
-if hasattr(self, 'httpbin'):
-return self.httpbin.url + path
-

[MediaWiki-commits] [Gerrit] pywikibot/core[master]: Fix HttpServerProblemTestCase.test_502 failing

2017-01-03 Thread Phantom42 (Code Review)
Phantom42 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/330281 )

Change subject: Fix HttpServerProblemTestCase.test_502 failing
..

Fix HttpServerProblemTestCase.test_502 failing

HttpbinTestCase class moved to aspects.py, pytest_httpbin is now used
instead of httpbin.org site only if test case inherits HttpbinTestCase

Bug: T154452
Change-Id: Ica26594a553de2e4555ffba56056141a56c3c6c5
---
M tests/aspects.py
M tests/http_tests.py
2 files changed, 55 insertions(+), 59 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/81/330281/1

diff --git a/tests/aspects.py b/tests/aspects.py
index 305c4be..813ba08 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -29,7 +29,6 @@
 UITestCase:
 Not integrated; direct subclass of unittest.TestCase.
 """
-import imp
 import inspect
 import itertools
 import os
@@ -60,6 +59,16 @@
 add_metaclass, execute_pwb, DrySite, DryRequest,
 WarningSourceSkipContextManager, AssertAPIErrorContextManager,
 )
+
+try:
+import pytest_httpbin
+optional_pytest_httpbin_cls_decorator = 
pytest_httpbin.use_class_based_httpbin
+except ImportError:
+pytest_httpbin = None
+
+def optional_pytest_httpbin_cls_decorator(f):
+"""Empty decorator in case pytest_httpbin is not installed."""
+return f
 
 OSWIN32 = (sys.platform == 'win32')
 
@@ -484,13 +493,10 @@
 if not hasattr(cls, 'sites'):
 return
 
-# Check is pytest is used and pytest_httpbin module is installed.
-if hasattr(sys, '_test_runner_pytest'):
-try:
-imp.find_module('pytest_httpbin')
-httpbin_used = True
-except ImportError:
-httpbin_used = False
+if issubclass(cls, HttpbinTestCase):
+# If test uses httpbin, then check is pytest test runner is used
+# and pytest_httpbin module is installed.
+httpbin_used = hasattr(sys, '_test_runner_pytest') and 
pytest_httpbin
 else:
 httpbin_used = False
 
@@ -1658,3 +1664,43 @@
 CapturingTestCase.process_assert,
 CapturingTestCase.patch_assert,
 ]
+
+
+@optional_pytest_httpbin_cls_decorator
+class HttpbinTestCase(TestCase):
+
+"""
+Custom test case class, which allows doing dry httpbin tests using 
pytest-httpbin.
+
+Test cases, which use httpbin, need to inherit this class.
+"""
+
+sites = {
+'httpbin': {
+'hostname': 'httpbin.org',
+},
+}
+
+def get_httpbin_url(self, path=''):
+"""
+Return url of httpbin.
+
+If pytest is used, returns url of local httpbin server.
+Otherwise, returns: http://httpbin.org
+"""
+if hasattr(self, 'httpbin'):
+return self.httpbin.url + path
+else:
+return 'http://httpbin.org' + path
+
+def get_httpbin_hostname(self):
+"""
+Return httpbin hostname.
+
+If pytest is used, returns hostname of local httpbin server.
+Otherwise, returns: httpbin.org
+"""
+if hasattr(self, 'httpbin'):
+return '{0}:{1}'.format(self.httpbin.host, self.httpbin.port)
+else:
+return 'httpbin.org'
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 72db94c..f41f930 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -25,57 +25,7 @@
 )
 
 from tests import join_images_path
-from tests.aspects import unittest, TestCase, DeprecationTestCase, 
require_modules
-
-try:
-import pytest_httpbin
-optional_pytest_httpbin_cls_decorator = 
pytest_httpbin.use_class_based_httpbin
-except ImportError:
-pytest_httpbin = None
-
-def optional_pytest_httpbin_cls_decorator(f):
-"""Empty decorator in case pytest_httpbin is not installed."""
-return f
-
-
-@optional_pytest_httpbin_cls_decorator
-class HttpbinTestCase(TestCase):
-
-"""
-Custom test case class, which allows doing dry httpbin tests using 
pytest-httpbin.
-
-Test cases, which use httpbin, need to inherit this class.
-"""
-
-sites = {
-'httpbin': {
-'hostname': 'httpbin.org',
-},
-}
-
-def get_httpbin_url(self, path=''):
-"""
-Return url of httpbin.
-
-If pytest is used, returns url of local httpbin server.
-Otherwise, returns: http://httpbin.org
-"""
-if hasattr(self, 'httpbin'):
-return self.httpbin.url + path
-else:
-return 'http://httpbin.org' + path
-
-def get_httpbin_hostname(self):
-"""
-Return httpbin hostname.
-
-If pytest is used, returns hostname of local httpbin server.
-Otherwise, returns: httpbin.org
-"""
-if hasattr(self, 'httpbin'):
-return '{0}:{1}'.format(self.httpbin.host, self.httpbin.port)
-else: