-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make new functionality available under for_partial_call to align with…
… for_call as recommended by @fornellas. Also added more tests, and moved docs around
- Loading branch information
Showing
3 changed files
with
80 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,44 @@ | ||
from testslide import TestCase | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from testslide import TestCase, mock_callable | ||
|
||
from . import sample_module | ||
|
||
|
||
class TestAcceptAnyArg(TestCase): | ||
def test_ignore_other_args(self): | ||
self.mock_callable( | ||
sample_module, "test_function", ignore_other_args=True | ||
).for_call("a").to_return_value(["blah"]) | ||
def test_for_partial_call_accepts_all_other_args(self): | ||
self.mock_callable(sample_module, "test_function").for_partial_call( | ||
"a" | ||
).to_return_value(["blah"]) | ||
sample_module.test_function("a", "b") | ||
|
||
def test_ignore_other_kwargs(self): | ||
self.mock_callable( | ||
sample_module, "test_function", ignore_other_kwargs=True | ||
).for_call("firstarg", "secondarg", kwarg1="a").to_return_value(["blah"]) | ||
def test_for_partial_call_accepts_all_other_kwargs(self): | ||
self.mock_callable(sample_module, "test_function").for_partial_call( | ||
"firstarg", "secondarg", kwarg1="a" | ||
).to_return_value(["blah"]) | ||
sample_module.test_function("firstarg", "secondarg", kwarg1="a", kwarg2="x") | ||
|
||
def test_ignore_other_args_and_kwargs(self): | ||
self.mock_callable( | ||
sample_module, | ||
"test_function", | ||
ignore_other_args=True, | ||
ignore_other_kwargs=True, | ||
).for_call("firstarg", kwarg1="a").to_return_value(["blah"]) | ||
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"]) | ||
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( | ||
"firstarg", kwarg1="a" | ||
).to_return_value(["blah"]) | ||
sample_module.test_function( | ||
"differentarg", "alsodifferent", kwarg1="a", kwarg2="x" | ||
) | ||
|
||
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( | ||
"firstarg", kwarg1="x" | ||
).to_return_value(["blah"]) | ||
sample_module.test_function("firstarg", "secondarg", kwarg1="a", kwarg2="x") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters