Re: adding a simulation mode

Discussion in 'Python' started by Mike C. Fletcher, Jul 4, 2012.

  1. 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
     
    Mike C. Fletcher, Jul 4, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. andrea crotti

    adding a simulation mode

    andrea crotti, Jul 4, 2012, in forum: Python
    Replies:
    4
    Views:
    232
    Paul Rubin
    Jul 4, 2012
  2. Devin Jeanpierre

    Re: adding a simulation mode

    Devin Jeanpierre, Jul 4, 2012, in forum: Python
    Replies:
    0
    Views:
    204
    Devin Jeanpierre
    Jul 4, 2012
  3. Dieter Maurer

    Re: adding a simulation mode

    Dieter Maurer, Jul 5, 2012, in forum: Python
    Replies:
    0
    Views:
    187
    Dieter Maurer
    Jul 5, 2012
  4. andrea crotti

    Re: adding a simulation mode

    andrea crotti, Jul 5, 2012, in forum: Python
    Replies:
    0
    Views:
    176
    andrea crotti
    Jul 5, 2012
  5. andrea crotti

    Re: adding a simulation mode

    andrea crotti, Jul 12, 2012, in forum: Python
    Replies:
    11
    Views:
    431
    Chris Angelico
    Jul 13, 2012
Loading...

Share This Page