adding a simulation mode

Mike C. Fletcher mcfletch at vrplumber.com
Wed Jul 4 17:30:46 CEST 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




More information about the Python-list mailing list