From d8b0c580a1cca612a7d1e6e10abbf1fc423bb629 Mon Sep 17 00:00:00 2001 From: Balint Csergo Date: Thu, 16 Mar 2023 10:57:29 -0700 Subject: [PATCH] release TestSlide 2.7.1 with various tiny changes (#347) Summary: * pin typeguard to < 3.0 for now * Reformat with new black * Pygments upgrade broke our fragile CLI unittest, fix CI - [] Added tests, if you've added code that should be tested N/A - [ ] Updated the documentation, if you've changed APIs N/A - [X] Ensured the test suite passes - [X] Made sure your code lints - [X] Completed the Contributor License Agreement ("CLA") Pull Request resolved: https://github.com/facebook/TestSlide/pull/347 Reviewed By: pmazzini Differential Revision: D44133897 Pulled By: deathowl fbshipit-source-id: a01a3c35ebd8132f942b72be4cfb1ccef5b85483 --- pytest-testslide/testslide-version | 2 +- tests/accept_any_arg_unittest.py | 20 ++++++++++++++++---- tests/cli_unittest.py | 12 ++++++------ tests/dsl_unittest.py | 11 ----------- tests/mock_callable_testslide.py | 15 --------------- tests/mock_constructor_testslide.py | 1 - tests/strict_mock_testslide.py | 3 --- testslide/__init__.py | 1 - testslide/cli.py | 3 --- testslide/lib.py | 2 -- testslide/mock_callable.py | 3 --- testslide/version | 2 +- util/testslide-snippets/package.json | 2 +- 13 files changed, 25 insertions(+), 52 deletions(-) diff --git a/pytest-testslide/testslide-version b/pytest-testslide/testslide-version index 24ba9a3..860487c 100644 --- a/pytest-testslide/testslide-version +++ b/pytest-testslide/testslide-version @@ -1 +1 @@ -2.7.0 +2.7.1 diff --git a/tests/accept_any_arg_unittest.py b/tests/accept_any_arg_unittest.py index 487e8b4..41ecb16 100644 --- a/tests/accept_any_arg_unittest.py +++ b/tests/accept_any_arg_unittest.py @@ -22,14 +22,20 @@ def test_for_partial_call_accepts_all_other_kwargs(self): sample_module.test_function("firstarg", "secondarg", kwarg1="a", kwarg2="x") def test_for_partial_call_accepts_all_other_args_and_kwargs(self): - self.mock_callable(sample_module, "test_function",).for_partial_call( + self.mock_callable( + sample_module, + "test_function", + ).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): with self.assertRaises(mock_callable.UnexpectedCallArguments): - self.mock_callable(sample_module, "test_function",).for_partial_call( + self.mock_callable( + sample_module, + "test_function", + ).for_partial_call( "firstarg", kwarg1="a" ).to_return_value(["blah"]) sample_module.test_function( @@ -38,13 +44,19 @@ def test_for_partial_call_fails_if_no_required_args_are_present(self): def test_for_partial_call_fails_if_no_required_kwargs_are_present(self): with self.assertRaises(mock_callable.UnexpectedCallArguments): - self.mock_callable(sample_module, "test_function",).for_partial_call( + self.mock_callable( + sample_module, + "test_function", + ).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( + self.mock_callable( + sample_module, + "test_function", + ).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 e3a9851..f226845 100644 --- a/tests/cli_unittest.py +++ b/tests/cli_unittest.py @@ -284,14 +284,14 @@ def test_prints_exceptions_with_cause(self): tty_stdout=True, expected_return_code=1, expected_in_stdout=( - ' File \x1b[36m"tests/sample_tests.py"\x1b[39;49;00m, line \x1b[94m76\x1b[39;49;00m, in test_failing\r\n' - ' \x1b[94mraise\x1b[39;49;00m \x1b[36mAssertionError\x1b[39;49;00m(\x1b[33m"\x1b[39;49;00m\x1b[33mThird\x1b[39;49;00m\x1b[33m"\x1b[39;49;00m) \x1b[94mfrom\x1b[39;49;00m \x1b[04m\x1b[36mcause\x1b[39;49;00m\r\n' + ' File \x1b[36m"tests/sample_tests.py"\x1b[39;49;00m, line \x1b[94m76\x1b[39;49;00m, in test_failing\x1b[37m\x1b[39;49;00m\r\n' + ' \x1b[37m \x1b[39;49;00m\x1b[94mraise\x1b[39;49;00m \x1b[36mAssertionError\x1b[39;49;00m(\x1b[33m"\x1b[39;49;00m\x1b[33mThird\x1b[39;49;00m\x1b[33m"\x1b[39;49;00m) \x1b[94mfrom\x1b[39;49;00m \x1b[04m\x1b[36mcause\x1b[39;49;00m\x1b[37m\x1b[39;49;00m\r\n' "\x1b[0m\x1b[31m Caused by \x1b[0m\x1b[0m\x1b[31mAssertionError: Second\x1b[0m\r\n" - ' File \x1b[36m"tests/sample_tests.py"\x1b[39;49;00m, line \x1b[94m74\x1b[39;49;00m, in test_failing\r\n' - ' \x1b[94mraise\x1b[39;49;00m \x1b[36mAssertionError\x1b[39;49;00m(\x1b[33m"\x1b[39;49;00m\x1b[33mSecond\x1b[39;49;00m\x1b[33m"\x1b[39;49;00m) \x1b[94mfrom\x1b[39;49;00m \x1b[04m\x1b[36mcause\x1b[39;49;00m\r\n' + ' File \x1b[36m"tests/sample_tests.py"\x1b[39;49;00m, line \x1b[94m74\x1b[39;49;00m, in test_failing\x1b[37m\x1b[39;49;00m\r\n' + ' \x1b[37m \x1b[39;49;00m\x1b[94mraise\x1b[39;49;00m \x1b[36mAssertionError\x1b[39;49;00m(\x1b[33m"\x1b[39;49;00m\x1b[33mSecond\x1b[39;49;00m\x1b[33m"\x1b[39;49;00m) \x1b[94mfrom\x1b[39;49;00m \x1b[04m\x1b[36mcause\x1b[39;49;00m\x1b[37m\x1b[39;49;00m\r\n' "\x1b[0m\x1b[31m Caused by \x1b[0m\x1b[0m\x1b[31mAssertionError: First\x1b[0m\r\n" - ' File \x1b[36m"tests/sample_tests.py"\x1b[39;49;00m, line \x1b[94m72\x1b[39;49;00m, in test_failing\r\n' - ' \x1b[94mraise\x1b[39;49;00m \x1b[36mAssertionError\x1b[39;49;00m(\x1b[33m"\x1b[39;49;00m\x1b[33mFirst\x1b[39;49;00m\x1b[33m"\x1b[39;49;00m)\r\n' + ' File \x1b[36m"tests/sample_tests.py"\x1b[39;49;00m, line \x1b[94m72\x1b[39;49;00m, in test_failing\x1b[37m\x1b[39;49;00m\r\n' + ' \x1b[37m \x1b[39;49;00m\x1b[94mraise\x1b[39;49;00m \x1b[36mAssertionError\x1b[39;49;00m(\x1b[33m"\x1b[39;49;00m\x1b[33mFirst\x1b[39;49;00m\x1b[33m"\x1b[39;49;00m)\x1b[37m\x1b[39;49;00m\r\n' ), ) diff --git a/tests/dsl_unittest.py b/tests/dsl_unittest.py index 4d21b82..2d1ccb0 100644 --- a/tests/dsl_unittest.py +++ b/tests/dsl_unittest.py @@ -150,7 +150,6 @@ def _print_context_hierarchy(self, contexts=None, indent=""): class TestDSLContext(TestDSLBase): - # Context creation def test_can_be_named_from_decorator(self): @@ -413,7 +412,6 @@ def not_focused(context): class TestDSLSharedContext(TestDSLBase): - # Shared contexts def test_shared_context_named_from_decorator(self): @@ -507,7 +505,6 @@ def test_merge_shared_context(self): def top(context): @context.shared_context def Shared_context(context, arg_passed=False): - assert arg_passed @context.example @@ -567,7 +564,6 @@ def test_nest_shared_context(self): def top(context): @context.shared_context def Shared_context(context, arg_passed=False): - assert arg_passed @context.example @@ -843,7 +839,6 @@ def test_memoize_attribute(self): @context def top(context): - value = 1 memoized = [] @@ -871,7 +866,6 @@ def test_memoize_attribute_as_lambda(self): @context def top(context): - value = 1 context.memoize("attribute_name", lambda self: value + 1) @@ -892,7 +886,6 @@ def test_memoize_attribute_with_kwargs(self): @context def top(context): - value = 1 context.memoize( @@ -954,7 +947,6 @@ def test_memoize_before_attribute(self): @context def top(context): - value = 1 memoized = [] @@ -981,7 +973,6 @@ def test_memoize_before_attribute_as_lambda(self): @context def top(context): - value = 1 memoized = [] @@ -1101,7 +1092,6 @@ def test_before_hook_as_lambda(self): @context def top(context): - context.before(lambda self: mock("first before")) context.before(lambda self: mock("second before")) @@ -1207,7 +1197,6 @@ def test_after_hook_as_lambda(self): @context def top(context): - context.after(lambda self: mock("first after")) context.after(lambda self: mock("second after")) diff --git a/tests/mock_callable_testslide.py b/tests/mock_callable_testslide.py index 419f4be..8343137 100644 --- a/tests/mock_callable_testslide.py +++ b/tests/mock_callable_testslide.py @@ -26,7 +26,6 @@ async def coro_fun(*args): @context("mock_callable()") def mock_callable_tests(context): - ## ## Attributes ## @@ -326,7 +325,6 @@ def setup_assertion(self): @context.sub_context def fails_when(context): - context.merge_context("assert failure") context.merge_context("not called") @@ -335,7 +333,6 @@ def fails_when(context): @context.sub_context def passes_when(context): - context.merge_context("called exactly times") @context.sub_context(".and_assert_called_at_least(times)") @@ -357,7 +354,6 @@ def setup_assertion(self): @context.sub_context def fails_when(context): - context.merge_context("assert failure") context.merge_context("not called") @@ -365,7 +361,6 @@ def fails_when(context): @context.sub_context def passes_when(context): - context.merge_context("called exactly times") context.merge_context("called more times") @@ -388,7 +383,6 @@ def setup_assertion(self): @context.sub_context def fails_when(context): - context.merge_context("assert failure") context.merge_context("not called") @@ -396,7 +390,6 @@ def fails_when(context): @context.sub_context def passes_when(context): - context.merge_context("called less times") context.merge_context("called exactly times") @@ -408,7 +401,6 @@ def setup_assertion(self): @context.sub_context def fails_when(context): - context.merge_context("assert failure") context.merge_context("not called") @@ -580,7 +572,6 @@ def it_raises(self): @context.sub_context(".to_yield_values(values_list)") def to_yield_values_values_list(context): - context.memoize( "values_list", lambda self: [["first"], ["second"], ["third"]] ) @@ -626,7 +617,6 @@ def it_raises_StopIteration(self): @context.sub_context(".to_raise(exception)") def to_raise_exception(context): - context.memoize("exception_class", lambda self: RuntimeError) context.memoize("times", lambda self: 3) @@ -665,7 +655,6 @@ def it_raises_an_instance_of_the_class(self): @context.sub_context def when_given_an_exception_instance(context): - context.memoize("exception_message", lambda self: "test exception") context.memoize( "exception", @@ -750,7 +739,6 @@ def _wrapper_func(original_function, *args, **kwargs): return _wrapper_func if has_original_callable: - context.memoize("times", lambda self: 3) @context.before @@ -792,9 +780,7 @@ def it_fails_to_mock(self): @context.sub_context(".to_call_original()") def to_call_original(context): - if has_original_callable: - context.memoize("times", lambda self: 3) @context.before @@ -1509,7 +1495,6 @@ def _original_target(self): @context.sub_context def that_is_dynamically_defined_by_the_instance(context): - context.memoize("callable_arg", lambda self: "dynamic_instance_method") @context.memoize_before diff --git a/tests/mock_constructor_testslide.py b/tests/mock_constructor_testslide.py index c353ab0..0ab1f97 100644 --- a/tests/mock_constructor_testslide.py +++ b/tests/mock_constructor_testslide.py @@ -94,7 +94,6 @@ def function_at_module(): @context("mock_constructor()") def mock_constructor(context): - context.memoize("target_module", lambda self: sys.modules[__name__]) context.memoize_before("target_class_name", lambda self: target_class_name) diff --git a/tests/strict_mock_testslide.py b/tests/strict_mock_testslide.py index 084a9de..763836f 100644 --- a/tests/strict_mock_testslide.py +++ b/tests/strict_mock_testslide.py @@ -64,7 +64,6 @@ async def __aexit__(self, exc_type, exc, tb): class Template(TemplateParent): - __slots__ = ["slot_attribute"] non_callable: str = "original value" @@ -553,7 +552,6 @@ def works_with_wraps(self): @context.shared_context def common_examples(context, type_validation): - if type_validation: @context.example @@ -679,7 +677,6 @@ def isinstance_is_true_for_template(self): @context.sub_context def method_mocking(context): - context.merge_context("can access attributes") @context.after diff --git a/testslide/__init__.py b/testslide/__init__.py index 45ab13f..2793a19 100644 --- a/testslide/__init__.py +++ b/testslide/__init__.py @@ -912,7 +912,6 @@ def add_memoized_attribute( self.context_data_memoizable_attributes[name] = memoizable_code if before: - if inspect.iscoroutinefunction(memoizable_code): async def async_materialize_attribute( diff --git a/testslide/cli.py b/testslide/cli.py index 89247c1..2bb7278 100644 --- a/testslide/cli.py +++ b/testslide/cli.py @@ -78,7 +78,6 @@ def _load_unittest_test_cases(import_module_names: List[str]) -> None: _unittest_testcase_loaded = True for test_case in _get_all_test_cases(import_module_names): - test_method_names = [ test_method_name for test_method_name in dir(test_case) @@ -100,7 +99,6 @@ def get_context_code( test_case: unittest.TestCase, ) -> Callable[[testslide.dsl._DSLContext], None]: def context_code(context: testslide.dsl._DSLContext) -> None: - for test_method_name in test_method_names: @contextmanager @@ -172,7 +170,6 @@ class _Config: class Cli: - FORMAT_NAME_TO_FORMATTER_CLASS = { "p": ProgressFormatter, "progress": ProgressFormatter, diff --git a/testslide/lib.py b/testslide/lib.py index de194c1..2370879 100644 --- a/testslide/lib.py +++ b/testslide/lib.py @@ -202,7 +202,6 @@ def wrapped_check_type( locals: Optional[Dict[str, Any]] = None, **kwargs: Any, ) -> None: - if _is_a_mock(inner_value): inner_type = _extract_mock_template(inner_value) if inner_type is None: @@ -283,7 +282,6 @@ def _validate_callable_arg_types( def _skip_first_arg(template: Any, attr_name: str) -> bool: - if inspect.ismodule(template): return False diff --git a/testslide/mock_callable.py b/testslide/mock_callable.py index 7f50750..87cf2f4 100644 --- a/testslide/mock_callable.py +++ b/testslide/mock_callable.py @@ -154,7 +154,6 @@ def _format_args(indent: int, *args: Any, **kwargs: Any) -> str: def _is_coroutine(obj: Any) -> bool: - if [int(re.sub(r"[^0-9]", "", x)) for x in platform.python_version_tuple()] < [ 3, 11, @@ -680,7 +679,6 @@ def _registered_calls(self) -> Any: class _MockCallableDSL: - CALLABLE_MOCKS: Dict[ Union[int, Tuple[int, str]], Union[Callable[[Type[object]], Any]] ] = {} @@ -1166,7 +1164,6 @@ def and_assert_called_ordered( class _MockAsyncCallableDSL(_MockCallableDSL): - _NAME: str = "mock_async_callable" def __init__( diff --git a/testslide/version b/testslide/version index 24ba9a3..860487c 100644 --- a/testslide/version +++ b/testslide/version @@ -1 +1 @@ -2.7.0 +2.7.1 diff --git a/util/testslide-snippets/package.json b/util/testslide-snippets/package.json index 9f01128..9e382fa 100644 --- a/util/testslide-snippets/package.json +++ b/util/testslide-snippets/package.json @@ -8,7 +8,7 @@ "type": "github", "url": "https://github.com/facebook/TestSlide" }, - "version": "2.7.0", + "version": "2.7.1", "engines": { "vscode": "^1.40.0" },