[Python-projects] Assertions, type checking, and testing

Aurélien Campéas aurelien.campeas at logilab.fr
Mon Jun 19 11:36:35 CEST 2006


On Fri, Jun 09, 2006 at 11:04:31AM -0400, David G. Wonnacott wrote:
> Please excuse my asking of a long and elementary question. I have
> done some general Google searches, but found so many options that I
> had trouble choosing among them, and I have done some searches that
> were restricted to lists.logilab.org, but found only things like a
> question I asked on June 13 of last year :-(
> 

I haven't seen an answer to this, so ...

> 
> 
> I hope to start teaching introductory computer science with Python
> (rather than C++), but am not that fluent with Python myself yet.
> This is clearly a recipe for potential disaster, so in addition to

Since you are coming from C++ (fluent in that ?), I don't believe
switching to python can be a recipe to disater, even if you are only
learning the basics. You will be stunned by the amount of C++ verbiage
that is just useless and has to be unlearned. This is a good move :)

> generally playing with python this summer, I am hoping you can give
> me some guidance on one or two key issues that I think are elevant
> to your approach at LogiLab.
> 
> Our introductory sequence emphasizes various approaches to thinking
> about algorithms and data structures; we talk quite a bit about
> assertions, and also about their relationship to proofs and
> testing. We spend as little time on language features as we can.
> 
> I am hoping to find some combined set of Python tools that will let us
> make a variety of specific kinds of assertions, such as function pre-
> and post-conditions, loop invariants, and data-structure invariants. I
> would like to be able to include assertions about the types of
> objects, but do not want to have to do this in all cases (since part
> of the appeal of Python is that you get to focus on your algorithm
> rather than on expressing the type of your algorithm).
> 
> I am also hoping to find either
> 
> a) testing tools to let us selectively disengage various classes of
>    assertions (i.e. you want to test pre- and post-conditions and loop
>    invariants during unit tests, but perhaps only pre-conditions
>    during some integration tests), or

To me this looks like a software engineering requirement more than
something needed in the context of algorithmic teaching ... (esp. the
ability to selectively switch on and off various kinds of assertions)

> 
> b) static checks of these assertions (I had asked last year about
>    doing this with logilab's logic system).
> 
> 
> Please let me know if you have any recommendations for tools for
> specialized assertions, especially if they integrate with either
> testing tools or static checks.

The aspects package from logilab could be of some help, wrt defining
various kinds of invariants, pre- post- conditions on *methods* ...

I don't know of any tool that would do a), but I don't know a great
deal of the immense python toolset available out there, and it might
be possible to build such a simple tool with a few lines of
code. Could you give some examples of the kind of assertions you would
want to check and be able to enable/disable on the fly, and also these
properties you would want to statically check (something Pylint could
be used for, maybe) -- in
pseudo-code ?

Cheers,
Aurélien.

> 
> I'd also appreciate any other general recommendations for someone in
> my position.

ps: if checking assertions/invariants (in code) is so important, you
could consider using Eiffel, or even B
(http://en.wikipedia.org/wiki/B-Method) but for this one the tools are unfree.

> 
> Thanks,
> 	Dave Wonnacott
> 	davew at cs.haverford.edu
> _______________________________________________
> Python-Projects mailing list
> Python-Projects at lists.logilab.org
> http://lists.logilab.org/mailman/listinfo/python-projects
> 


More information about the Python-Projects mailing list