unitest with python curses app

Brian balex at sympatico.ca
Sat Feb 21 06:51:54 CET 2004

On Fri, 20 Feb 2004 16:52:07 -0500, David M. Cooke wrote:

>> I'm writing a program with curses in python and having a bit of trouble
>> understanding how to use unittest. So far, I have used testing
>> successfully -- as long as the report goes to stdout (or does unittest
>> write to stderr?)
> I'm interested: how are you unit testing curses routines? Are you
> testing just the output routines, or are other non-curses routines being
> called?
Unfortunately, only the routines that did not involve the curses module were
easy to test. Judging from your message, I think you inferred this.
(Indeed, you seem to have lived it.)

However, I did build a dump-to-text feature into an object that wraps
all curses newwin objects. When <obj>.dumpCells() is called, a text record for
each cell in the newwin is generated. It looks something like this:

t 5 5 -acharset +abold ... (other attribute codes follow)
h 5 6 -acharset +abold ... (other attribute codes follow)
... (other cell records follow)

With respect to the first record: "t" is the character at [y ,x] ==
[5,5]. It is not from the alternate
character set (-acharset). It is rendered in bold (+abold). Other
attributes follow the same pattern: +attrName for on and -attrName for
off. Foreground and background colour numbers (or names -- I can't
remember) appear at the end.

These human readable-records could be used to build test cases for the
screen outputs. I haven't done it yet, though. I imagine such a test
comparing the results of a call to .cellDump() to some stored (and
correct, hopefully) result in a file.


More information about the Python-list mailing list