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


Groups > comp.lang.python > #24867

Re: adding a simulation mode

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <mcfletch@vrplumber.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.034
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'subject:adding': 0.07; 'unittest': 0.07; 'url:blog': 0.09; 'src,': 0.09; 'def': 0.10; '05:42': 0.16; 'dest': 0.16; 'dest)': 0.16; 'wrote:': 0.17; 'import': 0.21; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'mike': 0.27; 'assert': 0.29; 'src': 0.29; 'class': 0.29; 'install': 0.29; 'function': 0.30; 'to:addr:python-list': 0.33; 'self': 0.34; 'whatever': 0.35; 'skip:_ 40': 0.35; 'should': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'skip:u 10': 0.60; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'andrea': 0.84; 'received:192.168.15': 0.84; 'received:98.158': 0.84; 'subject:mode': 0.84
Date Wed, 04 Jul 2012 11:30:46 -0400
From "Mike C. Fletcher" <mcfletch@vrplumber.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: adding a simulation mode
References <CAF_E5JbFK4ZYsvwdVHxw-S7vLkpwskF=OCohWW2okmPi56ObOA@mail.gmail.com>
In-Reply-To <CAF_E5JbFK4ZYsvwdVHxw-S7vLkpwskF=OCohWW2okmPi56ObOA@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To mcfletch@vrplumber.com
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1793.1341416405.4697.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1341416405 news.xs4all.nl 6894 [2001:888:2000:d::a6]:45270
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:24867

Show key headers only | 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