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


Groups > comp.lang.python > #24856

adding a simulation mode

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <andrea.crotti.0@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'paths': 0.05; 'subject:adding': 0.07; 'command.': 0.09; 'false)': 0.09; 'garbage': 0.09; 'happen.': 0.09; 'logic': 0.09; 'thrown': 0.09; 'to:name:python-list': 0.15; 'dest)': 0.16; 'perforce': 0.16; 'simulate': 0.16; 'sqlalchemy': 0.16; 'variable': 0.20; 'exceptions': 0.22; 'example': 0.23; 'idea': 0.24; 'external': 0.24; 'pass': 0.25; 'possibility': 0.27; 'disk': 0.27; 'message- id:@mail.gmail.com': 0.27; 'run': 0.28; 'parameters.': 0.29; "i'm": 0.29; 'maybe': 0.29; 'checked': 0.30; 'implement': 0.32; 'interaction': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'machines': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'add': 0.36; 'but': 0.36; 'should': 0.36; 'too': 0.36; 'possible': 0.37; 'virtual': 0.37; 'quite': 0.37; 'received:209': 0.37; 'files': 0.38; 'some': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'else.': 0.65; 'potentially': 0.66; 'complex,': 0.84; 'mock': 0.84; 'subject:mode': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=ynIReKSQXVAaQ/cHmcZFmgRCHvTdAsesQH/FeSvi+9A=; b=MGsiIscVmu0+cy+SbJu9CRs8myTZatSbiIGMLGKTV8oqGmodsDaPDcjzuxfb27/eFl 2Uo0J+wMTg8utWuRzX7XkUUl2kAOzd9EDsWxXJl5x/tQZaxsuFtO+T/OaUjBB0DQiJyP 7q65dIxbkUbUkpggf172mzCJlvB/yypDiIaJCQh9HSUbccxI2mLZTnOzu35liaa8vrea 6xjAijD/Giu8GHA4rtcpTX74tY5+OYgi3AYMJdKnGKtEZQC+kZ0fZvv+qnujby/OMZ4M pWkPqg/VEIAcVqYu9QUsu6onBHWgPMcjigyJ6EoFXhest3F11S2uuDJ1tpcHkc0UGd1v 7r6Q==
MIME-Version 1.0
Date Wed, 4 Jul 2012 10:42:56 +0100
Subject adding a simulation mode
From andrea crotti <andrea.crotti.0@gmail.com>
To python-list <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
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.1786.1341394979.4697.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1341394979 news.xs4all.nl 6971 [2001:888:2000:d::a6]:37159
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:24856

Show key headers only | View raw


I'm writing a program which has to interact with many external
resources, at least:
- mysql database
- perforce
- shared mounts
- files on disk

And the logic is quite complex, because there are many possible paths to
follow depending on some other parameters.
This program even needs to run on many virtual machines at the same time
so the interaction is another thing I need to check...

Now I successfully managed to mock the database with sqlalchemy and only
the fields I actually need, but I now would like to simulate also
everything else.

I would like for example that if I simulate I can pass a fake database,
a fake configuration and get the log of what exactly would happen.  But
I'm not sure how to implement it now..  One possibility would be to have
a global variable (PRETEND_ONLY = False) that if set should be checked
before every potentially system-dependent command.

For example

copytree(src, dest) becomes:
if not PRETEND_ONLY:
    copytree(src, dest)

But I don't like it too much because I would have to add a lot of
garbage around..

Another way is maybe to set the sys.excepthook to something that catchs
all the exceptions that would be thrown by these comands, but I'm not
sure is a good idea either..

Any suggestion?

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


Thread

adding a simulation mode andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-04 10:42 +0100
  Re: adding a simulation mode Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-04 13:41 +0000
    Re: adding a simulation mode andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-04 14:59 +0100
    Re: adding a simulation mode andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-04 15:19 +0100
  Re: adding a simulation mode Paul Rubin <no.email@nospam.invalid> - 2012-07-04 10:01 -0700

csiph-web