Skip to content

Commit

Permalink
release TestSlide 2.7.1 with various tiny changes (#347)
Browse files Browse the repository at this point in the history
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: #347

Reviewed By: pmazzini

Differential Revision: D44133897

Pulled By: deathowl

fbshipit-source-id: a01a3c35ebd8132f942b72be4cfb1ccef5b85483
  • Loading branch information
deathowl authored and facebook-github-bot committed Mar 16, 2023
1 parent 1b6bc10 commit d8b0c58
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pytest-testslide/testslide-version
@@ -1 +1 @@
2.7.0
2.7.1
20 changes: 16 additions & 4 deletions tests/accept_any_arg_unittest.py
Expand Up @@ -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(
Expand All @@ -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")
12 changes: 6 additions & 6 deletions tests/cli_unittest.py
Expand Up @@ -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'
),
)

Expand Down
11 changes: 0 additions & 11 deletions tests/dsl_unittest.py
Expand Up @@ -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):
Expand Down Expand Up @@ -413,7 +412,6 @@ def not_focused(context):


class TestDSLSharedContext(TestDSLBase):

# Shared contexts

def test_shared_context_named_from_decorator(self):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -843,7 +839,6 @@ def test_memoize_attribute(self):

@context
def top(context):

value = 1
memoized = []

Expand Down Expand Up @@ -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)
Expand All @@ -892,7 +886,6 @@ def test_memoize_attribute_with_kwargs(self):

@context
def top(context):

value = 1

context.memoize(
Expand Down Expand Up @@ -954,7 +947,6 @@ def test_memoize_before_attribute(self):

@context
def top(context):

value = 1
memoized = []

Expand All @@ -981,7 +973,6 @@ def test_memoize_before_attribute_as_lambda(self):

@context
def top(context):

value = 1
memoized = []

Expand Down Expand Up @@ -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"))

Expand Down Expand Up @@ -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"))

Expand Down
15 changes: 0 additions & 15 deletions tests/mock_callable_testslide.py
Expand Up @@ -26,7 +26,6 @@ async def coro_fun(*args):

@context("mock_callable()")
def mock_callable_tests(context):

##
## Attributes
##
Expand Down Expand Up @@ -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")
Expand All @@ -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)")
Expand All @@ -357,15 +354,13 @@ def setup_assertion(self):

@context.sub_context
def fails_when(context):

context.merge_context("assert failure")

context.merge_context("not called")
context.merge_context("called less times")

@context.sub_context
def passes_when(context):

context.merge_context("called exactly times")
context.merge_context("called more times")

Expand All @@ -388,15 +383,13 @@ def setup_assertion(self):

@context.sub_context
def fails_when(context):

context.merge_context("assert failure")

context.merge_context("not called")
context.merge_context("called more times fail")

@context.sub_context
def passes_when(context):

context.merge_context("called less times")
context.merge_context("called exactly times")

Expand All @@ -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")
Expand Down Expand Up @@ -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"]]
)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/mock_constructor_testslide.py
Expand Up @@ -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)

Expand Down
3 changes: 0 additions & 3 deletions tests/strict_mock_testslide.py
Expand Up @@ -64,7 +64,6 @@ async def __aexit__(self, exc_type, exc, tb):


class Template(TemplateParent):

__slots__ = ["slot_attribute"]

non_callable: str = "original value"
Expand Down Expand Up @@ -553,7 +552,6 @@ def works_with_wraps(self):

@context.shared_context
def common_examples(context, type_validation):

if type_validation:

@context.example
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion testslide/__init__.py
Expand Up @@ -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(
Expand Down
3 changes: 0 additions & 3 deletions testslide/cli.py
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -172,7 +170,6 @@ class _Config:


class Cli:

FORMAT_NAME_TO_FORMATTER_CLASS = {
"p": ProgressFormatter,
"progress": ProgressFormatter,
Expand Down
2 changes: 0 additions & 2 deletions testslide/lib.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions testslide/mock_callable.py
Expand Up @@ -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,
Expand Down Expand Up @@ -680,7 +679,6 @@ def _registered_calls(self) -> Any:


class _MockCallableDSL:

CALLABLE_MOCKS: Dict[
Union[int, Tuple[int, str]], Union[Callable[[Type[object]], Any]]
] = {}
Expand Down Expand Up @@ -1166,7 +1164,6 @@ def and_assert_called_ordered(


class _MockAsyncCallableDSL(_MockCallableDSL):

_NAME: str = "mock_async_callable"

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion testslide/version
@@ -1 +1 @@
2.7.0
2.7.1
2 changes: 1 addition & 1 deletion util/testslide-snippets/package.json
Expand Up @@ -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"
},
Expand Down

0 comments on commit d8b0c58

Please sign in to comment.