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


Groups > comp.lang.python > #24901 > unrolled thread

Re: adding a simulation mode

Started byDieter Maurer <dieter@handshake.de>
First post2012-07-05 10:39 +0200
Last post2012-07-05 10:39 +0200
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.


Contents

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

#24901 — Re: adding a simulation mode

FromDieter Maurer <dieter@handshake.de>
Date2012-07-05 10:39 +0200
SubjectRe: adding a simulation mode
Message-ID<mailman.1816.1341477607.4697.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web