[Python-Dev] A Testing language Construct that could also be a Distributed programming construct - How can this be done in Python
Brett Cannon
brett at python.org
Sun Aug 17 21:10:37 CEST 2008
This is the wrong mailing list to ask this question; python-dev is for
discussing the design of the language. General help questions should
go to comp.lang.python.
On Sun, Aug 17, 2008 at 3:52 AM, Saravanan Shanmugham (sarvi)
<sarvi at cisco.com> wrote:
> I am using Python as a test language and wondering how best to represent
> what is shown below in TTCN-3
> TTCN-3, a testing domain specific language has a construct that looks like
> below Its trying to send a request and define 3 alternative
> outcomes/events.
>
> web_port.send("http://www.googe.com/")
> resonseTimer.start(300)
> alt {
> [] web_port.receive("something") {
> responseTimer.stop;
> setverdict(pass);
> }
> [] web_port.receive("somethingelse") {
> responseTimer.stop;
> setverdict(fail);
> }
> [] responseTimer.timeout {
> setverdict(fail);
> }
> }
>
> I am trying to do something similar with python and find myself in a fix as
> to how to code it clean.
>
> I can't do it with
> if ...elseif ... elseif .... else
> unless I wrap it in an event loop.
> Since otherwise it means that each condition function will be executed
> once. While what we are looking for is way to define potential events that
> can happen and a particular segment of code to executed for a specific event
> match
>
> The closest thing that I can do is something like this, assuming I implement
> the doalternatives method to take a list of function, code pairs. It would
> take the list of function-name, parameters list and run it in an event loop
> or in separate threads as the need may be to match one of them.
> When one of them matches it would be expected to run the code block
> associated with it. Which would get me the same behaviour.
>
> doalternatives(
> [web_port.receive,"something"],
> "responseTimer.stop;
> setverdict(pass);"
> [web_port.receive,"somethingelse"],
> "responseTimer.stop;
> setverdict(fail);"
> [responseTimer.timeout],
> "responseTimer.stop;
> setverdict(pass);"
> }
>
> The above looks pretty ok. Except that I have to define the python code
> block as a string.
> It would be nice if there was a python language construct that would allow
> me to define a block of python code that can be passed as a code object into
> a function.
>
> That would serve the above purpose as well as cases for distributed or
> parallel programming as well.
>
> A construct like
> invoke doalternatives with:
> param [web_port.receive,"something"]
> param:
> responseTimer.stop()
> setverdict(pass)
> param [web_port.receive,"something else"]
> param:
> responseTimer.stop()
> setverdict(fail)
> param [responseTimer.timeout]
> param:
> responseTimer.stop()
> setverdict(pass)
>
> I am sure we can do better than what I have proposed above. But the general
> idea is to be able to define and pass code segments as code objects around a
> function invocation and and pass the code objects as parameters into the
> invoked function.
>
> What do people think? Is there any existing construct that I might be
> missing to achieve the above?
>
> Sarvi
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/brett%40python.org
>
>
More information about the Python-Dev
mailing list