diff --git a/tests/accept_any_arg_unittest.py b/tests/accept_any_arg_unittest.py index 9b8e8ca..c6bb412 100644 --- a/tests/accept_any_arg_unittest.py +++ b/tests/accept_any_arg_unittest.py @@ -25,9 +25,7 @@ def test_for_partial_call_accepts_all_other_args_and_kwargs(self): self.mock_callable( sample_module, "test_function", - ).for_partial_call( - "firstarg", kwarg1="a" - ).to_return_value(["blah"]) + ).for_partial_call("firstarg", kwarg1="a").to_return_value(["blah"]) sample_module.test_function("firstarg", "xx", kwarg1="a", kwarg2="x") def test_for_partial_call_fails_if_no_required_args_are_present(self): @@ -35,9 +33,7 @@ def test_for_partial_call_fails_if_no_required_args_are_present(self): self.mock_callable( sample_module, "test_function", - ).for_partial_call( - "firstarg", kwarg1="a" - ).to_return_value(["blah"]) + ).for_partial_call("firstarg", kwarg1="a").to_return_value(["blah"]) sample_module.test_function( "differentarg", "alsodifferent", kwarg1="a", kwarg2="x" ) @@ -47,16 +43,12 @@ def test_for_partial_call_fails_if_no_required_kwargs_are_present(self): self.mock_callable( sample_module, "test_function", - ).for_partial_call( - "firstarg", kwarg1="x" - ).to_return_value(["blah"]) + ).for_partial_call("firstarg", kwarg1="x").to_return_value(["blah"]) sample_module.test_function("firstarg", "secondarg", kwarg1="a", kwarg2="x") def test_matchers_work_with_for_partial_call(self): self.mock_callable( sample_module, "test_function", - ).for_partial_call( - matchers.Any(), "secondarg" - ).to_return_value(["blah"]) + ).for_partial_call(matchers.Any(), "secondarg").to_return_value(["blah"]) sample_module.test_function("asdasdeas", "secondarg", kwarg1="a", kwarg2="x") diff --git a/tests/cli_unittest.py b/tests/cli_unittest.py index 3f2cfc4..0c64d94 100644 --- a/tests/cli_unittest.py +++ b/tests/cli_unittest.py @@ -460,8 +460,7 @@ def test_focus(self): self.argv.append("--focus") self.run_testslide( expected_stdout_startswith=( - "top context\n" - " *focused example: PASS\n" + "top context\n" " *focused example: PASS\n" # TODO add remaining bits of the output (using regexes) ) ) diff --git a/tests/matchers_unittest.py b/tests/matchers_unittest.py index a814a9e..92b6fdf 100644 --- a/tests/matchers_unittest.py +++ b/tests/matchers_unittest.py @@ -457,7 +457,11 @@ def testBitwiseInverse(self): def testCannotChainMoreThanTwo(self): with self.assertRaises(testslide.matchers.AlreadyChainedException): - testslide.matchers.Any() | testslide.matchers.AnyStr() | testslide.matchers.AnyInt() + ( + testslide.matchers.Any() + | testslide.matchers.AnyStr() + | testslide.matchers.AnyInt() + ) with self.assertRaises(testslide.matchers.AlreadyChainedException): ( testslide.matchers.Any() diff --git a/tests/mock_async_callable_testslide.py b/tests/mock_async_callable_testslide.py index c3e8586..88c8d39 100644 --- a/tests/mock_async_callable_testslide.py +++ b/tests/mock_async_callable_testslide.py @@ -62,8 +62,7 @@ def assertRaisesWithMessage(self, exception, msg): self.assertEqual( ex_msg, msg, - "Expected exception {}.{} message " - "to be\n{}\nbut got\n{}.".format( + "Expected exception {}.{} message " "to be\n{}\nbut got\n{}.".format( exception.__module__, exception.__name__, repr(msg), repr(ex_msg) ), ) diff --git a/tests/mock_callable_testslide.py b/tests/mock_callable_testslide.py index faf1d86..fec1373 100644 --- a/tests/mock_callable_testslide.py +++ b/tests/mock_callable_testslide.py @@ -64,8 +64,7 @@ def assertRaisesWithMessage(self, exception, msg): self.assertEqual( ex_msg, msg, - "Expected exception {}.{} message " - "to be\n{}\nbut got\n{}.".format( + "Expected exception {}.{} message " "to be\n{}\nbut got\n{}.".format( exception.__module__, exception.__name__, repr(msg), repr(ex_msg) ), ) diff --git a/tests/mock_constructor_testslide.py b/tests/mock_constructor_testslide.py index 23da8b7..46833c9 100644 --- a/tests/mock_constructor_testslide.py +++ b/tests/mock_constructor_testslide.py @@ -110,8 +110,7 @@ def assertRaisesWithMessageInException(self, exception, msg): self.assertIn( msg, ex_msg, - "Expected exception {}.{} message " - "to be\n{}\nbut got\n{}.".format( + "Expected exception {}.{} message " "to be\n{}\nbut got\n{}.".format( exception.__module__, exception.__name__, repr(msg), repr(ex_msg) ), ) diff --git a/tests/strict_mock_testslide.py b/tests/strict_mock_testslide.py index 716dcef..aaf2958 100644 --- a/tests/strict_mock_testslide.py +++ b/tests/strict_mock_testslide.py @@ -159,8 +159,7 @@ def assertRaisesWithMessage(self, exception, msg): self.assertEqual( ex_msg, msg, - "Expected exception {}.{} message " - "to be\n{}\nbut got\n{}.".format( + "Expected exception {}.{} message " "to be\n{}\nbut got\n{}.".format( exception.__module__, exception.__name__, repr(msg), repr(ex_msg) ), ) @@ -901,9 +900,11 @@ def mock(msg): setattr(self.strict_mock, self.method_name, mock) with self.assertRaises(NonAwaitableReturn): - await getattr( - self.strict_mock, self.method_name - )("hello"), + ( + await getattr( + self.strict_mock, self.method_name + )("hello"), + ) @context.example async def fails_on_wrong_type_call(self): diff --git a/testslide/bdd/dsl.py b/testslide/bdd/dsl.py index 12d0e5a..e66eedf 100644 --- a/testslide/bdd/dsl.py +++ b/testslide/bdd/dsl.py @@ -200,7 +200,10 @@ def nest_context(self, name: str, *args: Any, **kwargs: Any) -> None: if name not in self.current_context.all_shared_contexts: # type:ignore raise TypeError('Shared context "{}" does not exist'.format(name)) self._create_context( - name, self.current_context.all_shared_contexts[name], *args, **kwargs # type: ignore + name, + self.current_context.all_shared_contexts[name], + *args, + **kwargs, # type: ignore ) # Helper function diff --git a/testslide/bdd/lib.py b/testslide/bdd/lib.py index 554e226..30d3484 100644 --- a/testslide/bdd/lib.py +++ b/testslide/bdd/lib.py @@ -453,7 +453,16 @@ def addUnexpectedSuccess(self, test: "TestCase") -> None: # type: ignore super(_TestSlideTestResult, self).addUnexpectedSuccess(test) self._add_exception((type(UnexpectedSuccess), UnexpectedSuccess(), None)) # type: ignore - def addSubTest(self, test: "TestCase", subtest: "TestCase", err: Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[types.TracebackType]]) -> None: # type: ignore + def addSubTest( + self, + test: "TestCase", + subtest: "TestCase", + err: Tuple[ + Optional[Type[BaseException]], + Optional[BaseException], + Optional[types.TracebackType], + ], + ) -> None: # type: ignore """Called at the end of a subtest. 'err' is None if the subtest ended successfully, otherwise it's a tuple of values as returned by sys.exc_info(). @@ -816,7 +825,8 @@ def exec_body(ns: Dict[str, Callable]) -> None: # This suite will only contain TestSlide's example test. test_suite = unittest.TestLoader().loadTestsFromName( - "test_test_slide", test_slide_test_case # type: ignore + "test_test_slide", + test_slide_test_case, # type: ignore ) setattr(self, attr_name, list(test_suite)[0]) result = _TestSlideTestResult() diff --git a/testslide/core/lib.py b/testslide/core/lib.py index 179811c..11fed7b 100644 --- a/testslide/core/lib.py +++ b/testslide/core/lib.py @@ -98,7 +98,7 @@ def _extract_NonCallableMock_template(mock_obj: Mock) -> Optional[Any]: def _extract_mock_template( - mock: Union[Mock, "StrictMock"] + mock: Union[Mock, "StrictMock"], ) -> Optional[Union[Type[str], Type[dict], Type[int]]]: template = None for mock_class, extract_mock_template in MOCK_TEMPLATE_EXTRACTORS.items(): diff --git a/testslide/core/mock_callable.py b/testslide/core/mock_callable.py index f56d8fe..950ee81 100644 --- a/testslide/core/mock_callable.py +++ b/testslide/core/mock_callable.py @@ -107,7 +107,12 @@ def unpatch_all_callable_mocks() -> None: This method must be called after every test unconditionally to remove all active mock_callable() patches. """ - global register_assertion, _default_register_assertion, _call_order_assertion_registered, _received_ordered_calls, _expected_ordered_calls + global \ + register_assertion, \ + _default_register_assertion, \ + _call_order_assertion_registered, \ + _received_ordered_calls, \ + _expected_ordered_calls register_assertion = _default_register_assertion _call_order_assertion_registered = False @@ -162,7 +167,9 @@ def _is_coroutine(obj: Any) -> bool: 3, 11, ]: - return inspect.iscoroutine(obj) or isinstance(obj, asyncio.coroutines.CoroWrapper) # type: ignore + return inspect.iscoroutine(obj) or isinstance( + obj, asyncio.coroutines.CoroWrapper + ) # type: ignore else: return inspect.iscoroutine(obj) @@ -371,7 +378,10 @@ def assertion() -> None: register_assertion(assertion) def add_call_order_assertion(self) -> None: - global _call_order_assertion_registered, _received_ordered_calls, _expected_ordered_calls + global \ + _call_order_assertion_registered, \ + _received_ordered_calls, \ + _expected_ordered_calls if not _call_order_assertion_registered: @@ -553,7 +563,6 @@ def __init__( self.new_implementation = new_implementation async def run(self, *args: Any, **kwargs: Any) -> Optional[Any]: - await super().run(*args, **kwargs) coro = self.new_implementation(*args, **kwargs) if not _is_coroutine(coro): @@ -1001,13 +1010,19 @@ def to_raise( if isinstance(ex, BaseException): self._add_runner( _RaiseRunner( - self._original_target, self._method, self._original_callable, ex # type: ignore + self._original_target, + self._method, + self._original_callable, + ex, # type: ignore ) ) elif isinstance(ex(), BaseException): self._add_runner( _RaiseRunner( - self._original_target, self._method, self._original_callable, ex() # type: ignore + self._original_target, + self._method, + self._original_callable, + ex(), # type: ignore ) ) else: @@ -1227,7 +1242,10 @@ def with_implementation(self, func: Callable) -> "_MockAsyncCallableDSL": raise ValueError("{} must be callable.".format(func)) self._add_runner( _AsyncImplementationRunner( - self._original_target, self._method, self._original_callable, func # type: ignore + self._original_target, + self._method, + self._original_callable, + func, # type: ignore ) ) return self diff --git a/testslide/core/mock_constructor.py b/testslide/core/mock_constructor.py index 108b50a..cebd472 100644 --- a/testslide/core/mock_constructor.py +++ b/testslide/core/mock_constructor.py @@ -367,7 +367,9 @@ def mock_constructor( prev_frame = caller_frame.f_back if prev_frame: caller_frame_info = inspect.getframeinfo(prev_frame, context=0) - callable_mock = _CallableMock(original_class, "__new__", caller_frame_info) # type: ignore[assignment] + callable_mock = _CallableMock( + original_class, "__new__", caller_frame_info + ) # type: ignore[assignment] mocked_class = _patch_and_return_mocked_class( target, class_name, diff --git a/testslide/core/strict_mock.py b/testslide/core/strict_mock.py index 6af0ae7..32e2cf1 100644 --- a/testslide/core/strict_mock.py +++ b/testslide/core/strict_mock.py @@ -742,18 +742,21 @@ async def awaitable_return_validation_wrapper( raise NonAwaitableReturn(self, name) return_value = await result_awaitable - if not lib._is_wrapped_for_signature_and_type_validation( - # The original value was already wrapped for type - # validation. Skipping additional validation to - # allow, for example, mock_callable to disable - # validation for a very specific mock call rather - # for the whole StrictMock instance - value - ) and not isinstance( - # If the return value is a _BaseRunner then type - # validation, if needed, has already been performed - return_value, - mock_callable._BaseRunner, + if ( + not lib._is_wrapped_for_signature_and_type_validation( + # The original value was already wrapped for type + # validation. Skipping additional validation to + # allow, for example, mock_callable to disable + # validation for a very specific mock call rather + # for the whole StrictMock instance + value + ) + and not isinstance( + # If the return value is a _BaseRunner then type + # validation, if needed, has already been performed + return_value, + mock_callable._BaseRunner, + ) ): lib._validate_return_type( template_value, @@ -769,18 +772,21 @@ def return_validation_wrapper(*args, **kwargs): return_value = signature_validation_wrapper( *args, **kwargs ) - if not lib._is_wrapped_for_signature_and_type_validation( - # The original value was already wrapped for type - # validation. Skipping additional validation to - # allow, for example, mock_callable to disable - # validation for a very specific mock call rather - # for the whole StrictMock instance - value - ) and not isinstance( - # If the return value is a _BaseRunner then type - # validation, if needed, has already been performed - return_value, - mock_callable._BaseRunner, + if ( + not lib._is_wrapped_for_signature_and_type_validation( + # The original value was already wrapped for type + # validation. Skipping additional validation to + # allow, for example, mock_callable to disable + # validation for a very specific mock call rather + # for the whole StrictMock instance + value + ) + and not isinstance( + # If the return value is a _BaseRunner then type + # validation, if needed, has already been performed + return_value, + mock_callable._BaseRunner, + ) ): lib._validate_return_type( template_value, diff --git a/testslide/executor/cli.py b/testslide/executor/cli.py index 7b20e77..d498d57 100644 --- a/testslide/executor/cli.py +++ b/testslide/executor/cli.py @@ -154,7 +154,9 @@ def example_code(self: Any) -> None: return context_code - testslide.bdd.dsl.context("{}.{}".format(test_case.__module__, test_case.__name__))( # type: ignore + testslide.bdd.dsl.context( + "{}.{}".format(test_case.__module__, test_case.__name__) + )( # type: ignore get_context_code(test_case) ) diff --git a/testslide/executor/runner.py b/testslide/executor/runner.py index 88bb912..3781b9b 100644 --- a/testslide/executor/runner.py +++ b/testslide/executor/runner.py @@ -365,11 +365,7 @@ def _get_ascii_logo_lines(self) -> List[str]: {self._red_bright_attr("| |")}{self._yellow_bright_attr("| |")}{self._green_bright_attr("|")} {self._bright_attr(f"| {backslash}|/")} {self._green_bright_attr("|")} {self._red_bright_attr(f"|.{quote}")}{self._yellow_bright_attr("| |")}{self._green_bright_attr("|")} {self._bright_attr(f"--{quote}{quote}")} {self._bright_attr("'")}{self._green_bright_attr("__|")} {self._yellow_bright_attr(f"--{quote}")} {self._green_bright_attr(f"|__---{quote}{quote}{quote}")} -""".split( - "\n" - )[ - 1:8 - ] +""".split("\n")[1:8] def _get_summary_lines( self, total: int, success: int, fail: int, skip: int, not_executed_examples: int @@ -440,7 +436,9 @@ def finish(self, not_executed_examples: List[Example]) -> None: result = cast(Dict[str, Union[Example, BaseException]], result) print("") self.print_failed_example( # type: ignore - number + 1, result["example"], result["exception"] # type: ignore + number + 1, + result["example"], + result["exception"], # type: ignore ) summary_lines = self._get_summary_lines( @@ -533,7 +531,9 @@ def finish(self, not_executed_examples: List[Example]) -> None: result = cast(Dict[str, Union[Example, BaseException]], result) print("") self.print_failed_example( - number + 1, result["example"], result["exception"] # type: ignore + number + 1, + result["example"], + result["exception"], # type: ignore ) print("")