Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #24867 > unrolled thread

Re: adding a simulation mode

Started by"Mike C. Fletcher" <mcfletch@vrplumber.com>
First post2012-07-04 11:30 -0400
Last post2012-07-04 11:30 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: adding a simulation mode "Mike C. Fletcher" <mcfletch@vrplumber.com> - 2012-07-04 11:30 -0400

#24867 — Re: adding a simulation mode

From"Mike C. Fletcher" <mcfletch@vrplumber.com>
Date2012-07-04 11:30 -0400
SubjectRe: adding a simulation mode
Message-ID<mailman.1793.1341416405.4697.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web