How to test that an exception is raised ?

2005-01-28 Thread StepH
Hi,

I've this module :

from optparse import OptionParser
import re

_version = "P1"

def writeVar(f, line):
"""Output a line in .xml format in the file f."""

f.write('\t\n')
name = line.split()[0]
adr = line.split()[3]
f.write('\t\t' + name + '\n')
f.write('\t\t' + adr + '\n')
f.write('\t\n')

def mps2xml(mps,verbose):
"""Convert '.mps' to '.xml'."""

try:
f = open(mps)
f.close()

xmlfile = mps + ".xml"
f = open(xmlfile, "w+")
f.write('\n')
f.writelines('\n')

pat = re.compile(".*Var.*g.*0x00.*")
lines = list(open(mps))
nbScan = nbFound = 0
for line in lines:
nbScan = nbScan + 1
if pat.match(line):
writeVar(f, line)
nbFound = nbFound + 1

f.writelines('\n')
f.close()

if verbose:
print "Output to file %s..." % xmlfile
print "Lines scanned:", nbScan
print "Lines found:", nbFound

except:
if verbose:
print "FileError"

if __name__ == "__main__":
usage = "usage: %prog [options] filename"
parser = OptionParser(usage)

parser.add_option("-v", "--verbose", action="store_true",
dest="verbose")
parser.add_option("-q", "--quiet", action="store_false", dest="verbose")

(options, args) = parser.parse_args()

if len(args) != 1:
parser.error("incorrect number of arguments")
exit(1)

if options.verbose:
print "mps2xml -", _version

mps2xml(args[0],options.verbose)

And this "unittest" module :

import mps2xml
import os
import unittest

class Tests(unittest.TestCase):

def setUp(self):
self.mps = "test.mps"

def tearDown(self):
pass

def test_badFile(self):
"""Check that an exception is raised if a bad filename is passed to
mps2xml"""
self.assertRaises((IOError),mps2xml.mps2xml, "thisfiledoesntexists",
False)

def test_writeVar_Output(self):
"""Check the output of the 'writeVar' method"""

line = " irM1slotnoisePPtmp  Var.g 0x0002F6"
file = open("testWriteVar.xml","w+")
mps2xml.writeVar(file, line)
file.close()

outputlines = list(open("testWriteVar.xml"))
goodlines = list(open("testWriteVar.xml.good"))
self.assertEquals(outputlines, goodlines, 'bad output format')

def test_mps2xml_Creation(self):
    """Check if test.mps.xml is created"""

mps2xml.mps2xml(self.mps, False)
self.assert_(os.path.exists(self.mps + ".xml"), 'test.mps.xml not
created')

if __name__ == '__main__':
unittest.main()

But i've prob with the 1st test : test_badFile.
When I run the test, unittest say that no error is Raised.
But when I run the mps2xml module with a bad file as arg., the exception is
well Raised.

What i'm doing wrong ?

It is because the exception in catched in the mps2xml module ?

Thanks for your helps.

StepH.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to test that an exception is raised ?

2005-01-28 Thread StepH
Thanks for you answer.
I'm new to Python (coming from C/C++).

> > But i've prob with the 1st test : test_badFile.
> > When I run the test, unittest say that no error is Raised.
> > But when I run the mps2xml module with a bad file as arg., the exception
> > is
> > well Raised.
>
> I assume you don't actually see the exception (you don't see the stack
> traceback printed as an output) but you just see your own message
> "FileError".  That means that the exception was raised and caught by your
> try-except statement.

Yes, when i'm run mps2xml.py with a bad filename as arg., the IOError is
launched and is correctly intercepted.

>
> > What i'm doing wrong ?
> >
> > It is because the exception in catched in the mps2xml module ?
>
> With the above mentioned assumption, that must be it.  Once the exception
is
> caught, it is caught and no other code invoking mps2xml.mps2xml (including
> the assertRaises in your test) will see the exception.

Do you say that it's not possible to test (using unittest) if an exception
is well raised if the tested code catch it ?
How to solve this paradoxe ?  How to automaticaly test such code ?

>
> Your mps2xml.mps2xml function should return a value indicating success or
> failure or should re-raise the exception.

1./ Cheking error-return value if not a good idea for me, cause this make
the code less clear.  I don't want a code where i've to test each function
return value...
2./ If I re-raise the exception, then how to not show the traceback.  My
user will became crazy if they view such error msg.

>  You need a mechanism to let
> invoking code know that it was successful or it failed.  With a return
code,
> you should test that and not the exception.  The assert you use should
work
> if you re-raise the exception.
>
> And BTW, it is a bad idea to use a generic "except" statement like you do.
> That catches ALL the exceptions and you will never know if a different
> exception than IOError was raised.  You should catch only IOError
> specifically or any other exception that you may expect.  You can add then
> an extra "except" statement catching all the other exceptions, but only if
> it is essential for your application to handle all exceptions gracefully
> instead of just exiting with a stack traceback.

It seems that there is 2 school here.  I've read a lot on python, and somed
'guru' Python say that it's maybe better to use exception even for case you
can "predict", no ?  Or i'm completly wrong ?
>
> > Thanks for your helps.
> >
> > StepH.
> >
> >

Thanks again.
StepH.
>
>


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to test that an exception is raised ?

2005-01-28 Thread StepH
Antoon Pardon a écrit :
Op 2005-01-28, StepH schreef <[EMAIL PROTECTED]>:
Thanks for you answer.
I'm new to Python (coming from C/C++).
Do you say that it's not possible to test (using unittest) if an exception
is well raised if the tested code catch it ?
How to solve this paradoxe ?  How to automaticaly test such code ?

IMO you want something unittest are not designed for.
So why the assertRaises function in unittest ?  My goal is to test if an 
exception is well raised when a bad filename is passed to the mps2xml 
function.

Unittest are supposed to test for particular results, not for particular
behaviour within. If the expected behaviour is that calling code doesn't
see an exception raised, then the test passed if no exception was seen.
No (unless i don't well understand you), the expected behavior is to 
launch an exception if a bad filename is passed.  If no exception is 
raised, this is not normal.

You equally can't test which branch of an if statement was taken or
which parameter was given to a helper function in order to get to
the desired result.
I'm agree with out on this point, but not for the exception part...
That you internally raise an exception and catches it, is an
implementation detail, that normally is of no concern to
the tester.
I'll conclude this thred here...  In fact, I think I've to go-back to 
theory (at least about exception)...

Thanks at all fo trying to help me.  I'm new to Python, and i've not 
already embrass the "python way" completly.

See you later.
StepH.
--
http://mail.python.org/mailman/listinfo/python-list


wanna stop by my homemade glory hole?

2005-08-19 Thread Steph
my husband is installing an extra bathroom poolside.  there is a perfect size 
hole (unless you have a huge cock) to stick your dick through into the adjoing 
room.  come around the side of my house(perfect if you look like a repair man) 
enter into the unfisnished bathroom and I'll service you from the other side.  
you can leave when your done, no talking or small talk.  i want to do this 
before the hole gets patched up. its been a huge fantasy of mine ever since 
I've seen a glory hole online. you can email me for a time convienient for you. 
im home all-day most days so my schedule is open. do you prefer a certain color 
of lipstick? check out my pic and email here under kallegirl26 
www.no-strings-fun.net/kallegirl26 
ready and waiting, me ;o)


-- 
http://mail.python.org/mailman/listinfo/python-list


Tricks to install/run Python on Windows ?

2004-12-26 Thread StepH
Hi,
I'm new to Python.  I'm working under XP, and I've alot of prob. (not 
with the langage itself, but with the tools):

I've install Pyhton 2.4 in C:\Python24, using the .msi windows installer.
Then, I've install "PythonWin" (the last build-203).
I'll try to summerize my prob.:
1./ The PythonWin IDE is not stable at all.  Sometimes it exit without 
reason, or don't stop on breakpoint, etc...  Are some of you aware of 
bugs in the last PyhtonWin IDE release ?  I've to open the TaskManager. 
 AT some point, i'm not able to (p.e.) open a file under it !!!

2./ I've try to download Komode (he 3.1 personnal).  I've also prob. 
with it !  Also, the breakpoint seems to not always work...

3./ So, i've try to use the command line, but i've to manualy change the 
code page od my dos box from 437 to 1252 (i'm live in belgium).  And 
i've not try how to do that permanently !

4./ Before, I had Python23 and it seems that when unstalling it, all the 
keys in the registry are not removed at all.  When i've install the 2.4, 
I had a mismatch which force me to complety re-install the machine (I'm 
not an expert of the registry)...

5./ Installing komodo seems to "block" pythonwinIDE completly...
What's wrong ?  Python seems terific, but the tools...
So... maybe i've to try BlackAdder ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tricks to install/run Python on Windows ?

2004-12-27 Thread StepH
It's me a écrit :
Try running with the latest version of Python 2.3 instead of 2.4.   May be
you would have better luck.
I've found similar stability problems with some of the tools (eventhough
they have 2.4 releases) as well.
I switched back to 2.3 and so far I have no complains.

So far i remember, I'll have no prob. using Python 2.3 (and the 
PythonWin distro for 2.3), yes.

For now, I'm trying WingIDE, and all seems good.  A little slow, but for 
now, it works without "surprise".

Thanks a lot to all of you.
PS:I'll also have a look at DrPython later.
"StepH" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi,
I'm new to Python.  I'm working under XP, and I've alot of prob. (not
with the langage itself, but with the tools):
I've install Pyhton 2.4 in C:\Python24, using the .msi windows installer.
Then, I've install "PythonWin" (the last build-203).
I'll try to summerize my prob.:
1./ The PythonWin IDE is not stable at all.  Sometimes it exit without
reason, or don't stop on breakpoint, etc...  Are some of you aware of
bugs in the last PyhtonWin IDE release ?  I've to open the TaskManager.
 AT some point, i'm not able to (p.e.) open a file under it !!!
2./ I've try to download Komode (he 3.1 personnal).  I've also prob.
with it !  Also, the breakpoint seems to not always work...
3./ So, i've try to use the command line, but i've to manualy change the
code page od my dos box from 437 to 1252 (i'm live in belgium).  And
i've not try how to do that permanently !
4./ Before, I had Python23 and it seems that when unstalling it, all the
keys in the registry are not removed at all.  When i've install the 2.4,
I had a mismatch which force me to complety re-install the machine (I'm
not an expert of the registry)...
5./ Installing komodo seems to "block" pythonwinIDE completly...
What's wrong ?  Python seems terific, but the tools...
So... maybe i've to try BlackAdder ?


--
http://mail.python.org/mailman/listinfo/python-list


Python 2.4 & BLT ?

2005-05-10 Thread StepH
Hi,

I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) 
distibution...

I'v try to download btlz-for-8.3.exe, but when i try to install it, i've 
a msgbox saying to the file is corrupt...

Any idea ?

Thanks.

StepH.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 & BLT ?

2005-05-11 Thread StepH
Ron Adam a écrit :
> StepH wrote:
> 
>> Hi,
>>
>> I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) 
>> distibution...
>>
>> I'v try to download btlz-for-8.3.exe, but when i try to install it, 
>> i've a msgbox saying to the file is corrupt...
>>
>> Any idea ?
>>
>> Thanks.
>>
>> StepH.
> 
> 
> Have you tried blt2.4z-for-8.4exe?
> 
> http://blt.sourceforge.net

yes.  When i try to execute it, a small msgbox apprea with the msg:
Corrupt installation detected!

Any idea ?

> 
> 
> _Ron
> 
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 & BLT ?

2005-05-12 Thread StepH
Ron Adam a écrit :
> StepH wrote:
> 
>> Ron Adam a écrit :
>>
>>> StepH wrote:
>>>
>>>
>>>> Hi,
>>>>
>>>> I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) 
>>>> distibution...
>>>>
>>>> I'v try to download btlz-for-8.3.exe, but when i try to install it, 
>>>> i've a msgbox saying to the file is corrupt...
>>>>
>>>> Any idea ?
>>>>
>>>> Thanks.
>>>>
>>>> StepH.
>>>
>>>
>>>
>>> Have you tried blt2.4z-for-8.4exe?
>>>
>>> http://blt.sourceforge.net
>>
>>
>>
>> yes.  When i try to execute it, a small msgbox apprea with the msg:
>> Corrupt installation detected!
>>
>> Any idea ?
> 
> 
> Sounds like it might not be a corrupted install exe file, but a 
> previously installed version that is corrupted.
>

Hum, i've try to re-install all from scratch without success...

> Does the message box say anything else?  With just "Corrupt installation 
> detected!", it could also be a support file or missing dll that the 
> installer needs.

Yes.  It's the only message that is displayed.
I've to go ahead...  so for now i'll use tk.Canvas for my display...

If you have idea ?

> 
> _Ron
> 
> 
> 
> 
> 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 & BLT ?

2005-05-14 Thread StepH
Ron Adam a écrit :
> StepH wrote:
> 
>> Ron Adam a écrit :
>>
>>> StepH wrote:
>>>
>>>
>>>> Ron Adam a écrit :
>>>>
>>>>
>>>>> StepH wrote:
>>>>>
>>>>>
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) 
>>>>>> distibution...
>>>>>>
>>>>>> I'v try to download btlz-for-8.3.exe, but when i try to install 
>>>>>> it, i've a msgbox saying to the file is corrupt...
>>>>>>
>>>>>> Any idea ?
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> StepH.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Have you tried blt2.4z-for-8.4exe?
>>>>>
>>>>> http://blt.sourceforge.net
>>>>
>>>>
>>>>
>>>>
>>>> yes.  When i try to execute it, a small msgbox apprea with the msg:
>>>> Corrupt installation detected!
>>>>
>>>> Any idea ?
>>>
>>>
>>>
>>> Sounds like it might not be a corrupted install exe file, but a 
>>> previously installed version that is corrupted.
>>>
>>
>>
>> Hum, i've try to re-install all from scratch without success...
>>
>>
>>> Does the message box say anything else?  With just "Corrupt 
>>> installation detected!", it could also be a support file or missing 
>>> dll that the installer needs.
>>
>>
>>
>> Yes.  It's the only message that is displayed.
>> I've to go ahead...  so for now i'll use tk.Canvas for my display...
>>
>> If you have idea ?
> 
> 
> A little googling found the following which may give you a clue or ideas 
> of further searches.  Also run a virus scanner on the file before hand.
> 
> http://www.noteworthysoftware.com/composer/faq/90.htm

Argg...  I always find me stupid when i don't have find myself a such 
easy solution.  Running the .exe from C:\temp works, but now, even if 
the installation succes, i'm not able to run the pmw sample based on 
it...  Looks like i've now to re-install pmw or somethings like that.

I'll find it...

Thanks a lot for your help.
StepH.

> http://www.transcender.com/faqs/detail.aspx?pn=tradwnldinstallarticle00900&full=True&tree=True
>  
> 
> http://www.visagesoft.com/help/index.php?_a=knowledgebase&_j=questiondetails&_i=5
>  
> 
> http://www.wise.com/KBArticle.aspx?articleno=1034
> 
> As a last resort, you may also be able to check the exe file by using a 
> zip file reader such as winzip or powerarchiver.  You should be able to 
> extract the individual files that way, but it may be a bit of a task to 
> figure out where to put them.
> 
> Hope this helps,
> 
> _Ron

-- 
http://mail.python.org/mailman/listinfo/python-list


Design Question. Data Acquisition/Display related.

2005-05-17 Thread StepH
Hi,

I'm building a little application, which the goal is to:

1./ Collect data via Serial line and or via a file (for playback).
2./ Display these data as graph, oscilloscope, ...

How manage this ?

1./ Is each "display" must responsible to acquire/read the data ?
2./ Or an engine collect the data then send them to each "display" ?

Also, how to "anim" this ?

1./ Via a timer ?
2./ Via a simple loop (read/update display/pause/read user key)

The app. will be a GUI (tkInter) app. and the user must be able to stop 
the process at any time.

Sure, all this must be maintenable, let's say to acquire data via other 
type of channel or to other type of display...

Yes, it's like a "mini" labView...

Any idea or link is welcome.

Thanks.

STepH.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Design Question. Data Acquisition/Display related.

2005-05-17 Thread StepH
Alex Verstraeten a écrit :

> StepH wrote:
>
>> 1./ Is each "display" must responsible to acquire/read the data ?
>> 2./ Or an engine collect the data then send them to each "display" ?
>>
>>  
>>
> I'd keep it simple:
>
> - DataCollector class
> asociated with one or more display instances (implemented as a list of 
> display subscribers)
> it collects data from a source and notifies each subscribed display 
> that new data is available.
> could something like a 'collect' method which performs:
>
> for display in self.subscribed_displays:
>   display.update( data )
>
>
> - Display class
> just a simple display class with an "update" method
> it should be able to receive new data
> and display new data
> (those 2 actions could be implemented in different methods, you might 
> not want to display everytime new data is available... maybe you might 
> want to consolidate data in some way and output it at some high interval)

Ok, it was my first idea too...

>
>> Also, how to "anim" this ?
>>
>> 1./ Via a timer ?
>> 2./ Via a simple loop (read/update display/pause/read user key)
>>  
>>
>
> a simple loop could do it
>  - handle user events
>  - collect data
>  - update displays
>  - sleep
>
>
>
Here i've a prob. (due to the fact that I start both with Python & 
TkInter).  In TkInter, you run your app by launching a mainloop() 
routine, right ?  So, how, in my forever loop (handle user events / 
Collect data / Update Display / Sleep) handle the user data ?

Sure, i can (i suppose), log user activity (via the event send by the Tk 
underlayer), the "poll" theses event in my for ever loop ?  But in this 
case, are these event will be correctly generated (by Tk) ?  How to 
"give the hand" to Tk in such scenario ?

Thanks for your help.

StepH.
-- 
http://mail.python.org/mailman/listinfo/python-list


pil and reportlab: image compression

2010-08-26 Thread steph
Hi group,

I've written a small application that puts images into a pdf document.
It works ok, but my problem is that the pdf-files become quite huge,
bigger than the original jpegs. The problem seems to arise because I
use PIL to resize the pictures - and the images seem to get
uncompressed in the process. Unfortunately I have not found a way to
compress them again before rendering them to the pdf. Any clues?

Thanks,
Stephan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pil and reportlab: image compression

2010-08-27 Thread steph
On 26 Aug., 13:16, steph  wrote:
> Hi group,
>
> I've written a small application that puts images into a pdf document.
> It works ok, but my problem is that the pdf-files become quite huge,
> bigger than the original jpegs. The problem seems to arise because I
> use PIL to resize the pictures - and the images seem to get
> uncompressed in the process. Unfortunately I have not found a way to
> compress them again before rendering them to the pdf. Any clues?
>
> Thanks,
> Stephan

Solved this by writung to anonymous mmap. Works nicely :-)
-- 
http://mail.python.org/mailman/listinfo/python-list