Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24867 > unrolled thread
| Started by | "Mike C. Fletcher" <mcfletch@vrplumber.com> |
|---|---|
| First post | 2012-07-04 11:30 -0400 |
| Last post | 2012-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.
Re: adding a simulation mode "Mike C. Fletcher" <mcfletch@vrplumber.com> - 2012-07-04 11:30 -0400
| From | "Mike C. Fletcher" <mcfletch@vrplumber.com> |
|---|---|
| Date | 2012-07-04 11:30 -0400 |
| Subject | Re: 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
Back to top | Article view | comp.lang.python
csiph-web