Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Re: adding a simulation mode

 
 
Mike C. Fletcher
Guest
Posts: n/a
 
      07-04-2012
On 12-07-04 05:42 AM, andrea crotti wrote:
....
> copytree(src, dest) becomes:
> if not PRETEND_ONLY:
> copytree(src, dest)

import globalsub, unittest

class MyTest( unittest.TestCase ):
def setUp( self ):
globalsub.subs( shutil.copytree )
def tearDown( self ):
globalsub.restore( shutil.copytree )

You can also pass a function to subs like so:

def setUp( self ):
self.copied_trees = []
def fake_copytree( src, dest ):
assert os.path.exists( src )
self.copied_trees.append( (src, dest ))
return dest # or whatever the thing should return
globalsub.subs( shutil.copytree, fake_copytree )

$ pip install globalsub

HTH,
Mike

--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com

 
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 11 07-13-2012 05:24 PM
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



Advertisments