[Tutor] Newbie & Unittest ...
Damon Timm
damontimm at gmail.com
Thu May 6 17:40:05 CEST 2010
Hi Vincent - Thanks for your input.
Where would I put that string ? In the function's doctsring ? Or
just as a print method ?
I have been looking online some more and it appears there may be a way
to create some sort of generator ... it's still a little confusing to
me, though. I was hoping there was an easier way. I can't imagine I
am the first person with this task to accomplish ...
Thanks,
Damon
On Thu, May 6, 2010 at 9:46 AM, Vincent Davis <vincent at vincentdavis.net> wrote:
> By they way you shouldn't need to use str(file) as I did. Unlessit is
> not a string already. Bad habit. I am used to numbers
> vincet
>
> On Thursday, May 6, 2010, Vincent Davis <vincent at vincentdavis.net> wrote:
>> I can't think of a way to do what you ask, without defining a test for each. ButI think what you might actually want is the define the error message to report which one failed. ie, it's one test with a meaningful error message.
>> 'Failed to load' + str(file)+' '+ str(k)+', '+str(v)I am not ecpert on unittests
>>
>>
>>
>>
>>
>> Vincent Davis
>> 720-301-3003
>>
>> vincent at vincentdavis.net
>>
>> my blog <http://vincentdavis.net> |
>> LinkedIn <http://www.linkedin.com/in/vincentdavis>
>> On Wed, May 5, 2010 at 6:37 PM, Damon Timm <damontimm at gmail.com> wrote:
>> Hi - am trying to write some unit tests for my little python project -
>> I had been hard coding them when necessary here or there but I figured
>> it was time to try and learn how to do it properly.
>>
>> I've read over Python's guide
>> (http://docs.python.org/library/unittest.html) but I am having a hard
>> time understanding how I can apply it *properly* to my first test case
>> ...
>>
>> What I am trying to do is straightforward, I am just not sure how to
>> populate the tests easily. Here is what I want to accomplish:
>>
>> # code
>> import unittest
>> from mlc.filetypes import * # the module I am testing
>>
>> # here are the *correct* key, value pairs I am testing against
>> TAG_VALUES = (
>> ('title', 'Christmas Waltz'),
>> ('artist', 'Damon Timm'),
>> ('album', 'Homemade'),
>> )
>>
>> # list of different file types that I want to test my tag grabbing capabilities
>> # the tags inside these files are set to match my TAG_VALUES
>> # I want to make sure my code is extracting them correctly
>> FILES = (
>> FLACFile('data/lossless/01 - Christmas Waltz.flac'),
>> MP3File('data/lossy/04 - Christmas Waltz (MP3-79).mp3'),
>> OGGFile('data/lossy/01 - Christmas Waltz (OGG-77).ogg'),
>> MP4File('data/lossy/06 - Christmas Waltz (M4A-64).m4a'),
>> )
>>
>> class TestFiles(unittest.TestCase):
>>
>> # this is the basic test
>> def test_values(self):
>> '''see if values from my object match what they should match'''
>> for file in FILES:
>> for k, v in TAG_VALUES:
>> self.assertEqual(self.file.tags[k], v)
>>
>> This test works, however, it only runs as *one* test (which either
>> fails or passes) and I want it to run as 12 different tests (three for
>> each file type) and be able to see which key is failing for which file
>> type. I know I could write them all out individually but that seems
>> unnecessary.
>>
>> I suspect my answer lies in the Suites but I can't wrap my head around it.
>>
>> Thanks!
>>
>> Damon
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list