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


Groups > comp.lang.python > #24901

Re: adding a simulation mode

Path csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'paths': 0.05; 'subject:adding': 0.07; 'python': 0.09; 'alternatives': 0.09; 'components:': 0.09; 'logic': 0.09; 'other,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'component': 0.15; 'interfaces': 0.15; 'paradigm.': 0.16; 'perforce': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'registry': 0.16; 'simulate': 0.16; 'sqlalchemy': 0.16; 'satisfying': 0.22; 'external': 0.24; 'header:User-Agent:1': 0.26; '(e.g.': 0.27; 'components': 0.27; 'disk': 0.27; 'interface': 0.27; 'header:X-Complaints-To:1': 0.28; 'run': 0.28; 'asks': 0.29; 'parameters.': 0.29; 'writes:': 0.29; "i'm": 0.29; 'gets': 0.32; 'switch': 0.32; 'interaction': 0.33; 'handle': 0.33; 'to:addr :python-list': 0.33; 'themselves': 0.33; 'another': 0.33; 'machines': 0.35; 'there': 0.35; 'received:org': 0.36; 'really': 0.36; 'but': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.37; 'uses': 0.37; 'virtual': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'easy': 0.60; 'provide': 0.62; 'different': 0.63; 'else.': 0.65; 'received:217': 0.68; 'andrea': 0.84; 'complex,': 0.84; 'mock': 0.84; 'subject:mode': 0.84; 'hand.': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dieter Maurer <dieter@handshake.de>
Subject Re: adding a simulation mode
Date Thu, 05 Jul 2012 10:39:44 +0200
References <CAF_E5JbFK4ZYsvwdVHxw-S7vLkpwskF=OCohWW2okmPi56ObOA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Gmane-NNTP-Posting-Host pd9e09178.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
Cancel-Lock sha1:/PkY/YwOtJZSlcPAdu3A6jiF2UY=
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.1816.1341477607.4697.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1341477607 news.xs4all.nl 6890 [2001:888:2000:d::a6]:42206
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:24901

Show key headers only | View raw


andrea crotti <andrea.crotti.0@gmail.com> writes:

> 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.

There is a paradigm called "inversion of control" which can be used
to handle those requirements.

With "inversion of control", the components interact on the bases
of interfaces. The components themselves do not know each other, they
know only the interfaces they want to interact with. For the interaction
to really take place, a component asks a registry "give me a component
satisfying this interface", gets it and uses the interface.

If you follow this paradigm, it is easy to switch components: just
register different alternatives for the interface at hand.


"zope.interface" and "zope.component" are python packages that
support this paradigm. Despite the "zope" in their name, they can be
used outside of "Zope".

"zope.interface" models interfaces, while "zope.component" provides
so called "utilities" (e.g. "database utility", "filesystem utility", ...)
and "adapters" and the corresponding registries.


Of course, they contain only the infrastructure for the "inversion of control"
paradigm. Up to you to provide the implementation for the various
mocks.

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


Thread

Re: adding a simulation mode Dieter Maurer <dieter@handshake.de> - 2012-07-05 10:39 +0200

csiph-web