jsatt / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

wrapping modules/classes/functions specified as strings #41

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
For most cases the wrapped objects would work just as expected, but they would 
have additional tracking data attached.

@mock.wrap('sys.stdin')
def foo(wrapped_stdin):
    do_sth()
    assert wrapped_stdin.called

Original issue reported on code.google.com by kon...@gmail.com on 24 Jun 2010 at 2:26

GoogleCodeExporter commented 8 years ago
Do you mean patch.wrap? I don't really understand what this would do and what 
"additional tracking data" it would have I'm afraid. (I'm sure you're aware of 
the wraps argument to Mock, right?)

Original comment by fuzzyman on 24 Jun 2010 at 7:49

GoogleCodeExporter commented 8 years ago
I meant mock.wrap, because I'd like to consider it somewhat parallel to patch. 
On the other hand, it actually performs the replacement and safe cleanup, so 
patch.wrap would be fine.

The idea is that all objects would basically act just like they should if no 
mocking was there, expect that they will also records their callargs and so on 
- just like a mock wrapping an object.

What's different here is - as I said - wrappling object *specified by strings*, 
so instead of writing

@patch('sys.stdin', Mock(wraps=sys.stdin)

I would just write 

@patch.wrap("sys.stdin")

Original comment by kon...@gmail.com on 24 Jun 2010 at 10:11

GoogleCodeExporter commented 8 years ago
Ah. So if you mean:

   @patch.wrap("sys.stdin") 

would be the equivalent of:

    @patch('sys.stdin', Mock(wraps=sys.stdin)

I would prefer it on patch than on mock as it is just another way of doing 
specialised patching.

Then I understand. :-) I'm not sure how commonly wraps is used and how much 
this is needed.

Original comment by fuzzyman on 24 Jun 2010 at 10:16

GoogleCodeExporter commented 8 years ago
patch.wrap('...') creating a mock that wraps an object, using Mock(wraps='...') 
is fine.

Original comment by fuzzyman on 26 Jun 2010 at 6:42

GoogleCodeExporter commented 8 years ago

Original comment by fuzzyman on 18 Jun 2011 at 12:03