Skip to content

Commit

Permalink
Merge 9c1b2fe into sapling-pr-archive-shish
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Mar 27, 2024
2 parents 628af4d + 9c1b2fe commit 7505f83
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
# Ensure that all flavours are run to completion even if an other flavor failed
fail-fast: false

Expand Down
21 changes: 7 additions & 14 deletions tests/lib_testslide.py
Expand Up @@ -42,9 +42,7 @@ def assert_passes(self, *args, **kwargs):
def assert_fails(self, *args, **kwargs):
with self.assertRaisesRegex(
testslide.lib.TypeCheckError,
"Call to "
+ self.callable_template.__name__
+ " has incompatible argument types",
f"Call to {self.callable_template.__name__} has incompatible argument types",
):
testslide.lib._validate_callable_arg_types(
self.skip_first_arg, self.callable_template, args, kwargs
Expand Down Expand Up @@ -208,15 +206,15 @@ def callable_template(self):
return sample_module.test_union

@context.example
def passes_with_StritMock_without_template(self):
def passes_with_StrictMock_without_template(self):
self.assert_passes({"StrictMock": StrictMock()})

@context.example("it works with unittest.mock.Mock without spec")
def passes_with_unittest_mock_Mock_without_spec(self):
self.assert_passes({"Mock": unittest.mock.Mock()})

@context.example
def passes_with_StritMock_with_valid_template(self):
def passes_with_StrictMock_with_valid_template(self):
self.assert_passes(
{"StrictMock(template=str)": StrictMock(template=str)}
)
Expand All @@ -226,7 +224,7 @@ def passes_with_unittest_mock_Mock_with_valid_spec(self):
self.assert_passes({"Mock(spec=str)": unittest.mock.Mock(spec=str)})

@context.example
def fails_with_StritMock_with_invalid_template(self):
def fails_with_StrictMock_with_invalid_template(self):
self.assert_fails(
{"StrictMock(template=dict)": StrictMock(template=dict)}
)
Expand All @@ -242,7 +240,7 @@ def callable_template(self):
return sample_module.test_tuple

@context.example
def passes_with_StritMock_without_template(self):
def passes_with_StrictMock_without_template(self):
self.assert_passes(
{
"StrictMock": (
Expand All @@ -264,7 +262,7 @@ def passes_with_unittest_mock_Mock_without_spec(self):
)

@context.example
def passes_with_StritMock_with_valid_template(self):
def passes_with_StrictMock_with_valid_template(self):
self.assert_passes(
{
"StrictMock(template=int)": (
Expand All @@ -286,7 +284,7 @@ def passes_with_unittest_mock_Mock_with_valid_spec(self):
)

@context.example
def fails_with_StritMock_with_invalid_template(self):
def fails_with_StrictMock_with_invalid_template(self):
self.assert_fails(
{
"StrictMock(template=dict)": (
Expand Down Expand Up @@ -366,11 +364,6 @@ def with_typevar_return() -> Type[TypeVar("T")]: # type: ignore[empty-body]
@context.example
def fails_for_wrong_type(self):
self.assert_fails(42)
# assert_regex = r"(?s)type of return must be .+; got .+ instead: .+Defined"
# with self.assertRaisesRegex(TypeError, assert_regex):
# testslide.lib._validate_return_type(
# self.callable_template, 42, self.caller_frame_info
# )

@context.example
def fails_for_mock_with_wrong_template(self):
Expand Down
17 changes: 10 additions & 7 deletions tests/mock_constructor_testslide.py
Expand Up @@ -205,13 +205,16 @@ def can_access_class_attributes(self):
self.assertEqual(original_target_class.CLASS_ATTR, "CLASS_ATTR")

@context.example
def can_call_class_methods(self):
for name in [
"regular_class_method",
"p2_super_class_method",
"p3_super_class_method",
]:
self.assertEqual(getattr(original_target_class, name)(), name)
def can_call_regular_class_method(self):
self.assertEqual(original_target_class.regular_class_method(), "regular_class_method")

@context.example
def can_call_p2_super_class_method(self):
self.assertEqual(original_target_class.p2_super_class_method(), "p2_super_class_method")

@context.example
def can_call_p3_super_class_method(self):
self.assertEqual(original_target_class.p3_super_class_method(), "p3_super_class_method")

@context.example
def can_call_static_methods(self):
Expand Down
13 changes: 7 additions & 6 deletions testslide/lib.py
Expand Up @@ -157,8 +157,10 @@ def _validate_callable_signature(
kwargs: Dict[str, Any],
) -> bool:
# python stdlib tests have to exempt some builtins for signature validation tests
# they use a giant alloy/deny list, which is impractical here so just ignore
# they use a giant allow/deny list, which is impractical here so just ignore
# all builtins.

# Ugly hack to make mock objects not be subclass of Mock
if _is_a_builtin(callable_template):
return False
if skip_first_arg and not inspect.ismethod(callable_template):
Expand Down Expand Up @@ -257,7 +259,6 @@ def _validate_callable_arg_types(
expected_type = argspec.annotations.get(argname)
if not expected_type:
continue

_validate_argument_type(expected_type, argname, args[idx])
except TypeCheckError as type_error:
type_errors.append(f"{repr(argname)}: {type_error}")
Expand All @@ -273,11 +274,11 @@ def _validate_callable_arg_types(
type_errors.append(f"{repr(argname)}: {type_error}")

if type_errors:
separator = "\n "
raise TypeCheckError(
"Call to "
+ callable_template.__name__
+ " has incompatible argument types:\n "
+ "\n ".join(type_errors)
f"Call to {callable_template.__name__} "
"has incompatible argument types:\n "
f"{separator.join(type_errors)}"
)


Expand Down

0 comments on commit 7505f83

Please sign in to comment.