Skip to content

Commit

Permalink
Merge pull request #736 from arcivanov/issue_735
Browse files Browse the repository at this point in the history
Fix remote getting too excited and classifying classes as callable methods
  • Loading branch information
arcivanov committed Jul 18, 2020
2 parents b78fe53 + 68fd25d commit b9a7cc1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
Expand Up @@ -41,7 +41,7 @@

@init
def init_coverage_properties(project):
project.plugin_depends_on("coverage", "~=5.0")
project.plugin_depends_on("coverage", "~=5.2")

# These settings are for aggregate coverage
project.set_property_if_unset("coverage_threshold_warn", 70)
Expand Down
6 changes: 5 additions & 1 deletion src/main/python/pybuilder/plugins/python/coveralls_plugin.py
Expand Up @@ -23,6 +23,7 @@
from pybuilder.errors import BuildFailedException
from pybuilder.execution import ExecutionManager
from pybuilder.plugins.python._coverage_util import patch_coverage
from pybuilder.python_utils import PY2

use_plugin("python.core")
use_plugin("analysis")
Expand All @@ -31,7 +32,10 @@

@init(environments="ci")
def init_coveralls_properties(project):
project.plugin_depends_on("coveralls", "~=1.11")
if PY2:
project.plugin_depends_on("coveralls", "<2.0.0")
else:
project.plugin_depends_on("coveralls", "~=2.1")

project.set_property_if_unset("coveralls_dry_run", False)
project.set_property_if_unset("coveralls_report", False)
Expand Down
4 changes: 3 additions & 1 deletion src/main/python/pybuilder/plugins/python/unittest_plugin.py
Expand Up @@ -37,9 +37,11 @@

@init
def init_test_source_directory(project):
project.plugin_depends_on("unittest-xml-reporting", "~=2.5.2")
if PY2:
project.plugin_depends_on("mock")
project.plugin_depends_on("unittest-xml-reporting", "~=2.5.2")
else:
project.plugin_depends_on("unittest-xml-reporting", "~=3.0.2")

project.set_property_if_unset("dir_source_unittest_python", "src/unittest/python")
project.set_property_if_unset("unittest_breaks_build", True)
Expand Down
29 changes: 28 additions & 1 deletion src/main/python/pybuilder/remote/__init__.py
Expand Up @@ -23,6 +23,24 @@

import sys # noqa: E402
from textwrap import dedent # noqa: E402

from types import (MethodType, # noqa: E402
FunctionType,
BuiltinFunctionType,
)

try:
from types import (WrapperDescriptorType, # noqa: E402
MethodWrapperType,
MethodDescriptorType,
ClassMethodDescriptorType,
)
except ImportError:
WrapperDescriptorType = type(object.__init__)
MethodWrapperType = type(object().__str__)
MethodDescriptorType = type(str.join)
ClassMethodDescriptorType = type(dict.__dict__['fromkeys'])

from os.path import normcase as nc, sep # noqa: E402
from io import BytesIO, StringIO # noqa: E402
from pickle import PickleError, Unpickler, UnpicklingError, HIGHEST_PROTOCOL # noqa: E402
Expand All @@ -37,6 +55,15 @@
PICKLE_PROTOCOL_MIN = 2
PICKLE_PROTOCOL_MAX = HIGHEST_PROTOCOL

CALLABLE_TYPES = (MethodType,
FunctionType,
BuiltinFunctionType,
MethodWrapperType,
ClassMethodDescriptorType,
WrapperDescriptorType,
MethodDescriptorType,
)

if PY2:
ConnectionError = EnvironmentError
_compat_pickle = None
Expand Down Expand Up @@ -368,7 +395,7 @@ def proxy_members(obj, public=True, protected=True, add_callable=True, add_str=T
is_callable and add_callable or
is_str and add_str):
member = getattr(obj, name)
if callable(member):
if isinstance(member, CALLABLE_TYPES):
methods.append(name)
else:
fields.append(name)
Expand Down
13 changes: 13 additions & 0 deletions src/unittest/python/plugins/python/unittest_plugin_tests.py
Expand Up @@ -26,6 +26,7 @@
_create_runner,
_get_make_result_method_name,
report_to_ci_server)
from pybuilder.python_utils import PY2
from pybuilder.utils import np
from test_utils import Mock, patch

Expand Down Expand Up @@ -212,3 +213,15 @@ def _makeResult(self):
pass

self.assertEqual(_get_make_result_method_name((TextTestRunner, _makeResult)), "_makeResult")


class UnittestRunnerCompatibilityTest(TestCase):
def test_sub_tests_issue_735(self):
"""
Test that numbers between 0 and 5 are all between 0 and 5.
"""
if not PY2:
for i in range(0, 6):
with self.subTest(i=i):
self.assertLess(i, 6)
self.assertGreaterEqual(i, 0)

0 comments on commit b9a7cc1

Please sign in to comment.