473,769 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2754
At some point, Brian <ba***@sympatic o.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.writ e(sys.stdout.ge tvalue())
old_stderr.writ e(sys.stderr.ge tvalue())

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)phy sics(dot)mcmast er(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***@sympatic o.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)phy sics(dot)mcmast er(dot)ca
Jul 18 '05 #4

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

Similar topics

0
1773
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 getch(); iv) hit a key; v) the program locks up, the interptreter is now munching on the CPU; vi) kill the interpreter from another shell; vii) scratch head and wonder why neither of the mutually exclusive clauses in the _io() member function...
1
2003
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: curses.h: check for missing prerequisite headers? configure: WARNING: curses.h: see the Autoconf documentation configure: WARNING: curses.h: section "Present But Cannot Be Compiled" configure: WARNING: curses.h: proceeding with the...
9
1536
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 cannot be compiled configure: WARNING: curses.h: check for missing prerequisite headers? configure: WARNING: curses.h: see the Autoconf documentation configure: WARNING: curses.h: section "Present But Cannot Be Compiled" configure: WARNING:...
1
3696
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 # # Brick & Ball in Python # by Jerry Fleming <jerryfleming@etang.com>
3
3717
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 version of curses in /usr/lib, so I downloaded and installed ncurses 5.5, both using default settings and using --with-shared. When the curses module is linked against libcurses.so I get some strange error about acs32map being undefined (which...
3
1544
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 .................................. Check for something else .......................... """
15
4815
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 ncurses. But as far as I can tell, it is not available for Python on Windows? Is there a workaround? Or are there alternative libraries that might be used instead of (n)curses? I know I can use (n)curses on *nix and console on Windows etc., but...
1
2835
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 correctly on UTF-8 enabled console. I googled around and got an impression that the reason for this problem is that python is linked with libcurses library instead of libcursesw. The latter one is said to be able to solve this problem. Has anybody...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10212
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7410
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.