Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: adding a simulation mode

Reply
Thread Tools

Re: adding a simulation mode

 
 
andrea crotti
Guest
Posts: n/a
 
      07-12-2012
One way instead that might actually work is this

def default_mock_action(func_name):
def _default_mock_action(*args, **kwargs):
print("running {} with args {} and {}".format(func_name, args, kwargs))

return _default_mock_action


def mock_fs_actions(to_run):
"""Take a function to run, and run it in an environment which
mocks all the possibly dangerous operations
"""
side_effect = [
'copytree',
'copy',
]

acts = dict((s, default_mock_action(s)) for s in side_effect)

with patch('pytest.runner.commands.ShellCommand.run',
default_mock_action('run')):
with patch.multiple('shutil', **acts):
to_run()


So I can just pass the main function inside the mock like
mock_fs_actions(main)

and it seems to do the job, but I have to list manually all the things
to mock and I'm not sure is the best idea anyway..
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: adding a simulation mode andrea crotti Python 0 07-05-2012 09:22 AM
Re: adding a simulation mode Dieter Maurer Python 0 07-05-2012 08:39 AM
adding a simulation mode andrea crotti Python 4 07-04-2012 05:01 PM
Re: adding a simulation mode Devin Jeanpierre Python 0 07-04-2012 04:08 PM
Re: adding a simulation mode Mike C. Fletcher Python 0 07-04-2012 03:30 PM



Advertisments