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


Groups > comp.lang.python > #24867

Re: adding a simulation mode

Date 2012-07-04 11:30 -0400
From "Mike C. Fletcher" <mcfletch@vrplumber.com>
Subject Re: adding a simulation mode
References <CAF_E5JbFK4ZYsvwdVHxw-S7vLkpwskF=OCohWW2okmPi56ObOA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1793.1341416405.4697.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web