[ANN] Metatest 0.1.0
Jonathan Fine
jfine at pytex.org
Tue Sep 18 19:46:06 EDT 2007
Ben Finney wrote:
> Jonathan Fine <jfine at pytex.org> writes:
>
>>Here's how to write some tests using Metatest. We can think of the
>>tests as an executable specification.
>>
>> from metatest.py.mymod import plus, Point
>>
>> # Function plus adds two numbers.
>> plus(2, 2) == 4
>> plus(2, '', _ex=TypeError)
>
> This second example seems counterintuitive. Is '_ex' part of the
> public interface? If so, why does it follow the convention for "not
> part of the public interface" (i.e. it is named with an underscore)?
Hello Ben
(Well, I'm glad you seem to find the first example intuitive.)
No, the function we are testing here is
def plus(a, b):
return a + b
However, the line
plus(2, '', _ex=TypeError)
refers only indirectly to the function plus, to be imported from mymod.
Read again the line
from metatest.py.mymod import plus, Point
We do some metapath magic and some __method__ tricks to ensure that here
plus is what I have called a 'stub object', although 'unknown' would be
a better term. See
http://metatest.sourceforge.net/doc/pyconuk2007/metatest.html#slide11
http://www.python.org/dev/peps/pep-0302/
The line
plus(2, '', _ex=TypeError)
causes something to be recorded, and when the test is run the _ex
argument is filtered off, and the remaining arguments passed to the plus
function, as imported from mymod.
This is done by the function split_kwargs in the module
http://metatest.cvs.sourceforge.net/metatest/metatest/py/metatest/player.py?view=markup
Hope this helps. If not, maybe try downloading and running it.
Finally, if you can think of a better way of saying, in Python, "The
function call plus(2, '') raises a TypeError", please let me know, and
I'll consider using it in the next version of Metatest.
--
Jonathan
More information about the Python-list
mailing list