Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: testing -- what to do for testing code with behaviour dependantupon which files exist?

Reply
Thread Tools

Re: testing -- what to do for testing code with behaviour dependantupon which files exist?

 
 
Brian van den Broek
Guest
Posts: n/a
 
      04-04-2005

> "Brian van den Broek" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>>Hi all,
>>
>>I'm just starting to employ unit testing (I'm using doctest), and I am
>>uncertain how to handle writing tests where the behaviour being tested is
>>dependant on whether certain file paths point to actual files.


Hi all,

I had a busy weekend after posting, so didn't get a chance to
follow-up until now. Thanks to all who responded.

Python's my first real language, and I am a mere hobbyist, so the
suggestions for search terms provided by Terry (and implicitly by
Andre who suggested a mock strategy) are most welcome! Sometimes the
hardest part of googling is knowing what terms to search for.

Grig suggested the tempfile module; I had rejected that initially, as
the code I am testing displays an error message containing the bad
file path, so I thought I needed to know the path name at time of
coding the tests. But, I've since learned that doctest can be made to
consider only leading portions of a line's content. So, this might
well work for me. Thanks for reminding me of the approach.

Jeremy suggested using a directory name akin to
"C:\onlyanidiotwouldhavethisdirecotrynameonadrive" . That is what I had
settled on before I posted. Somehow it feels unhappy and inelegant.
But, I'm a bit less uncomfortable with it seeing that others have done
so, too.

Anyway, thanks again for the suggestions Best to all,

Brian vdB

 
Reply With Quote
 
 
 
 
Jeremy Bowers
Guest
Posts: n/a
 
      04-04-2005
On Mon, 04 Apr 2005 17:02:20 -0400, Brian van den Broek wrote:
> Jeremy suggested using a directory name akin to
> "C:\onlyanidiotwouldhavethisdirecotrynameonadrive" . That is what I had
> settled on before I posted. Somehow it feels unhappy and inelegant.
> But, I'm a bit less uncomfortable with it seeing that others have done
> so, too.


To be clear, I would actually suggest
"onlyanidiotwouldhavethisdirecotrynameonadrive "... note the lack of C:\,
which would be platform specific, as would any other root specification.
Take advantage of the fact that every system I know of makes relative
directories easy, and also note you can work out what directory the
"current file" is in with a combination of __file__ and os.getcwd() (and
that while that won't work if someone changes the working directory,
that's bad form and IIRC breaks some other things in Python as well, so
don't do that).

Making it a relative directory may make it look just as bad, but it is in
some sense somewhat less inelegant; at that point, if someone is creating
that directory in the test directory of your app, they're just fooling
with you, and you don't really have to worry about people who maliciously
make your unit tests fail under most circumstances...
 
Reply With Quote
 
 
 
 
Brian van den Broek
Guest
Posts: n/a
 
      04-04-2005
Jeremy Bowers said unto the world upon 2005-04-04 17:26:
> On Mon, 04 Apr 2005 17:02:20 -0400, Brian van den Broek wrote:
>
>>Jeremy suggested using a directory name akin to
>>"C:\onlyanidiotwouldhavethisdirecotrynameonadriv e". That is what I had
>>settled on before I posted. Somehow it feels unhappy and inelegant.
>>But, I'm a bit less uncomfortable with it seeing that others have done
>>so, too.

>
>
> To be clear, I would actually suggest
> "onlyanidiotwouldhavethisdirecotrynameonadrive "... note the lack of C:\,


Quite so. My apologies for mis-characterizing your suggestion. And
thanks for the additional information that mis-characterization
provoked

Best,

Brian vdB

> which would be platform specific, as would any other root specification.
> Take advantage of the fact that every system I know of makes relative
> directories easy, and also note you can work out what directory the
> "current file" is in with a combination of __file__ and os.getcwd() (and
> that while that won't work if someone changes the working directory,
> that's bad form and IIRC breaks some other things in Python as well, so
> don't do that).
>
> Making it a relative directory may make it look just as bad, but it is in
> some sense somewhat less inelegant; at that point, if someone is creating
> that directory in the test directory of your app, they're just fooling
> with you, and you don't really have to worry about people who maliciously
> make your unit tests fail under most circumstances...



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Webinar - Testing the Untestable - Unit Testing Dependencies andLegacy Code (in C++) Avi C Programming 0 06-11-2012 01:55 PM
[ANN] Webinar - Testing the Untestable - Unit Testing Dependenciesand Legacy Code in C++ Avi C++ 0 06-06-2012 11:25 AM
debugger behaviour different to execution behaviour Andy Chambers Java 1 05-14-2007 09:51 AM
Microcontrollers: which one ? which language ? which compiler ? The Jesus of Suburbia NZ Computing 2 02-11-2006 06:53 PM
testing -- what to do for testing code with behaviour dependant uponwhich files exist? Brian van den Broek Python 3 04-03-2005 12:28 AM



Advertisments