473,418 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

unitest with python curses app

Hello;

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?)

The curses part of the program seems to affect unittest's writing of the
report. The screen is not what the report expects, so a lot of
information is in the wrong place after the program exits. (I actually wrap
the calls into the
curses library with curses.wrapper() in an attempt to restore the display
properly after the program exits -- to no avail. I guess the problem is
that unittest writes to the display while curses has control, not just
just afterwards.

How do I handle test reporting for a graphical (curses) application? I
would really like to read or capture the report on screen after the
program exits.

Many thanks,

Brian.
Jul 18 '05 #1
3 2733
At some point, Brian <ba***@sympatico.ca> wrote:
Hello;

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?
The curses part of the program seems to affect unittest's writing of the
report. The screen is not what the report expects, so a lot of
information is in the wrong place after the program exits. (I actually wrap
the calls into the
curses library with curses.wrapper() in an attempt to restore the display
properly after the program exits -- to no avail. I guess the problem is
that unittest writes to the display while curses has control, not just
just afterwards.
Right. Pain in the ass to debug that stuff too.
How do I handle test reporting for a graphical (curses) application? I
would really like to read or capture the report on screen after the
program exits.


Probably setting sys.stdout and sys.stderr to your own file objects
would work before calling unittest.main(). Something like this would
give the output after it runs:

import sys
from cStringIO import StringIO
import unittest

....test cases...

if __name__ == '__main__':
old_stdout, old_stderr = sys.stdout, sys.stderr
sys.stdout = StringIO()
sys.stderr = StringIO()
unittest.main()
old_stdout.write(sys.stdout.getvalue())
old_stderr.write(sys.stderr.getvalue())

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Jul 18 '05 #2
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.

Brian.
Jul 18 '05 #3
At some point, Brian <ba***@sympatico.ca> wrote:
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.)


Only recently -- I've been trying to port a DOS-era game written in
Turbo Pascal to run under Unix with ncurses. Debugging is a pain --
nevermind curses, but gdb doesn't work nicely with GNU Pascal.
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: [snip] 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.


Good idea. You could make a 'screen painter' to mock up what the
screen should be, to make it easier to generate the correct screens.

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matthew Alton | last post by:
The appended program freaks python 2.2 & 2.3 completely out. To reproduce the wierdness: i) copy the source to a file called consarn.py ii) $ python consarn.py; iii) the program is now doing a...
1
by: spanov | last post by:
i've got problem installing python-2.3.5 from sources on FreeBSD 5.3 root@server# ./configure > conf_log configure: WARNING: curses.h: present but cannot be compiled configure: WARNING:...
9
by: David Bear | last post by:
I need python 2.3. I have freebsd 4.10-releng. when configuring python I received the following: ../configure --prefix=/home/webenv > config-results configure: WARNING: curses.h: present but...
1
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # #...
3
by: skip | last post by:
I'm having no success building the curses module on Solaris 8 (yes, I know it's ancient - advancing the state-of-the-art is not yet an option) for Python 2.4. Sun provides an apparently ancient...
3
by: Maxim Veksler | last post by:
Hi list, I'm working on writing sanity check script, and for aesthetic reasons I would like the output be in the formatted like the gentoo init script output, that is: """ Check for something...
15
by: pinkfloydhomer | last post by:
I need to develop a cross-platform text-mode application. I would like to do it in Python and I would like to use a mature text-mode library for the UI stuff. The obvious choice, I thought, was...
1
by: shrek2099 | last post by:
Hi All, Recently I ran into a problem with UTF-8 surrport when using curses library in python 2.5 in Fedora 7. I found out that the program using curses cannot print out unicode characters...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.